Skip to content

Commit 297f592

Browse files
authored
Merge pull request #610 from contentstack/dev
Dev
2 parents df017fd + d32ead1 commit 297f592

File tree

17 files changed

+4157
-2346
lines changed

17 files changed

+4157
-2346
lines changed

api/src/constants/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export const LOCALE_MAPPER: any = {
177177
masterLocale: {
178178
"en-us": "en",
179179
},
180-
fr: "fr-fr",
180+
locales:{fr: "fr-fr",}
181181
};
182182
export const CHUNK_SIZE = 1048576;
183183

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: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -238,28 +238,30 @@ const startTestMigration = async (req: Request): Promise<any> => {
238238
}
239239
case CMS.WORDPRESS: {
240240
if (packagePath) {
241+
await wordpressService?.createLocale(req, project?.current_test_stack_id, projectId, project);
241242
await wordpressService?.getAllAssets(file_path, packagePath, project?.current_test_stack_id, projectId)
242243
await wordpressService?.createAssetFolderFile(file_path, project?.current_test_stack_id, projectId)
243244
await wordpressService?.getAllreference(file_path, packagePath, project?.current_test_stack_id, projectId)
244245
await wordpressService?.extractChunks(file_path, packagePath, project?.current_test_stack_id, projectId)
245-
await wordpressService?.getAllAuthors(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
246+
await wordpressService?.getAllAuthors(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project)
246247
//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)
248+
await wordpressService?.getAllTerms(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project)
249+
await wordpressService?.getAllTags(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project)
250+
await wordpressService?.getAllCategories(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project)
251+
await wordpressService?.extractPosts(packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project)
251252
await wordpressService?.extractGlobalFields(project?.current_test_stack_id, projectId)
252253
await wordpressService?.createVersionFile(project?.current_test_stack_id, projectId);
253254
}
254255
break;
255256
}
256257
case CMS.CONTENTFUL: {
257-
await contentfulService?.createLocale(file_path, project?.current_test_stack_id, projectId, project);
258-
await contentfulService?.createRefrence(file_path, project?.current_test_stack_id, projectId);
259-
await contentfulService?.createWebhooks(file_path, project?.current_test_stack_id, projectId);
260-
await contentfulService?.createEnvironment(file_path, project?.current_test_stack_id, projectId);
261-
await contentfulService?.createAssets(file_path, project?.current_test_stack_id, projectId, true);
262-
await contentfulService?.createEntry(file_path, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project);
258+
const cleanLocalPath = file_path?.replace?.(/\/$/, '');
259+
await contentfulService?.createLocale(cleanLocalPath, project?.current_test_stack_id, projectId, project);
260+
await contentfulService?.createRefrence(cleanLocalPath, project?.current_test_stack_id, projectId);
261+
await contentfulService?.createWebhooks(cleanLocalPath, project?.current_test_stack_id, projectId);
262+
await contentfulService?.createEnvironment(cleanLocalPath, project?.current_test_stack_id, projectId);
263+
await contentfulService?.createAssets(cleanLocalPath, project?.current_test_stack_id, projectId, true);
264+
await contentfulService?.createEntry(cleanLocalPath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project);
263265
await contentfulService?.createVersionFile(project?.current_test_stack_id, projectId);
264266
break;
265267
}
@@ -314,28 +316,30 @@ const startMigration = async (req: Request): Promise<any> => {
314316
}
315317
case CMS.WORDPRESS: {
316318
if (packagePath) {
319+
await wordpressService?.createLocale(req, project?.current_test_stack_id, projectId, project);
317320
await wordpressService?.getAllAssets(file_path, packagePath, project?.destination_stack_id, projectId,)
318321
await wordpressService?.createAssetFolderFile(file_path, project?.destination_stack_id, projectId)
319322
await wordpressService?.getAllreference(file_path, packagePath, project?.destination_stack_id, projectId)
320323
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)
324+
await wordpressService?.getAllAuthors(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project)
322325
//await wordpressService?.extractContentTypes(projectId, project?.destination_stack_id)
323-
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)
326+
await wordpressService?.getAllTerms(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project)
327+
await wordpressService?.getAllTags(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project)
328+
await wordpressService?.getAllCategories(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project)
329+
await wordpressService?.extractPosts(packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project)
327330
await wordpressService?.extractGlobalFields(project?.destination_stack_id, projectId)
328331
await wordpressService?.createVersionFile(project?.destination_stack_id, projectId);
329332
}
330333
break;
331334
}
332335
case CMS.CONTENTFUL: {
333-
await contentfulService?.createLocale(file_path, project?.destination_stack_id, projectId, project);
334-
await contentfulService?.createRefrence(file_path, project?.destination_stack_id, projectId);
335-
await contentfulService?.createWebhooks(file_path, project?.destination_stack_id, projectId);
336-
await contentfulService?.createEnvironment(file_path, project?.destination_stack_id, projectId);
337-
await contentfulService?.createAssets(file_path, project?.destination_stack_id, projectId);
338-
await contentfulService?.createEntry(file_path, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project);
336+
const cleanLocalPath = file_path?.replace?.(/\/$/, '');
337+
await contentfulService?.createLocale(cleanLocalPath, project?.destination_stack_id, projectId, project);
338+
await contentfulService?.createRefrence(cleanLocalPath, project?.destination_stack_id, projectId);
339+
await contentfulService?.createWebhooks(cleanLocalPath, project?.destination_stack_id, projectId);
340+
await contentfulService?.createEnvironment(cleanLocalPath, project?.destination_stack_id, projectId);
341+
await contentfulService?.createAssets(cleanLocalPath, project?.destination_stack_id, projectId);
342+
await contentfulService?.createEntry(cleanLocalPath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project);
339343
await contentfulService?.createVersionFile(project?.destination_stack_id, projectId);
340344
break;
341345
}
@@ -419,7 +423,6 @@ export const createSourceLocales = async (req: Request) => {
419423

420424
const projectId = req?.params?.projectId;
421425
const locales = req?.body?.locale;
422-
console.info("🚀 ~ createSourceLocales ~ locales:", locales);
423426

424427
try {
425428
// Find the project with the specified projectId

0 commit comments

Comments
 (0)