Skip to content

Commit 294be79

Browse files
committed
Merge branch 'dev' of github.com:contentstack/migration-v2-node-server into feature/CMG-528
2 parents c199455 + 5e30ee3 commit 294be79

File tree

34 files changed

+318
-223
lines changed

34 files changed

+318
-223
lines changed

.DS_Store

-6 KB
Binary file not shown.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ MigrationBackup/
349349
# Ionide (cross platform F# VS Code tools) working folder
350350
.ionide/
351351

352+
**.DS_Store
352353

353354
upload-api/node_modules
354355
upload-api/build

api/.DS_Store

-6 KB
Binary file not shown.

api/package-lock.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@contentstack/cli-utilities": "^1.7.1",
3030
"@contentstack/json-rte-serializer": "^2.0.7",
3131
"@contentstack/marketplace-sdk": "^1.2.4",
32-
"axios": "^1.7.8",
32+
"axios": "^1.8.2",
3333
"chokidar": "^3.6.0",
3434
"cors": "^2.8.5",
3535
"dotenv": "^16.3.1",

api/src/.DS_Store

-8 KB
Binary file not shown.

api/src/services/.DS_Store

-6 KB
Binary file not shown.

api/src/services/contentful.service.ts

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -88,39 +88,44 @@ function makeChunks(assetData: any) {
8888

8989
const transformCloudinaryObject = (input: any) => {
9090
const result: any = [];
91+
if (!Array.isArray(input)) {
92+
return result;
93+
}
9194
for (const metaData of input ?? []) {
92-
result?.push({
93-
public_id: metaData.public_id,
94-
resource_type: metaData.resource_type,
95-
type: metaData.type,
96-
format: metaData.format,
97-
version: metaData.version,
98-
url: metaData.original_url,
99-
secure_url: metaData.original_secure_url,
100-
width: metaData.width,
101-
height: metaData.height,
102-
bytes: metaData.bytes,
103-
duration: metaData.duration,
104-
tags: metaData.tags,
105-
metadata: metaData.metadata,
106-
created_at: metaData.created_at,
107-
access_mode: "public",
108-
access_control: [],
109-
created_by: {
110-
type: "",
111-
id: ""
112-
},
113-
uploaded_by: {
114-
type: "",
115-
id: ""
116-
},
117-
folder_id: "",
118-
id: "",
119-
folder: "",
120-
cs_metadata: {
121-
config_label: "config"
122-
}
123-
});
95+
if (metaData?.public_id) {
96+
result?.push({
97+
public_id: metaData?.public_id,
98+
resource_type: metaData?.resource_type,
99+
type: metaData?.type,
100+
format: metaData?.format,
101+
version: metaData?.version,
102+
url: metaData?.original_url,
103+
secure_url: metaData?.original_secure_url,
104+
width: metaData?.width,
105+
height: metaData?.height,
106+
bytes: metaData?.bytes,
107+
duration: metaData?.duration,
108+
tags: metaData?.tags,
109+
metadata: metaData?.metadata,
110+
created_at: metaData?.created_at,
111+
access_mode: "public",
112+
access_control: [],
113+
created_by: {
114+
type: "",
115+
id: ""
116+
},
117+
uploaded_by: {
118+
type: "",
119+
id: ""
120+
},
121+
folder_id: uuidv4(),
122+
id: uuidv4(),
123+
folder: "",
124+
cs_metadata: {
125+
config_label: "config"
126+
}
127+
});
128+
}
124129
}
125130
return result;
126131
}
@@ -185,7 +190,7 @@ function convertToArray(data: any) {
185190
if (typeof data === 'object' && data !== null && !Array.isArray(data)) {
186191
return [data]// Converts object values into an array
187192
}
188-
return data; // Return as is if it's already an array or not an object
193+
return data ?? []; // Return as is if it's already an array or not an object
189194
}
190195

191196
const mktApp = (type: string, data: any) => {
@@ -736,7 +741,6 @@ const mapLocales = ({ masterLocale, locale, locales }: any) => {
736741
* @throws Will log errors encountered during file reading, processing, or writing of entries.
737742
*/
738743
const createEntry = async (packagePath: any, destination_stack_id: string, projectId: string, contentTypes: any, mapperKeys: any, master_locale: string): Promise<void> => {
739-
console.info("🚀 ~ createEntry ~ master_locale:", master_locale)
740744
const srcFunc = 'createEntry';
741745
try {
742746
const entriesSave = path.join(DATA, destination_stack_id, ENTRIES_DIR_NAME);
@@ -783,7 +787,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
783787
entryData[name][lang][id] ??= {};
784788
locales.push(lang);
785789
const fieldData = currentCT?.fieldMapping?.find((item: any) => key === item?.uid);
786-
const newId = fieldData?.contentstackFieldUid ?? `${key}`.replace(/[^a-zA-Z0-9]+/g, "_");
790+
const newId = fieldData?.contentstackFieldUid ?? `${key}`?.replace?.(/[^a-zA-Z0-9]+/g, "_");
787791
entryData[name][lang][id][newId] = processField(
788792
langValue,
789793
entryId,
@@ -796,16 +800,14 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
796800
const pathName = getDisplayName(name, displayField);
797801
locales.forEach((locale) => {
798802
const localeCode = mapLocales({ masterLocale: master_locale, locale, locales: LOCALE_MAPPER });
799-
console.info("🚀 ~ locales.forEach ~ localeCode:", localeCode);
800803
const publishDetails = Object?.values?.(environmentsId)?.length ? Object?.values?.(environmentsId)
801804
.filter((env: any) => env?.name === environment_id)
802805
?.map((env: any) => ({
803806
environment: env?.uid,
804807
version: 1,
805-
locale: locale?.toLowerCase(),
808+
locale: locale?.toLowerCase?.(),
806809
})) : [];
807-
808-
const title = entryData[name][locale][id][pathName] || "";
810+
const title = fields?.[pathName]?.[locale] || "";
809811
const urlTitle = title
810812
?.replace?.(/[^a-zA-Z0-9]+/g, "-")
811813
?.toLowerCase?.();
@@ -858,7 +860,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
858860
);
859861
for await (const [chunkId, chunkData] of Object.entries(chunks)) {
860862
refs[chunkIndex++] = `${chunkId}-entries.json`;
861-
await writeFile(filePath, `${chunkId}-entries.json`, chunkData)
863+
await writeFile(filePath, `${chunkId}-entries.json`, chunkData);
862864
}
863865
await writeFile(filePath, ENTRIES_MASTER_FILE, refs);
864866
}

api/src/services/migration.service.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,10 @@ const startTestMigration = async (req: Request): Promise<any> => {
244244
await wordpressService?.extractChunks(file_path, packagePath, project?.current_test_stack_id, projectId)
245245
await wordpressService?.getAllAuthors(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
246246
//await wordpressService?.extractContentTypes(projectId, project?.current_test_stack_id, contentTypes)
247-
await wordpressService?.getAllTerms(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
248-
await wordpressService?.getAllTags(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
249-
await wordpressService?.getAllCategories(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
250-
await wordpressService?.extractPosts(packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
247+
await wordpressService?.getAllTerms(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
248+
await wordpressService?.getAllTags(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
249+
await wordpressService?.getAllCategories(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
250+
await wordpressService?.extractPosts(packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
251251
await wordpressService?.extractGlobalFields(project?.current_test_stack_id, projectId)
252252
await wordpressService?.createVersionFile(project?.current_test_stack_id, projectId);
253253
}
@@ -318,12 +318,12 @@ const startMigration = async (req: Request): Promise<any> => {
318318
await wordpressService?.createAssetFolderFile(file_path, project?.destination_stack_id, projectId)
319319
await wordpressService?.getAllreference(file_path, packagePath, project?.destination_stack_id, projectId)
320320
await wordpressService?.extractChunks(file_path, packagePath, project?.destination_stack_id, projectId)
321-
await wordpressService?.getAllAuthors(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
321+
await wordpressService?.getAllAuthors(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
322322
//await wordpressService?.extractContentTypes(projectId, project?.destination_stack_id)
323323
await wordpressService?.getAllTerms(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
324-
await wordpressService?.getAllTags(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
325-
await wordpressService?.getAllCategories(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
326-
await wordpressService?.extractPosts(packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
324+
await wordpressService?.getAllTags(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
325+
await wordpressService?.getAllCategories(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
326+
await wordpressService?.extractPosts(packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
327327
await wordpressService?.extractGlobalFields(project?.destination_stack_id, projectId)
328328
await wordpressService?.createVersionFile(project?.destination_stack_id, projectId);
329329

@@ -426,23 +426,23 @@ export const createSourceLocales = async (req: Request) => {
426426

427427
try {
428428
// Check if the project.json file exists
429-
if (!fs.existsSync(projectFilePath)) {
429+
if (!fs?.existsSync?.(projectFilePath)) {
430430
console.error(`project.json not found at ${projectFilePath}`);
431431
throw new Error(`project.json not found.`);
432432
}
433-
433+
434434
// Find the project with the specified projectId
435-
const project: any = ProjectModelLowdb.chain.get("projects").find({ id: projectId }).value();
435+
const project: any = ProjectModelLowdb?.chain?.get?.("projects")?.find?.({ id: projectId })?.value?.();
436436
if (project) {
437-
const index = ProjectModelLowdb.chain.get("projects").findIndex({ id: projectId }).value();
437+
const index = ProjectModelLowdb?.chain?.get?.("projects")?.findIndex?.({ id: projectId })?.value();
438438
if (index > -1) {
439-
440-
ProjectModelLowdb.update((data: any) => {
439+
440+
ProjectModelLowdb?.update((data: any) => {
441441
data.projects[index].source_locales = locales;
442442
});
443443
} // Write back the updated projects
444444
} else {
445-
logger.error(`Project with ID: ${projectId} not found`,{
445+
logger.error(`Project with ID: ${projectId} not found`, {
446446
status: HTTP_CODES?.NOT_FOUND,
447447
message: HTTP_TEXTS?.INVALID_ID
448448
})
@@ -467,30 +467,30 @@ export const createSourceLocales = async (req: Request) => {
467467
* @return - void
468468
* @throws Exception if the project ID is invalid or the when the path to project.json is incorrect
469469
*/
470-
export const updateLocaleMapper = async (req:Request) =>{
471-
const mapperObject = req.body;
472-
const projectFilePath = path.join(process.cwd(), 'database', 'project.json'); // Adjusted path to project.json
473-
const projectId = req.params.projectId;
470+
export const updateLocaleMapper = async (req: Request) => {
471+
const mapperObject = req?.body;
472+
const projectFilePath = path?.join?.(process?.cwd(), 'database', 'project.json'); // Adjusted path to project.json
473+
const projectId = req?.params?.projectId;
474474

475475
try {
476476
// Check if the project.json file exists
477-
if (!fs.existsSync(projectFilePath)) {
477+
if (!fs?.existsSync?.(projectFilePath)) {
478478
console.error(`project.json not found at ${projectFilePath}`);
479479
throw new Error(`project.json not found.`);
480480
}
481-
481+
482482
// Find the project with the specified projectId
483-
const project: any = ProjectModelLowdb.chain.get("projects").find({ id: projectId }).value();
483+
const project: any = ProjectModelLowdb?.chain?.get?.("projects")?.find?.({ id: projectId })?.value();
484484
if (project) {
485-
const index = ProjectModelLowdb.chain.get("projects").findIndex({ id: projectId }).value();
485+
const index = ProjectModelLowdb?.chain?.get("projects")?.findIndex?.({ id: projectId })?.value();
486486
if (index > -1) {
487-
ProjectModelLowdb.update((data: any) => {
487+
ProjectModelLowdb?.update((data: any) => {
488488
data.projects[index].master_locale = mapperObject?.master_locale;
489489
data.projects[index].locales = mapperObject?.locales;
490490
});
491491
} // Write back the updated projects
492492
} else {
493-
logger.error(`Project with ID: ${projectId} not found`,{
493+
logger.error(`Project with ID: ${projectId} not found`, {
494494
status: HTTP_CODES?.NOT_FOUND,
495495
message: HTTP_TEXTS?.INVALID_ID
496496
})

package-lock.json

Lines changed: 33 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)