Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions api/src/services/contentful.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function makeChunks(assetData: any) {
return chunks;
}

const mapLocales = ({ masterLocale, locale, locales }: any) => {
const mapLocales = ({ masterLocale, locale, locales, isNull = false }: any) => {
if (locales?.masterLocale?.[masterLocale ?? ''] === locale) {
return Object?.keys(locales?.masterLocale)?.[0]
}
Expand All @@ -93,7 +93,11 @@ const mapLocales = ({ masterLocale, locale, locales }: any) => {
return key;
}
}
return locale.toLowerCase();
if (isNull !== true) {
return locale?.toLowerCase?.();
} else {
return null;
}
}

const transformCloudinaryObject = (input: any) => {
Expand Down Expand Up @@ -842,7 +846,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
for await (const [localeKey, localeValues] of Object.entries(
values as { [key: string]: any }
)) {
const localeCode = mapLocales({ masterLocale: master_locale, locale: localeKey, locales: LocaleMapper });
const localeCode = mapLocales({ masterLocale: master_locale, locale: localeKey, locales: LocaleMapper, isNull: true });
const chunks = makeChunks(localeValues);
for (const [entryKey, entryValue] of Object.entries(localeValues)) {
const message = getLogMessage(
Expand All @@ -854,15 +858,18 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
}
const refs: { [key: string]: any } = {};
let chunkIndex = 1;
const filePath = path.join(
entriesSave,
ctName, localeCode
);
for await (const [chunkId, chunkData] of Object.entries(chunks)) {
refs[chunkIndex++] = `${chunkId}-entries.json`;
await writeFile(filePath, `${chunkId}-entries.json`, chunkData);
if (localeCode) {
const filePath = path.join(
entriesSave,
ctName,
localeCode
);
for await (const [chunkId, chunkData] of Object.entries(chunks)) {
refs[chunkIndex++] = `${chunkId}-entries.json`;
await writeFile(filePath, `${chunkId}-entries.json`, chunkData);
}
await writeFile(filePath, ENTRIES_MASTER_FILE, refs);
}
await writeFile(filePath, ENTRIES_MASTER_FILE, refs);
}
}
} else {
Expand Down Expand Up @@ -957,7 +964,8 @@ const createLocale = async (packagePath: string, destination_stack_id: string, p
)
await customLogger(projectId, destination_stack_id, 'info', message);
} else {
if (project?.locales?.[localeData?.code]) {
const newValueLocale = getKeyByValue(project?.locales, localeData?.code);
if (newValueLocale) {
allLocales[title] = newLocale;
const message = getLogMessage(
srcFunc,
Expand Down
27 changes: 14 additions & 13 deletions api/src/services/migration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,13 @@ const startTestMigration = async (req: Request): Promise<any> => {
break;
}
case CMS.CONTENTFUL: {
await contentfulService?.createLocale(file_path, project?.current_test_stack_id, projectId, project);
await contentfulService?.createRefrence(file_path, project?.current_test_stack_id, projectId);
await contentfulService?.createWebhooks(file_path, project?.current_test_stack_id, projectId);
await contentfulService?.createEnvironment(file_path, project?.current_test_stack_id, projectId);
await contentfulService?.createAssets(file_path, project?.current_test_stack_id, projectId, true);
await contentfulService?.createEntry(file_path, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project);
const cleanLocalPath = file_path?.replace?.(/\/$/, '');
await contentfulService?.createLocale(cleanLocalPath, project?.current_test_stack_id, projectId, project);
await contentfulService?.createRefrence(cleanLocalPath, project?.current_test_stack_id, projectId);
await contentfulService?.createWebhooks(cleanLocalPath, project?.current_test_stack_id, projectId);
await contentfulService?.createEnvironment(cleanLocalPath, project?.current_test_stack_id, projectId);
await contentfulService?.createAssets(cleanLocalPath, project?.current_test_stack_id, projectId, true);
await contentfulService?.createEntry(cleanLocalPath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project);
await contentfulService?.createVersionFile(project?.current_test_stack_id, projectId);
break;
}
Expand Down Expand Up @@ -330,12 +331,13 @@ const startMigration = async (req: Request): Promise<any> => {
break;
}
case CMS.CONTENTFUL: {
await contentfulService?.createLocale(file_path, project?.destination_stack_id, projectId, project);
await contentfulService?.createRefrence(file_path, project?.destination_stack_id, projectId);
await contentfulService?.createWebhooks(file_path, project?.destination_stack_id, projectId);
await contentfulService?.createEnvironment(file_path, project?.destination_stack_id, projectId);
await contentfulService?.createAssets(file_path, project?.destination_stack_id, projectId);
await contentfulService?.createEntry(file_path, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project);
const cleanLocalPath = file_path?.replace?.(/\/$/, '');
await contentfulService?.createLocale(cleanLocalPath, project?.destination_stack_id, projectId, project);
await contentfulService?.createRefrence(cleanLocalPath, project?.destination_stack_id, projectId);
await contentfulService?.createWebhooks(cleanLocalPath, project?.destination_stack_id, projectId);
await contentfulService?.createEnvironment(cleanLocalPath, project?.destination_stack_id, projectId);
await contentfulService?.createAssets(cleanLocalPath, project?.destination_stack_id, projectId);
await contentfulService?.createEntry(cleanLocalPath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale, project);
await contentfulService?.createVersionFile(project?.destination_stack_id, projectId);
break;
}
Expand Down Expand Up @@ -419,7 +421,6 @@ export const createSourceLocales = async (req: Request) => {

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

try {
// Find the project with the specified projectId
Expand Down
7 changes: 4 additions & 3 deletions upload-api/src/services/contentful/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ const createContentfulMapper = async (
) => {
try {
const { localPath } = config;
const fetchedLocales: [] = await extractLocale(localPath);
const cleanLocalPath = localPath?.replace?.(/\/$/, '');
const fetchedLocales: [] = await extractLocale(cleanLocalPath);

await extractContentTypes(localPath, affix);
await extractContentTypes(cleanLocalPath, affix);
const initialMapper = await createInitialMapper();
const req = {
method: 'post',
Expand All @@ -29,7 +30,7 @@ const createContentfulMapper = async (
},
data: JSON.stringify(initialMapper)
};
const {data, status} = await axios.request(req);
const { data, status } = await axios.request(req);
if (data?.data?.content_mapper?.length) {
logger.info('Validation success:', {
status: HTTP_CODES?.OK,
Expand Down
Loading