Skip to content

Commit 9a53386

Browse files
committed
Dev changes merged
2 parents bcdef16 + 8594332 commit 9a53386

File tree

17 files changed

+2209
-2427
lines changed

17 files changed

+2209
-2427
lines changed

.github/workflows/repo-sync.yml

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ jobs:
9898
git gc --prune=now # Garbage collect and prune unreachable objects
9999
100100
# echo "Installing ESLint dependencies..."
101-
# npm install --save-dev eslint @eslint/js globals
101+
npm install --save-dev eslint @eslint/js globals
102+
102103
103104
# if [ ! -f "eslint.config.cjs" ]; then
104105
# echo "Creating default ESLint config..."
@@ -143,34 +144,36 @@ jobs:
143144
rsync -av --delete ../upload-api/migration-sitecore/ ./upload-api/migration-sitecore/
144145
145146
# Ensure tsconfig.json exists, create a default one if missing
146-
if [ ! -f "tsconfig.json" ]; then
147-
echo "Creating default tsconfig.json..."
148-
cat <<EOL > tsconfig.json
149-
{
150-
"compilerOptions": {
151-
"target": "ES6",
152-
"module": "CommonJS",
153-
"strict": true,
154-
"esModuleInterop": true,
155-
"skipLibCheck": true,
156-
"forceConsistentCasingInFileNames": true
157-
},
158-
"include": ["src/**/*"],
159-
"exclude": ["node_modules", "dist"]
160-
}
161-
EOL
162-
fi
147+
# if [ ! -f "tsconfig.json" ]; then
148+
# echo "Creating default tsconfig.json..."
149+
# cat <<EOL > tsconfig.json
150+
# {
151+
# "compilerOptions": {
152+
# "target": "ES6",
153+
# "module": "CommonJS",
154+
# "strict": true,
155+
# "esModuleInterop": true,
156+
# "skipLibCheck": true,
157+
# "forceConsistentCasingInFileNames": true
158+
# },
159+
# "include": ["src/**/*"],
160+
# "exclude": ["node_modules", "dist"]
161+
# }
162+
# EOL
163+
# fi
163164
164165
# Remove unused imports
165-
npx ts-remove-unused-imports api/
166-
npx ts-remove-unused-imports ui/
167-
npx ts-remove-unused-imports upload-api/
166+
# npx ts-remove-unused-imports api/
167+
# npx ts-remove-unused-imports ui/
168+
# npx ts-remove-unused-imports upload-api/
168169
169170
# Remove missing imports
170-
npx ts-prune | grep -E '^(api/|ui/|upload-api/)/' | awk '{print $1}' | xargs -I {} sed -i '/import/d' {}
171+
# npx ts-prune | grep -E '^(api/|ui/|upload-api/)/' | awk '{print $1}' | xargs -I {} sed -i '/import/d' {}
172+
173+
# # Format code
174+
# npx prettier --write .
171175
172-
# Format code
173-
npx prettier --write .
176+
# eslint api/ ui/ upload-api/ --rule 'import/no-unresolved: error' --format compact | awk -F ':' '{print $1}' | sort -u | xargs -I {} sed -i '/import/d' {}
174177
175178
git add .
176179
git commit -m "Sync changes from migration-v2 PR #${{ github.event.pull_request.number }}"

api/src/services/migration.service.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ const startTestMigration = async (req: Request): Promise<any> => {
230230
case CMS.SITECORE_V9:
231231
case CMS.SITECORE_V10: {
232232
if (packagePath) {
233-
await siteCoreService?.createEntry({ packagePath, contentTypes, master_locale: project?.stackDetails?.master_locale, destinationStackId: project?.current_test_stack_id, projectId, keyMapper: project?.mapperKeys });
234-
await siteCoreService?.createLocale(req, project?.current_test_stack_id, projectId);
233+
await siteCoreService?.createEntry({ packagePath, contentTypes, master_locale: project?.stackDetails?.master_locale, destinationStackId: project?.current_test_stack_id, projectId, keyMapper: project?.mapperKeys, project });
234+
await siteCoreService?.createLocale(req, project?.current_test_stack_id, projectId, project);
235235
await siteCoreService?.createVersionFile(project?.current_test_stack_id);
236236
}
237237
break;
@@ -306,8 +306,8 @@ const startMigration = async (req: Request): Promise<any> => {
306306
case CMS.SITECORE_V9:
307307
case CMS.SITECORE_V10: {
308308
if (packagePath) {
309-
await siteCoreService?.createEntry({ packagePath, contentTypes, master_locale: project?.stackDetails?.master_locale, destinationStackId: project?.destination_stack_id, projectId, keyMapper: project?.mapperKeys });
310-
await siteCoreService?.createLocale(req, project?.destination_stack_id, projectId);
309+
await siteCoreService?.createEntry({ packagePath, contentTypes, master_locale: project?.stackDetails?.master_locale, destinationStackId: project?.destination_stack_id, projectId, keyMapper: project?.mapperKeys, project });
310+
await siteCoreService?.createLocale(req, project?.destination_stack_id, projectId, project);
311311
await siteCoreService?.createVersionFile(project?.destination_stack_id);
312312
}
313313
break;
@@ -417,18 +417,18 @@ const getLogs = async (req: Request): Promise<any> => {
417417
*/
418418
export const createSourceLocales = async (req: Request) => {
419419

420-
const projectId = req.params.projectId;
421-
const locales = req.body.locale
420+
const projectId = req?.params?.projectId;
421+
const locales = req?.body?.locale;
422+
console.info("🚀 ~ createSourceLocales ~ locales:", locales);
422423

423424
try {
424425
// Find the project with the specified projectId
425426
await ProjectModelLowdb?.read?.();
426427
const index = ProjectModelLowdb?.chain?.get?.("projects")?.findIndex?.({ id: projectId })?.value?.();
427-
if (index > -1) {
428+
if (typeof index === "number" && index > -1) {
428429
ProjectModelLowdb?.update?.((data: any) => {
429430
data.projects[index].source_locales = locales;
430431
});
431-
// Write back the updated projects
432432
} else {
433433
logger.error(`Project with ID: ${projectId} not found`, {
434434
status: HTTP_CODES?.NOT_FOUND,

api/src/services/org.service.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import logger from "../utils/logger.js";
88
import { HTTP_TEXTS, HTTP_CODES } from "../constants/index.js";
99
import { ExceptionFunction } from "../utils/custom-errors.utils.js";
1010
import { BadRequestError } from "../utils/custom-errors.utils.js";
11+
import ProjectModelLowdb from "../models/project-lowdb.js";
1112

1213
/**
1314
* Retrieves all stacks based on the provided request.
@@ -38,7 +39,6 @@ const getAllStacks = async (req: Request): Promise<LoginServiceType> => {
3839
},
3940
})
4041
);
41-
// console.info(err, res);
4242
if (err) {
4343
logger.error(
4444
getLogMessage(
@@ -63,11 +63,20 @@ const getAllStacks = async (req: Request): Promise<LoginServiceType> => {
6363
);
6464
});
6565
}
66-
// const locale:any[]
67-
// const locale = await getStackLocal(token_payload, stacks);
66+
await ProjectModelLowdb?.read?.();
67+
const testStacks = ProjectModelLowdb?.chain?.get?.("projects")?.flatMap?.("test_stacks")?.value?.();
68+
if (testStacks?.length > 0) {
69+
const filterStacks = [];
70+
for (const stack of stacks ?? []) {
71+
const isPresent = testStacks?.find?.((testStack: any) => testStack?.stackUid === stack?.api_key);
72+
if (isPresent === undefined) {
73+
filterStacks?.push(stack);
74+
}
75+
}
76+
stacks = filterStacks;
77+
}
6878
return {
6979
data: {
70-
// stacks: locale,
7180
stacks,
7281
},
7382
status: res.status,

api/src/services/sitecore.service.ts

Lines changed: 63 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { orgService } from './org.service.js';
99
import { getLogMessage } from '../utils/index.js';
1010
import customLogger from '../utils/custom-logger.utils.js';
1111

12-
1312
const append = "a";
1413
const baseDirName = MIGRATION_DATA_CONFIG.DATA
1514
const {
@@ -50,6 +49,18 @@ const AssetsPathSpliter = ({ path, id }: any) => {
5049
return newPath;
5150
}
5251

52+
const mapLocales = ({ masterLocale, locale, locales }: any) => {
53+
if (locales?.masterLocale?.[masterLocale ?? ''] === locale) {
54+
return Object?.keys(locales?.masterLocale)?.[0]
55+
}
56+
for (const [key, value] of Object?.entries?.(locales) ?? {}) {
57+
if (typeof value !== 'object' && value === locale) {
58+
return key;
59+
}
60+
}
61+
return locale?.toLowerCase?.();
62+
}
63+
5364

5465

5566
async function writeOneFile(indexPath: string, fileMeta: any) {
@@ -195,7 +206,7 @@ const cretaeAssets = async ({ packagePath, baseDir, destinationStackId, projectI
195206
return allAssetJSON;
196207
}
197208

198-
const createEntry = async ({ packagePath, contentTypes, master_locale, destinationStackId, projectId, keyMapper }: { packagePath: any; contentTypes: any; master_locale?: string, destinationStackId: string, projectId: string, keyMapper: any }) => {
209+
const createEntry = async ({ packagePath, contentTypes, master_locale, destinationStackId, projectId, keyMapper, project }: { packagePath: any; contentTypes: any; master_locale?: string, destinationStackId: string, projectId: string, keyMapper: any, project: any }) => {
199210
try {
200211
const srcFunc = 'createEntry';
201212
const baseDir = path.join(baseDirName, destinationStackId);
@@ -216,7 +227,11 @@ const createEntry = async ({ packagePath, contentTypes, master_locale, destinati
216227
const templateIndex = entriesData?.findIndex((ele: any) => ele?.template === template);
217228
if (templateIndex >= 0) {
218229
const entry = entriesData?.[templateIndex]?.locale?.[language];
219-
entry[id] = { meta: jsonData?.item?.$, fields: jsonData?.item?.fields };
230+
if (entry !== undefined) {
231+
entry[id] = { meta: jsonData?.item?.$, fields: jsonData?.item?.fields };
232+
} else {
233+
entriesData[templateIndex].locale[language] = entries;
234+
}
220235
} else {
221236
const locale: any = {};
222237
locale[language] = entries;
@@ -228,61 +243,59 @@ const createEntry = async ({ packagePath, contentTypes, master_locale, destinati
228243
for await (const ctType of contentTypes) {
229244
const message = getLogMessage(
230245
srcFunc,
231-
`Transforming entries of Content Type ${keyMapper[ctType?.contentstackUid] ?? ctType?.contentstackUid} has begun.`,
246+
`Transforming entries of Content Type ${keyMapper?.[ctType?.contentstackUid] ?? ctType?.contentstackUid} has begun.`,
232247
{}
233248
)
234249
await customLogger(projectId, destinationStackId, 'info', message);
235250
const entryPresent: any = entriesData?.find((item: any) => uidCorrector({ uid: item?.template }) === ctType?.contentstackUid)
236251
if (entryPresent) {
237252
const locales: any = Object?.keys(entryPresent?.locale);
253+
const allLocales: any = { masterLocale: project?.master_locale ?? LOCALE_MAPPER?.masterLocale, ...project?.locales ?? {} }
238254
for await (const locale of locales) {
239-
let newLocale = locale;
255+
const newLocale = mapLocales({ masterLocale: master_locale, locale, locales: allLocales });
240256
const entryLocale: any = {};
241-
if (typeof LOCALE_MAPPER?.masterLocale === 'object' && LOCALE_MAPPER?.masterLocale !== null && LOCALE_MAPPER?.masterLocale?.[master_locale ?? ''] === locale) {
242-
newLocale = Object?.keys(LOCALE_MAPPER?.masterLocale)?.[0];
243-
Object.entries(entryPresent?.locale?.[locale] || {}).map(async ([uid, entry]: any) => {
244-
const entryObj: any = {};
245-
entryObj.uid = uid;
246-
for await (const field of entry?.fields?.field ?? []) {
247-
for await (const fsc of ctType?.fieldMapping ?? []) {
248-
if (fsc?.contentstackFieldType !== 'group' && !field?.$?.key?.includes('__')) {
249-
if (fsc?.contentstackFieldUid === 'title') {
250-
entryObj[fsc?.contentstackFieldUid] = entry?.meta?.name;
251-
}
252-
if (fsc?.contentstackFieldUid === 'url') {
253-
entryObj[fsc?.contentstackFieldUid] = `/${entry?.meta?.key}`;
254-
}
255-
if (getLastKey(fsc?.uid) === field?.$?.key) {
256-
const content: any = await entriesFieldCreator({ field: fsc, content: field?.content, idCorrector, allAssetJSON, contentTypes, entriesData, locale });
257-
const gpData: any = ctType?.fieldMapping?.find((elemant: any) => elemant?.uid === fsc?.uid?.split('.')?.[0]);
258-
if (gpData?.uid) {
259-
const ctUid = uidCorrector({ uid: gpData?.uid });
260-
if (ctUid !== gpData?.contentstackFieldUid && fsc?.contentstackFieldUid?.includes(ctUid)) {
261-
const newUid: any = fsc?.contentstackFieldUid?.replace(ctUid, gpData?.contentstackFieldUid);
262-
entryObj[newUid] = content;
263-
} else {
264-
entryObj[fsc?.contentstackFieldUid] = content;
265-
}
257+
Object.entries(entryPresent?.locale?.[locale] || {}).map(async ([uid, entry]: any) => {
258+
const entryObj: any = {};
259+
entryObj.uid = uid;
260+
for await (const field of entry?.fields?.field ?? []) {
261+
for await (const fsc of ctType?.fieldMapping ?? []) {
262+
if (fsc?.contentstackFieldType !== 'group' && !field?.$?.key?.includes('__')) {
263+
if (fsc?.contentstackFieldUid === 'title') {
264+
entryObj[fsc?.contentstackFieldUid] = entry?.meta?.name;
265+
}
266+
if (fsc?.contentstackFieldUid === 'url') {
267+
entryObj[fsc?.contentstackFieldUid] = `/${entry?.meta?.key}`;
268+
}
269+
if (getLastKey(fsc?.uid) === field?.$?.key) {
270+
const content: any = await entriesFieldCreator({ field: fsc, content: field?.content, idCorrector, allAssetJSON, contentTypes, entriesData, locale });
271+
const gpData: any = ctType?.fieldMapping?.find((elemant: any) => elemant?.uid === fsc?.uid?.split('.')?.[0]);
272+
if (gpData?.uid) {
273+
const ctUid = uidCorrector({ uid: gpData?.uid });
274+
if (ctUid !== gpData?.contentstackFieldUid && fsc?.contentstackFieldUid?.includes(ctUid)) {
275+
const newUid: any = fsc?.contentstackFieldUid?.replace(ctUid, gpData?.contentstackFieldUid);
276+
entryObj[newUid] = content;
266277
} else {
267278
entryObj[fsc?.contentstackFieldUid] = content;
268279
}
280+
} else {
281+
entryObj[fsc?.contentstackFieldUid] = content;
269282
}
270283
}
271284
}
272285
}
273-
entryObj.publish_details = [];
274-
if (Object.keys?.(entryObj)?.length > 1) {
275-
entryLocale[uid] = unflatten(entryObj) ?? {};
276-
const message = getLogMessage(
277-
srcFunc,
278-
`Entry title "${entryObj?.title}"(${keyMapper[ctType?.contentstackUid] ?? ctType?.contentstackUid}) in the ${newLocale} locale has been successfully transformed.`,
279-
{}
280-
)
281-
await customLogger(projectId, destinationStackId, 'info', message)
282-
}
283-
});
284-
}
285-
const mapperCt: string = (keyMapper[ctType?.contentstackUid] !== "" && keyMapper[ctType?.contentstackUid] !== undefined) ? keyMapper[ctType?.contentstackUid]
286+
}
287+
entryObj.publish_details = [];
288+
if (Object.keys?.(entryObj)?.length > 1) {
289+
entryLocale[uid] = unflatten(entryObj) ?? {};
290+
const message = getLogMessage(
291+
srcFunc,
292+
`Entry title "${entryObj?.title}"(${keyMapper?.[ctType?.contentstackUid] ?? ctType?.contentstackUid}) in the ${newLocale} locale has been successfully transformed.`,
293+
{}
294+
)
295+
await customLogger(projectId, destinationStackId, 'info', message)
296+
}
297+
});
298+
const mapperCt: string = (keyMapper?.[ctType?.contentstackUid] !== "" && keyMapper?.[ctType?.contentstackUid] !== undefined) ? keyMapper?.[ctType?.contentstackUid]
286299
: ctType?.contentstackUid;
287300
const fileMeta = { "1": `${newLocale}.json` };
288301
const entryPath = path.join(
@@ -296,11 +309,11 @@ const createEntry = async ({ packagePath, contentTypes, master_locale, destinati
296309
} else {
297310
const message = getLogMessage(
298311
srcFunc,
299-
`No entries found for the content type ${keyMapper[ctType?.contentstackUid] ?? ctType?.contentstackUid}.`,
312+
`No entries found for the content type ${keyMapper?.[ctType?.contentstackUid] ?? ctType?.contentstackUid}.`,
300313
{}
301314
)
302315
await customLogger(projectId, destinationStackId, 'error', message)
303-
console.info('Entries missing for', keyMapper[ctType?.contentstackUid] ?? ctType?.contentstackUid)
316+
console.info('Entries missing for', keyMapper?.[ctType?.contentstackUid] ?? ctType?.contentstackUid)
304317
}
305318
}
306319
return true;
@@ -309,13 +322,13 @@ const createEntry = async ({ packagePath, contentTypes, master_locale, destinati
309322
}
310323
}
311324

312-
const createLocale = async (req: any, destinationStackId: string, projectId: string) => {
325+
const createLocale = async (req: any, destinationStackId: string, projectId: string, project: any) => {
313326
const srcFunc = 'createLocale';
314327
try {
315328
const baseDir = path.join(baseDirName, destinationStackId);
316329
const localeSave = path.join(baseDir, LOCALE_DIR_NAME);
317330
const allLocalesResp = await orgService.getLocales(req)
318-
const masterLocale = Object?.keys?.(LOCALE_MAPPER?.masterLocale)?.[0];
331+
const masterLocale = Object?.keys?.(project?.master_locale ?? LOCALE_MAPPER?.masterLocale)?.[0];
319332
const msLocale: any = {};
320333
const uid = uuidv4();
321334
msLocale[uid] = {
@@ -331,14 +344,14 @@ const createLocale = async (req: any, destinationStackId: string, projectId: str
331344
)
332345
await customLogger(projectId, destinationStackId, 'info', message);
333346
const allLocales: any = {};
334-
for (const [key, value] of Object.entries(LOCALE_MAPPER)) {
347+
for (const [key, value] of Object.entries(project?.locales ?? LOCALE_MAPPER)) {
335348
const localeUid = uuidv4();
336349
if (key !== 'masterLocale' && typeof value === 'string') {
337350
allLocales[localeUid] = {
338-
"code": value,
351+
"code": key,
339352
"fallback_locale": masterLocale,
340353
"uid": localeUid,
341-
"name": allLocalesResp?.data?.locales?.[value] ?? ''
354+
"name": allLocalesResp?.data?.locales?.[key] ?? ''
342355
}
343356
const message = getLogMessage(
344357
srcFunc,

api/src/utils/content-type-creator.utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,9 @@ const mergeTwoCts = async (ct: any, mergeCts: any) => {
672672
...ct,
673673
title: mergeCts?.title,
674674
uid: mergeCts?.uid,
675+
options: {
676+
"singleton": false,
677+
}
675678
}
676679
for await (const field of ctData?.schema ?? []) {
677680
if (field?.data_type === 'group') {

0 commit comments

Comments
 (0)