Skip to content

Commit 56d5bb9

Browse files
committed
Conflict resolved
2 parents 9e9df00 + 358a6bb commit 56d5bb9

File tree

28 files changed

+315
-79
lines changed

28 files changed

+315
-79
lines changed

.DS_Store

0 Bytes
Binary file not shown.

.github/workflows/repo-sync.yml

Lines changed: 14 additions & 11 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,7 @@ jobs:
5757
ui:
5858
- 'ui/**'
5959
upload-api:
60-
- 'upload-api/**'
60+
- 'upload-api/src/**'
6161
migration-sitecore:
6262
- 'upload-api/migration-sitecore/**'
6363
migration-contentful:
@@ -88,11 +88,12 @@ jobs:
8888
git clone https://x-access-token:${{ secrets.GH_PAT }}@github.com/${{ env.SITECORE_REPO }}.git
8989
cd migration-tool-sitecore
9090
git checkout -b sync-from-migration-v2-${{ github.event.pull_request.number }}
91+
git pull origin ${{ env.BRANCH }}
9192
rsync -av --delete ${{ env.RSYNC_SITECORE_API_SRC_SERVICES_EXCLUDES }} ../api/ ./api/
9293
rsync -av --delete ../cli/ ./cli/
9394
rsync -av --delete ../ui/ ./ui/
94-
rsync -av --delete ${{ env.RSYNC_SITECORE_UPLOAD_API_SRC_EXCLUDES }} ../upload-api/ ./upload-api/
95-
rsync -av --delete ../upload-api/migration-sitecore ./upload-api/migration-sitecore
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/
9697
git add .
9798
git commit -m "Sync changes from migration-v2 PR #${{ github.event.pull_request.number }}"
9899
git push origin sync-from-migration-v2-${{ github.event.pull_request.number }}
@@ -117,7 +118,7 @@ jobs:
117118
env:
118119
GH_TOKEN: ${{ secrets.GH_PAT }}
119120

120-
- name: Sync changes to wordpress-repo (if applicable)
121+
- name: Sync changes to contentful-repo (if applicable)
121122
if: |
122123
env.merged == 'true' &&
123124
(
@@ -132,11 +133,12 @@ jobs:
132133
git clone https://x-access-token:${{ secrets.GH_PAT }}@github.com/${{ env.CONTENTFUL_REPO }}.git
133134
cd migration-tool-contentful
134135
git checkout -b sync-from-migration-v2-${{ github.event.pull_request.number }}
136+
git pull origin ${{ env.BRANCH }}
135137
rsync -av --delete ${{ env.RSYNC_CONTENTFUL_API_SRC_SERVICES_EXCLUDES }} ../api/ ./api/
136138
rsync -av --delete ../cli/ ./cli/
137139
rsync -av --delete ../ui/ ./ui/
138-
rsync -av --delete ${{ env.RSYNC_CONTENTFUL_UPLOAD_API_SRC_EXCLUDES }} ../upload-api/ ./upload-api/
139-
rsync -av --delete ../upload-api/migration-contentful ./upload-api/migration-contentful
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/
140142
git add .
141143
git commit -m "Sync changes from migration-v2 PR #${{ github.event.pull_request.number }}"
142144
git push origin sync-from-migration-v2-${{ github.event.pull_request.number }}
@@ -176,11 +178,12 @@ jobs:
176178
git clone https://x-access-token:${{ secrets.GH_PAT }}@github.com/${{ env.WORDPRESS_REPO }}.git
177179
cd migration-tool-wordpress
178180
git checkout -b sync-from-migration-v2-${{ github.event.pull_request.number }}
181+
git pull origin ${{ env.BRANCH }}
179182
rsync -av --delete ${{ env.RSYNC_WORDPRESS_API_SRC_SERVICES_EXCLUDES }} ../api/ ./api/
180183
rsync -av --delete ../cli/ ./cli/
181184
rsync -av --delete ../ui/ ./ui/
182-
rsync -av --delete ${{ env.RSYNC_WORDPRESS_UPLOAD_API_SRC_EXCLUDES }} ../upload-api/ ./upload-api/
183-
rsync -av --delete ../upload-api/migration-wordpress ./upload-api/migration-wordpress
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/
184187
git add .
185188
git commit -m "Sync changes from migration-v2 PR #${{ github.event.pull_request.number }}"
186189
git push origin sync-from-migration-v2-${{ github.event.pull_request.number }}

api/.DS_Store

0 Bytes
Binary file not shown.

api/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ dist/
1717
# Mono auto generated files
1818
mono_crash.*
1919

20+
#MAC DS_Store File
21+
/api/.DS_Store
22+
2023
# Build results
2124
[Dd]ebug/
2225
[Dd]ebugPublic/

api/production.env

Lines changed: 0 additions & 3 deletions
This file was deleted.

api/src/.DS_Store

0 Bytes
Binary file not shown.

api/src/controllers/migration.controller.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Request, Response } from "express";
2-
import { migrationService } from "../services/migration.service.js";
2+
import { migrationService } from "../services/migration.service.js"
33

44
/**
55
* Creates a test stack.
@@ -55,10 +55,22 @@ const getLogs = async (req: Request, res: Response): Promise<void> => {
5555
res.status(200).json(resp);
5656
};
5757

58+
const saveLocales = async (req:Request, res: Response):Promise<void> =>{
59+
const resp = await migrationService.createSourceLocales(req)
60+
res.status(200).json(resp);
61+
}
62+
63+
const saveMappedLocales = async (req:Request, res:Response):Promise<void> =>{
64+
const resp = await migrationService.updateLocaleMapper(req);
65+
res.status(200).json(resp);
66+
}
67+
5868
export const migrationController = {
5969
createTestStack,
6070
deleteTestStack,
6171
startTestMigration,
6272
startMigration,
6373
getLogs,
74+
saveLocales,
75+
saveMappedLocales
6476
};

api/src/routes/migration.routes.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,31 @@ router.get(
6565

6666
)
6767

68+
/**
69+
* Route for updating the source locales from legacy CMS
70+
* @route POST /validator
71+
* @group Migration
72+
* @param {string} projectID - Current project ID
73+
* @body {Object} locales - Fetched Locales
74+
* @returns {Promise<void>} - A promise which resolves when the locales are updated in the DB
75+
*/
76+
router.post(
77+
"/localeMapper/:projectId",
78+
asyncRouter(migrationController.saveLocales)
79+
)
80+
81+
/**
82+
* Route for updating the mapped locales by user
83+
* @route POST /validator
84+
* @group Migration
85+
* @param {string} projectID - Current project ID
86+
* @body {Object} locales - Mapped Locales
87+
* @returns {Promise<void>} - A promise which resolves when the locales are updated in the DB
88+
*/
89+
router.post(
90+
"/updateLocales/:projectId",
91+
asyncRouter(migrationController.saveMappedLocales)
92+
)
93+
6894

6995
export default router;

api/src/services/.DS_Store

6 KB
Binary file not shown.

api/src/services/contentful.service.ts

Lines changed: 32 additions & 21 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,9 +331,9 @@ const processField = (
331331
break;
332332
}
333333
}
334-
335334
};
336335

336+
337337
// Helper function to clean up brackets in non-numeric lang_value
338338
const cleanBrackets = (lang_value: any) => {
339339
const myJSON = JSON.stringify(lang_value);
@@ -437,11 +437,11 @@ const saveAsset = async (
437437
const publishDetails: { environment: any; version: number; locale: any }[] =
438438
[];
439439
const assetsSave = path.join(DATA, destination_stack_id, ASSETS_DIR_NAME);
440-
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) ?? {};
441441
const localeId = await readFile(path.join(DATA, destination_stack_id, LOCALE_DIR_NAME), LOCALE_CF_LANGUAGE);
442442

443443
if (assets.fields.file && assets.fields.title) {
444-
Object.values(environmentsId).forEach((env: any) => {
444+
Object?.values?.(environmentsId)?.length && Object.values(environmentsId).forEach((env: any) => {
445445
if (env?.name === assets?.sys?.environment?.sys?.id) {
446446
Object.values(localeId).forEach((locale: any) => {
447447
publishDetails.push({
@@ -697,6 +697,18 @@ const createEnvironment = async (packagePath: any, destination_stack_id: string,
697697
}
698698
};
699699

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+
700712
/**
701713
* Creates and processes entries from a given package file and saves them to the destination stack directory.
702714
*
@@ -723,7 +735,8 @@ const createEnvironment = async (packagePath: any, destination_stack_id: string,
723735
*
724736
* @throws Will log errors encountered during file reading, processing, or writing of entries.
725737
*/
726-
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)
727740
const srcFunc = 'createEntry';
728741
try {
729742
const entriesSave = path.join(DATA, destination_stack_id, ENTRIES_DIR_NAME);
@@ -736,7 +749,7 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
736749
if (entries && entries.length > 0) {
737750
const assetId = await readFile(assetsSave, ASSETS_SCHEMA_FILE) ?? [];
738751
const entryId = await readFile(path.join(DATA, destination_stack_id, REFERENCES_DIR_NAME), REFERENCES_FILE_NAME);
739-
const environmentsId = await readFile(environmentSave, ENVIRONMENTS_FILE_NAME);
752+
const environmentsId = await readFile(environmentSave, ENVIRONMENTS_FILE_NAME) ?? {};
740753
const displayField: { [key: string]: any } = {}
741754
content.map((item: any) => {
742755
displayField[item.name.toLowerCase().replace(/[^a-z0-9]+/g, "_")] =
@@ -782,13 +795,15 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
782795
});
783796
const pathName = getDisplayName(name, displayField);
784797
locales.forEach((locale) => {
785-
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)
786801
.filter((env: any) => env?.name === environment_id)
787802
?.map((env: any) => ({
788803
environment: env?.uid,
789804
version: 1,
790-
locale: locale.toLowerCase(),
791-
}));
805+
locale: locale?.toLowerCase(),
806+
})) : [];
792807

793808
const title = entryData[name][locale][id][pathName] || "";
794809
const urlTitle = title
@@ -815,21 +830,18 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
815830
);
816831
});
817832
});
818-
819833
return entryData;
820834
},
821835
{}
822836
);
823-
const writePromises = [];
824-
825-
for (const [newKey, values] of Object.entries(result)) {
837+
for await (const [newKey, values] of Object.entries(result)) {
826838
const currentCT = contentTypes?.find((ct: any) => ct?.otherCmsUid === newKey);
827839
const ctName = currentCT?.contentstackUid in mapperKeys ?
828840
mapperKeys?.[currentCT?.contentstackUid] : (currentCT?.contentstackUid ?? newKey.replace(/([A-Z])/g, "_$1").toLowerCase());
829-
for (const [localeKey, localeValues] of Object.entries(
841+
for await (const [localeKey, localeValues] of Object.entries(
830842
values as { [key: string]: any }
831843
)) {
832-
const chunks = await makeChunks(localeValues);
844+
const chunks = makeChunks(localeValues);
833845
for (const [entryKey, entryValue] of Object.entries(localeValues)) {
834846
const message = getLogMessage(
835847
srcFunc,
@@ -844,14 +856,13 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje
844856
entriesSave,
845857
ctName, localeKey.toLowerCase()
846858
);
847-
for (const [chunkId, chunkData] of Object.entries(chunks)) {
859+
for await (const [chunkId, chunkData] of Object.entries(chunks)) {
848860
refs[chunkIndex++] = `${chunkId}-entries.json`;
849-
writePromises.push(writeFile(filePath, `${chunkId}-entries.json`, chunkData))
861+
await writeFile(filePath, `${chunkId}-entries.json`, chunkData)
850862
}
851-
writePromises.push(writeFile(filePath, ENTRIES_MASTER_FILE, refs));
863+
await writeFile(filePath, ENTRIES_MASTER_FILE, refs);
852864
}
853865
}
854-
await Promise.all(writePromises);
855866
} else {
856867
const message = getLogMessage(
857868
srcFunc,

0 commit comments

Comments
 (0)