Skip to content

Commit f8c312f

Browse files
committed
removed the nodemon code
2 parents 6e3d5d8 + e6bbc02 commit f8c312f

File tree

22 files changed

+249
-199
lines changed

22 files changed

+249
-199
lines changed

api/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"build": "npx tsc",
88
"start": "NODE_ENV=production node dist/server.js",
9-
"dev": "NODE_ENV=production tsx watch ./src/server.ts",
9+
"dev": "NODE_ENV=production tsx ./src/server.ts",
1010
"prettify": "prettier --write .",
1111
"windev": "SET NODE_ENV=production&& tsx watch ./src/server.ts",
1212
"winstart": "SET NODE_ENV=production&& node dist/server.js",
@@ -45,7 +45,6 @@
4545
"jsonwebtoken": "^9.0.2",
4646
"lowdb": "^7.0.1",
4747
"mkdirp": "^3.0.1",
48-
"nodemon": "^3.1.9",
4948
"p-limit": "^6.2.0",
5049
"path-to-regexp": "^8.2.0",
5150
"router": "^2.0.0",

api/src/models/FieldMapper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface FieldMapper {
2828
field_mapper: {
2929
id: string;
3030
projectId: string;
31+
contentTypeId: string;
3132
uid: string;
3233
otherCmsField: string;
3334
otherCmsType: string;

api/src/services/contentMapper.service.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,21 @@ const putTestData = async (req: Request) => {
3636
const contentTypes = req.body.contentTypes;
3737

3838
try {
39-
await FieldMapperModel.read();
39+
40+
/*
41+
this code snippet is iterating over an array called contentTypes and
42+
transforming each element by adding a unique identifier (id) if it doesn't already exist.
43+
The transformed elements are then stored in the contentType variable,
44+
and the generated id values are pushed into the contentIds array.
45+
*/
46+
await ContentTypesMapperModelLowdb.read();
47+
const contentIds: any[] = [];
48+
const contentType = contentTypes.map((item: any) => {
49+
const id = item?.id?.replace(/[{}]/g, "")?.toLowerCase() || uuidv4();
50+
item.id = id;
51+
contentIds.push(id);
52+
return { ...item, id, projectId };
53+
});
4054

4155
/*
4256
this code snippet iterates over an array of contentTypes and performs
@@ -47,36 +61,24 @@ const putTestData = async (req: Request) => {
4761
It then updates the field_mapper property of a data object using the FieldMapperModel.update() function.
4862
Finally, it updates the fieldMapping property of each type in the contentTypes array with the fieldIds array.
4963
*/
64+
await FieldMapperModel.read();
65+
5066
contentTypes.map((type: any, index: any) => {
5167
const fieldIds: string[] = [];
5268
const fields = type?.fieldMapping?.filter((field: any) => field)?.map?.((field: any) => {
5369
const id = field?.id ? field?.id?.replace(/[{}]/g, "")?.toLowerCase() : uuidv4();
5470
field.id = id;
5571
fieldIds.push(id);
56-
return { id, projectId, isDeleted: false, ...field };
72+
return { id, projectId, contentTypeId: type?.id, isDeleted: false, ...field };
5773
});
5874

5975
FieldMapperModel.update((data: any) => {
6076
data.field_mapper = [...(data?.field_mapper ?? []), ...(fields ?? [])];
6177
});
62-
contentTypes[index].fieldMapping = fieldIds;
78+
contentType[index].fieldMapping = fieldIds;
6379
});
6480

65-
await ContentTypesMapperModelLowdb.read();
66-
const contentIds: any[] = [];
6781

68-
/*
69-
this code snippet is iterating over an array called contentTypes and
70-
transforming each element by adding a unique identifier (id) if it doesn't already exist.
71-
The transformed elements are then stored in the contentType variable,
72-
and the generated id values are pushed into the contentIds array.
73-
*/
74-
const contentType = contentTypes.map((item: any) => {
75-
const id = item?.id?.replace(/[{}]/g, "")?.toLowerCase() || uuidv4();
76-
item.id = id;
77-
contentIds.push(id);
78-
return { ...item, id, projectId };
79-
});
8082

8183
await ContentTypesMapperModelLowdb.update((data: any) => {
8284
data.ContentTypesMappers = [
@@ -248,7 +250,7 @@ const getFieldMapping = async (req: Request) => {
248250
const fieldData = contentType?.fieldMapping?.map?.((fields: any) => {
249251
const fieldMapper = FieldMapperModel.chain
250252
.get("field_mapper")
251-
.find({ id: fields, projectId: projectId })
253+
.find({ id: fields, projectId: projectId, contentTypeId: contentTypeId })
252254
.value();
253255

254256
return fieldMapper;
@@ -616,7 +618,7 @@ const updateContentType = async (req: Request) => {
616618
await FieldMapperModel.read();
617619
fieldMapping.forEach((field: any) => {
618620
const fieldIndex = FieldMapperModel.data.field_mapper.findIndex(
619-
(f: any) => f?.id === field?.id
621+
(f: any) => f?.id === field?.id && f?.contentTypeId === field?.contentTypeId
620622
);
621623
if (fieldIndex > -1 && field?.contentstackFieldType !== "") {
622624
FieldMapperModel.update((data: any) => {

api/src/services/contentful.service.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function makeChunks(assetData: any) {
8484
return chunks;
8585
}
8686

87-
const mapLocales = ({ masterLocale, locale, locales }: any) => {
87+
const mapLocales = ({ masterLocale, locale, locales, isNull = false }: any) => {
8888
if (locales?.masterLocale?.[masterLocale ?? ''] === locale) {
8989
return Object?.keys(locales?.masterLocale)?.[0]
9090
}
@@ -93,7 +93,11 @@ const mapLocales = ({ masterLocale, locale, locales }: any) => {
9393
return key;
9494
}
9595
}
96-
return locale.toLowerCase();
96+
if (isNull !== true) {
97+
return locale?.toLowerCase?.();
98+
} else {
99+
return null;
100+
}
97101
}
98102

99103
const transformCloudinaryObject = (input: any) => {
@@ -842,7 +846,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
842846
for await (const [localeKey, localeValues] of Object.entries(
843847
values as { [key: string]: any }
844848
)) {
845-
const localeCode = mapLocales({ masterLocale: master_locale, locale: localeKey, locales: LocaleMapper });
849+
const localeCode = mapLocales({ masterLocale: master_locale, locale: localeKey, locales: LocaleMapper, isNull: true });
846850
const chunks = makeChunks(localeValues);
847851
for (const [entryKey, entryValue] of Object.entries(localeValues)) {
848852
const message = getLogMessage(
@@ -854,15 +858,18 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
854858
}
855859
const refs: { [key: string]: any } = {};
856860
let chunkIndex = 1;
857-
const filePath = path.join(
858-
entriesSave,
859-
ctName, localeCode
860-
);
861-
for await (const [chunkId, chunkData] of Object.entries(chunks)) {
862-
refs[chunkIndex++] = `${chunkId}-entries.json`;
863-
await writeFile(filePath, `${chunkId}-entries.json`, chunkData);
861+
if (localeCode) {
862+
const filePath = path.join(
863+
entriesSave,
864+
ctName,
865+
localeCode
866+
);
867+
for await (const [chunkId, chunkData] of Object.entries(chunks)) {
868+
refs[chunkIndex++] = `${chunkId}-entries.json`;
869+
await writeFile(filePath, `${chunkId}-entries.json`, chunkData);
870+
}
871+
await writeFile(filePath, ENTRIES_MASTER_FILE, refs);
864872
}
865-
await writeFile(filePath, ENTRIES_MASTER_FILE, refs);
866873
}
867874
}
868875
} else {
@@ -957,7 +964,8 @@ const createLocale = async (packagePath: string, destination_stack_id: string, p
957964
)
958965
await customLogger(projectId, destination_stack_id, 'info', message);
959966
} else {
960-
if (project?.locales?.[localeData?.code]) {
967+
const newValueLocale = getKeyByValue(project?.locales, localeData?.code);
968+
if (newValueLocale) {
961969
allLocales[title] = newLocale;
962970
const message = getLogMessage(
963971
srcFunc,

api/src/services/migration.service.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -429,35 +429,36 @@ const startTestMigration = async (req: Request): Promise<any> => {
429429
break;
430430
}
431431
case CMS.CONTENTFUL: {
432+
const cleanLocalPath = file_path?.replace?.(/\/$/, '');
432433
await contentfulService?.createLocale(
433-
file_path,
434+
cleanLocalPath,
434435
project?.current_test_stack_id,
435436
projectId,
436437
project
437438
);
438439
await contentfulService?.createRefrence(
439-
file_path,
440+
cleanLocalPath,
440441
project?.current_test_stack_id,
441442
projectId
442443
);
443444
await contentfulService?.createWebhooks(
444-
file_path,
445+
cleanLocalPath,
445446
project?.current_test_stack_id,
446447
projectId
447448
);
448449
await contentfulService?.createEnvironment(
449-
file_path,
450+
cleanLocalPath,
450451
project?.current_test_stack_id,
451452
projectId
452453
);
453454
await contentfulService?.createAssets(
454-
file_path,
455+
cleanLocalPath,
455456
project?.current_test_stack_id,
456457
projectId,
457458
true
458459
);
459460
await contentfulService?.createEntry(
460-
file_path,
461+
cleanLocalPath,
461462
project?.current_test_stack_id,
462463
projectId,
463464
contentTypes,
@@ -698,34 +699,35 @@ const startMigration = async (req: Request): Promise<any> => {
698699
break;
699700
}
700701
case CMS.CONTENTFUL: {
702+
const cleanLocalPath = file_path?.replace?.(/\/$/, '');
701703
await contentfulService?.createLocale(
702-
file_path,
704+
cleanLocalPath,
703705
project?.destination_stack_id,
704706
projectId,
705707
project
706708
);
707709
await contentfulService?.createRefrence(
708-
file_path,
710+
cleanLocalPath,
709711
project?.destination_stack_id,
710712
projectId
711713
);
712714
await contentfulService?.createWebhooks(
713-
file_path,
715+
cleanLocalPath,
714716
project?.destination_stack_id,
715717
projectId
716718
);
717719
await contentfulService?.createEnvironment(
718-
file_path,
720+
cleanLocalPath,
719721
project?.destination_stack_id,
720722
projectId
721723
);
722724
await contentfulService?.createAssets(
723-
file_path,
725+
cleanLocalPath,
724726
project?.destination_stack_id,
725727
projectId
726728
);
727729
await contentfulService?.createEntry(
728-
file_path,
730+
cleanLocalPath,
729731
project?.destination_stack_id,
730732
projectId,
731733
contentTypes,
@@ -805,8 +807,8 @@ const getLogs = async (req: Request): Promise<any> => {
805807
* @throws Exception if the project ID is invalid or the when the path to project.json is incorrect
806808
*/
807809
export const createSourceLocales = async (req: Request) => {
808-
const projectId = req.params.projectId;
809-
const locales = req.body.locale;
810+
const projectId = req?.params?.projectId;
811+
const locales = req?.body?.locale;
810812

811813
try {
812814
// Find the project with the specified projectId

0 commit comments

Comments
 (0)