Skip to content

Commit 0383ba8

Browse files
merge conflict resolved
1 parent 35902cb commit 0383ba8

File tree

6 files changed

+83
-57
lines changed

6 files changed

+83
-57
lines changed

.github/workflows/repo-sync.yml

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ env:
1414
RSYNC_SITECORE_API_SRC_SERVICES_EXCLUDES: "--exclude 'src/services/contentful/' --exclude 'src/services/contentful.service.ts' --exclude 'src/services/wordpress.service.ts'" # Include only sitecore services
1515
RSYNC_CONTENTFUL_API_SRC_SERVICES_EXCLUDES: "--exclude 'src/services/wordpress.service.ts' --exclude 'src/services/sitecore.service.ts'" # Include only contentful services
1616
RSYNC_WORDPRESS_API_SRC_SERVICES_EXCLUDES: "--exclude 'src/services/contentful/' --exclude 'src/services/contentful.service.ts' --exclude 'src/services/sitecore.service.ts'" # Include only wordpress services
17-
RSYNC_SITECORE_UPLOAD_API_SRC_EXCLUDES: "--exclude 'migration-contentful/' --exclude 'migration-wordpress/' --exclude 'controllers/wordpress/' --exclude 'models/contentful.json' --exclude 'models/wordpress.json' --exclude 'services/contentful/' --exclude 'validators/aem/' --exclude 'validators/contentful/' --exclude 'validators/wordpress/'" # Include only sitecore upload-api
18-
RSYNC_CONTENTFUL_UPLOAD_API_SRC_EXCLUDES: "--exclude 'migration-sitecore/' --exclude 'migration-wordpress/' --exclude 'controllers/sitecore/' --exclude 'models/wordpress.json' --exclude 'validators/aem/' --exclude 'validators/sitecore/' --exclude 'validators/wordpress/'" # Include only contentful upload-api
19-
RSYNC_WORDPRESS_UPLOAD_API_SRC_EXCLUDES: "--exclude 'migration-sitecore/' --exclude 'migration-contentful/' --exclude 'controllers/sitecore/' --exclude 'models/contentful.json' --exclude 'validators/aem/' --exclude 'validators/sitecore/' --exclude 'validators/contentful/'" # Include only wordpress upload-api
17+
RSYNC_SITECORE_UPLOAD_API_SRC_EXCLUDES: "--exclude 'controllers/wordpress/' --exclude 'controllers/contentful/' --exclude 'models/contentful.json' --exclude 'models/wordpress.json' --exclude 'services/contentful/' --exclude 'validators/aem/' --exclude 'validators/contentful/' --exclude 'validators/wordpress/'" # Include only sitecore upload-api
18+
RSYNC_CONTENTFUL_UPLOAD_API_SRC_EXCLUDES: "--exclude 'controllers/sitecore/' --exclude 'controllers/wordpress/' --exclude 'models/wordpress.json' --exclude 'validators/aem/' --exclude 'validators/sitecore/' --exclude 'validators/wordpress/'" # Include only contentful upload-api
19+
RSYNC_WORDPRESS_UPLOAD_API_SRC_EXCLUDES: "--exclude 'controllers/sitecore/' --exclude 'controllers/contentful/' --exclude 'models/contentful.json' --exclude 'services/contentful/' --exclude 'validators/aem/' --exclude 'validators/sitecore/' --exclude 'validators/contentful/'" # Include only wordpress upload-api
2020
jobs:
2121
sync-on-merge:
2222
runs-on: ubuntu-latest
@@ -57,7 +57,13 @@ jobs:
5757
ui:
5858
- 'ui/**'
5959
upload-api:
60-
- 'upload-api/**'
60+
- 'upload-api/src/**'
61+
migration-sitecore:
62+
- 'upload-api/migration-sitecore/**'
63+
migration-contentful:
64+
- 'upload-api/migration-contentful/**'
65+
migration-wordpress:
66+
- 'upload-api/migration-wordpress/**'
6167
index:
6268
- 'index.js'
6369
@@ -75,16 +81,19 @@ jobs:
7581
steps.file_changes.outputs.cli == 'true' ||
7682
steps.file_changes.outputs.ui == 'true' ||
7783
steps.file_changes.outputs.upload-api == 'true' ||
84+
steps.file_changes.outputs.migration-sitecore == 'true' ||
7885
steps.file_changes.outputs.index == 'true'
7986
)
8087
run: |
8188
git clone https://x-access-token:${{ secrets.GH_PAT }}@github.com/${{ env.SITECORE_REPO }}.git
8289
cd migration-tool-sitecore
8390
git checkout -b sync-from-migration-v2-${{ github.event.pull_request.number }}
91+
git pull origin ${{ env.BRANCH }}
8492
rsync -av --delete ${{ env.RSYNC_SITECORE_API_SRC_SERVICES_EXCLUDES }} ../api/ ./api/
8593
rsync -av --delete ../cli/ ./cli/
8694
rsync -av --delete ../ui/ ./ui/
87-
rsync -av --delete ${{ env.RSYNC_SITECORE_UPLOAD_API_SRC_EXCLUDES }} ../upload-api/ ./upload-api/
95+
rsync -av --delete ${{ env.RSYNC_SITECORE_UPLOAD_API_SRC_EXCLUDES }} ../upload-api/src/ ./upload-api/src/
96+
rsync -av --delete ../upload-api/migration-sitecore/ ./upload-api/migration-sitecore/
8897
git add .
8998
git commit -m "Sync changes from migration-v2 PR #${{ github.event.pull_request.number }}"
9099
git push origin sync-from-migration-v2-${{ github.event.pull_request.number }}
@@ -97,6 +106,7 @@ jobs:
97106
steps.file_changes.outputs.cli == 'true' ||
98107
steps.file_changes.outputs.ui == 'true' ||
99108
steps.file_changes.outputs.upload-api == 'true' ||
109+
steps.file_changes.outputs.migration-sitecore == 'true' ||
100110
steps.file_changes.outputs.index == 'true'
101111
)
102112
run: |
@@ -116,16 +126,19 @@ jobs:
116126
steps.file_changes.outputs.cli == 'true' ||
117127
steps.file_changes.outputs.ui == 'true' ||
118128
steps.file_changes.outputs.upload-api == 'true' ||
129+
steps.file_changes.outputs.migration-contentful == 'true' ||
119130
steps.file_changes.outputs.index == 'true'
120131
)
121132
run: |
122133
git clone https://x-access-token:${{ secrets.GH_PAT }}@github.com/${{ env.CONTENTFUL_REPO }}.git
123134
cd migration-tool-contentful
124135
git checkout -b sync-from-migration-v2-${{ github.event.pull_request.number }}
136+
git pull origin ${{ env.BRANCH }}
125137
rsync -av --delete ${{ env.RSYNC_CONTENTFUL_API_SRC_SERVICES_EXCLUDES }} ../api/ ./api/
126138
rsync -av --delete ../cli/ ./cli/
127139
rsync -av --delete ../ui/ ./ui/
128-
rsync -av --delete ${{ env.RSYNC_CONTENTFUL_UPLOAD_API_SRC_EXCLUDES }} ../upload-api/ ./upload-api/
140+
rsync -av --delete ${{ env.RSYNC_CONTENTFUL_UPLOAD_API_SRC_EXCLUDES }} ../upload-api/src/ ./upload-api/src/
141+
rsync -av --delete ../upload-api/migration-contentful/ ./upload-api/migration-contentful/
129142
git add .
130143
git commit -m "Sync changes from migration-v2 PR #${{ github.event.pull_request.number }}"
131144
git push origin sync-from-migration-v2-${{ github.event.pull_request.number }}
@@ -138,6 +151,7 @@ jobs:
138151
steps.file_changes.outputs.cli == 'true' ||
139152
steps.file_changes.outputs.ui == 'true' ||
140153
steps.file_changes.outputs.upload-api == 'true' ||
154+
steps.file_changes.outputs.migration-contentful == 'true' ||
141155
steps.file_changes.outputs.index == 'true'
142156
)
143157
run: |
@@ -157,16 +171,19 @@ jobs:
157171
steps.file_changes.outputs.cli == 'true' ||
158172
steps.file_changes.outputs.ui == 'true' ||
159173
steps.file_changes.outputs.upload-api == 'true' ||
174+
steps.file_changes.outputs.migration-wordpress == 'true' ||
160175
steps.file_changes.outputs.index == 'true'
161176
)
162177
run: |
163178
git clone https://x-access-token:${{ secrets.GH_PAT }}@github.com/${{ env.WORDPRESS_REPO }}.git
164179
cd migration-tool-wordpress
165180
git checkout -b sync-from-migration-v2-${{ github.event.pull_request.number }}
181+
git pull origin ${{ env.BRANCH }}
166182
rsync -av --delete ${{ env.RSYNC_WORDPRESS_API_SRC_SERVICES_EXCLUDES }} ../api/ ./api/
167183
rsync -av --delete ../cli/ ./cli/
168184
rsync -av --delete ../ui/ ./ui/
169-
rsync -av --delete ${{ env.RSYNC_WORDPRESS_UPLOAD_API_SRC_EXCLUDES }} ../upload-api/ ./upload-api/
185+
rsync -av --delete ${{ env.RSYNC_WORDPRESS_UPLOAD_API_SRC_EXCLUDES }} ../upload-api/src/ ./upload-api/src/
186+
rsync -av --delete ../upload-api/migration-wordpress/ ./upload-api/migration-wordpress/
170187
git add .
171188
git commit -m "Sync changes from migration-v2 PR #${{ github.event.pull_request.number }}"
172189
git push origin sync-from-migration-v2-${{ github.event.pull_request.number }}
@@ -179,6 +196,7 @@ jobs:
179196
steps.file_changes.outputs.cli == 'true' ||
180197
steps.file_changes.outputs.ui == 'true' ||
181198
steps.file_changes.outputs.upload-api == 'true' ||
199+
steps.file_changes.outputs.migration-wordpress == 'true' ||
182200
steps.file_changes.outputs.index == 'true'
183201
)
184202
run: |

api/src/services/contentful.service.ts

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { JSDOM } from "jsdom";
1010
import { jsonToHtml, jsonToMarkdown, htmlToJson } from '@contentstack/json-rte-serializer';
1111

1212

13-
import { CHUNK_SIZE, MIGRATION_DATA_CONFIG } from "../constants/index.js";
13+
import { CHUNK_SIZE, MIGRATION_DATA_CONFIG, LOCALE_MAPPER } from "../constants/index.js";
1414
import { Locale } from "../models/types.js";
1515
import jsonRTE from "./contentful/jsonRTE.js";
1616
import { getAllLocales, getLogMessage } from "../utils/index.js";
@@ -234,7 +234,7 @@ const processField = (
234234
return assetsData;
235235
} else {
236236
const id = lang_value?.sys?.id;
237-
if (id in assetId) {
237+
if (assetId && id in assetId) {
238238
return assetId?.[id]
239239
}
240240
return null;
@@ -253,7 +253,7 @@ const processField = (
253253
return refs;
254254
}
255255
const id = lang_value?.sys?.id;
256-
if (id in entryId) return [[entryId?.[id]]];
256+
if (entryId && id in entryId) return [[entryId?.[id]]];
257257
return null;
258258
}
259259

@@ -331,11 +331,9 @@ const processField = (
331331
break;
332332
}
333333
}
334-
335-
336-
337334
};
338335

336+
339337
// Helper function to clean up brackets in non-numeric lang_value
340338
const cleanBrackets = (lang_value: any) => {
341339
const myJSON = JSON.stringify(lang_value);
@@ -439,11 +437,11 @@ const saveAsset = async (
439437
const publishDetails: { environment: any; version: number; locale: any }[] =
440438
[];
441439
const assetsSave = path.join(DATA, destination_stack_id, ASSETS_DIR_NAME);
442-
const environmentsId = await readFile(path.join(DATA, destination_stack_id, ENVIRONMENTS_DIR_NAME), ENVIRONMENTS_FILE_NAME);
440+
const environmentsId = await readFile(path.join(DATA, destination_stack_id, ENVIRONMENTS_DIR_NAME), ENVIRONMENTS_FILE_NAME) ?? {};
443441
const localeId = await readFile(path.join(DATA, destination_stack_id, LOCALE_DIR_NAME), LOCALE_CF_LANGUAGE);
444442

445443
if (assets.fields.file && assets.fields.title) {
446-
Object.values(environmentsId).forEach((env: any) => {
444+
Object?.values?.(environmentsId)?.length && Object.values(environmentsId).forEach((env: any) => {
447445
if (env?.name === assets?.sys?.environment?.sys?.id) {
448446
Object.values(localeId).forEach((locale: any) => {
449447
publishDetails.push({
@@ -699,6 +697,18 @@ const createEnvironment = async (packagePath: any, destination_stack_id: string,
699697
}
700698
};
701699

700+
const mapLocales = ({ masterLocale, locale, locales }: any) => {
701+
if (locales?.masterLocale?.[masterLocale ?? ''] === locale) {
702+
return Object?.keys(locales?.masterLocale)?.[0]
703+
}
704+
for (const [key, value] of Object?.entries?.(locales) ?? {}) {
705+
if (typeof value !== 'object' && value === locale) {
706+
return key;
707+
}
708+
}
709+
return locale.toLowerCase();
710+
}
711+
702712
/**
703713
* Creates and processes entries from a given package file and saves them to the destination stack directory.
704714
*
@@ -725,7 +735,8 @@ const createEnvironment = async (packagePath: any, destination_stack_id: string,
725735
*
726736
* @throws Will log errors encountered during file reading, processing, or writing of entries.
727737
*/
728-
const createEntry = async (packagePath: any, destination_stack_id: string, projectId: string, contentTypes: any, mapperKeys: any): Promise<void> => {
738+
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)
729740
const srcFunc = 'createEntry';
730741
try {
731742
const entriesSave = path.join(DATA, destination_stack_id, ENTRIES_DIR_NAME);
@@ -738,7 +749,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
738749
if (entries && entries.length > 0) {
739750
const assetId = await readFile(assetsSave, ASSETS_SCHEMA_FILE) ?? [];
740751
const entryId = await readFile(path.join(DATA, destination_stack_id, REFERENCES_DIR_NAME), REFERENCES_FILE_NAME);
741-
const environmentsId = await readFile(environmentSave, ENVIRONMENTS_FILE_NAME);
752+
const environmentsId = await readFile(environmentSave, ENVIRONMENTS_FILE_NAME) ?? {};
742753
const displayField: { [key: string]: any } = {}
743754
content.map((item: any) => {
744755
displayField[item.name.toLowerCase().replace(/[^a-z0-9]+/g, "_")] =
@@ -784,13 +795,15 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
784795
});
785796
const pathName = getDisplayName(name, displayField);
786797
locales.forEach((locale) => {
787-
const publishDetails = Object?.values?.(environmentsId)
798+
const localeCode = mapLocales({ masterLocale: master_locale, locale, locales: LOCALE_MAPPER });
799+
console.info("🚀 ~ locales.forEach ~ localeCode:", localeCode);
800+
const publishDetails = Object?.values?.(environmentsId)?.length ? Object?.values?.(environmentsId)
788801
.filter((env: any) => env?.name === environment_id)
789802
?.map((env: any) => ({
790803
environment: env?.uid,
791804
version: 1,
792-
locale: locale.toLowerCase(),
793-
}));
805+
locale: locale?.toLowerCase(),
806+
})) : [];
794807

795808
const title = entryData[name][locale][id][pathName] || "";
796809
const urlTitle = title
@@ -817,21 +830,18 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
817830
);
818831
});
819832
});
820-
821833
return entryData;
822834
},
823835
{}
824836
);
825-
const writePromises = [];
826-
827-
for (const [newKey, values] of Object.entries(result)) {
837+
for await (const [newKey, values] of Object.entries(result)) {
828838
const currentCT = contentTypes?.find((ct: any) => ct?.otherCmsUid === newKey);
829839
const ctName = currentCT?.contentstackUid in mapperKeys ?
830840
mapperKeys?.[currentCT?.contentstackUid] : (currentCT?.contentstackUid ?? newKey.replace(/([A-Z])/g, "_$1").toLowerCase());
831-
for (const [localeKey, localeValues] of Object.entries(
841+
for await (const [localeKey, localeValues] of Object.entries(
832842
values as { [key: string]: any }
833843
)) {
834-
const chunks = await makeChunks(localeValues);
844+
const chunks = makeChunks(localeValues);
835845
for (const [entryKey, entryValue] of Object.entries(localeValues)) {
836846
const message = getLogMessage(
837847
srcFunc,
@@ -846,14 +856,13 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
846856
entriesSave,
847857
ctName, localeKey.toLowerCase()
848858
);
849-
for (const [chunkId, chunkData] of Object.entries(chunks)) {
859+
for await (const [chunkId, chunkData] of Object.entries(chunks)) {
850860
refs[chunkIndex++] = `${chunkId}-entries.json`;
851-
writePromises.push(writeFile(filePath, `${chunkId}-entries.json`, chunkData))
861+
await writeFile(filePath, `${chunkId}-entries.json`, chunkData)
852862
}
853-
writePromises.push(writeFile(filePath, ENTRIES_MASTER_FILE, refs));
863+
await writeFile(filePath, ENTRIES_MASTER_FILE, refs);
854864
}
855865
}
856-
await Promise.all(writePromises);
857866
} else {
858867
const message = getLogMessage(
859868
srcFunc,

api/src/services/contentful/jsonRTE.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ function parseBlockReference(obj: any, lang?: LangType, destination_stack_id?: S
250250

251251
function parseInlineReference(obj: any, lang?: LangType, destination_stack_id?: StackId): any {
252252
const entryId: { [key: string]: any } = destination_stack_id && readFile(path.join(process.cwd(), DATA, destination_stack_id, RTE_REFERENCES_DIR_NAME, RTE_REFERENCES_FILE_NAME));
253-
const entry = Object.entries(entryId).find(([arrayKey, arrayValue]) => arrayKey === lang && arrayValue[obj.data.target.sys.id]);
253+
const entry = entryId && Object.entries(entryId).find(([arrayKey, arrayValue]) => arrayKey === lang && arrayValue[obj.data.target.sys.id]);
254254

255255
if (entry) {
256256
const [arrayKey, arrayValue] = entry;
@@ -315,8 +315,6 @@ function parseBlockAsset(obj: any, lang?: LangType, destination_stack_id?: Stack
315315
}
316316

317317

318-
319-
320318
function parseBlockquote(obj: any): any {
321319
const children = obj.content.map((e: any) => parsers.get(e.nodeType)?.(e)).filter(Boolean);
322320
return {

api/src/services/migration.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ const startTestMigration = async (req: Request): Promise<any> => {
259259
await contentfulService?.createWebhooks(file_path, project?.current_test_stack_id, projectId);
260260
await contentfulService?.createEnvironment(file_path, project?.current_test_stack_id, projectId);
261261
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);
262+
await contentfulService?.createEntry(file_path, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale);
263263
await contentfulService?.createVersionFile(project?.current_test_stack_id, projectId);
264264
break;
265265
}
@@ -299,8 +299,8 @@ const startMigration = async (req: Request): Promise<any> => {
299299
await customLogger(projectId, project?.destination_stack_id, 'info', message);
300300
await setLogFilePath(loggerPath);
301301
const contentTypes = await fieldAttacher({ orgId, projectId, destinationStackId: project?.destination_stack_id, region, user_id });
302-
await marketPlaceAppService?.createAppManifest({ orgId, destinationStackId: project?.current_test_stack_id, region, userId: user_id });
303-
await extensionService?.createExtension({ destinationStackId: project?.current_test_stack_id });
302+
await marketPlaceAppService?.createAppManifest({ orgId, destinationStackId: project?.destination_stack_id, region, userId: user_id });
303+
await extensionService?.createExtension({ destinationStackId: project?.destination_stack_id });
304304
switch (cms) {
305305
case CMS.SITECORE_V8:
306306
case CMS.SITECORE_V9:
@@ -337,7 +337,7 @@ const startMigration = async (req: Request): Promise<any> => {
337337
await contentfulService?.createWebhooks(file_path, project?.destination_stack_id, projectId);
338338
await contentfulService?.createEnvironment(file_path, project?.destination_stack_id, projectId);
339339
await contentfulService?.createAssets(file_path, project?.destination_stack_id, projectId);
340-
await contentfulService?.createEntry(file_path, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys);
340+
await contentfulService?.createEntry(file_path, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale);
341341
await contentfulService?.createVersionFile(project?.destination_stack_id, projectId);
342342
break;
343343
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ export const contenTypeMaker = async ({ contentType, destinationStackId, project
748748
if (currentCt?.uid) {
749749
ct = await mergeTwoCts(ct, currentCt);
750750
}
751-
if (ct?.uid) {
751+
if (ct?.uid && ct?.schema?.length) {
752752
if (contentType?.type === 'global_field') {
753753
const globalSave = path.join(MIGRATION_DATA_CONFIG.DATA, destinationStackId, GLOBAL_FIELDS_DIR_NAME);
754754
const message = getLogMessage(srcFunc, `Global Field ${ct?.uid} has been successfully Transformed.`, {});

0 commit comments

Comments
 (0)