From 0eaabed2891b8fdb71272aa18e689df43dda909f Mon Sep 17 00:00:00 2001 From: shobhit upadhyay Date: Wed, 5 Mar 2025 12:26:58 +0530 Subject: [PATCH 1/6] backend locale mapper feature --- api/.DS_Store | Bin 0 -> 6148 bytes api/src/.DS_Store | Bin 0 -> 8196 bytes api/src/controllers/migration.controller.ts | 8 +++- api/src/routes/migration.routes.ts | 5 +++ api/src/services/.DS_Store | Bin 0 -> 6148 bytes api/src/services/migration.service.ts | 42 +++++++++++++++++++ package-lock.json | 17 ++++++++ package.json | 3 +- upload-api/migration-sitecore/index.js | 15 ++++--- upload-api/src/config/index.ts | 4 +- upload-api/src/constants/index.ts | 3 +- upload-api/src/controllers/sitecore/index.ts | 30 ++++++++++++- 12 files changed, 114 insertions(+), 13 deletions(-) create mode 100644 api/.DS_Store create mode 100644 api/src/.DS_Store create mode 100644 api/src/services/.DS_Store diff --git a/api/.DS_Store b/api/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..bda49881c8a335aba2af001ebb82598bfeb4d882 GIT binary patch literal 6148 zcmeHKO-jQ+6n@WE2z1k>%fTD;24jgQ$N`kLP#0-aBD&78bm_(;coX-2@28kza3cf@ z@4?JB^L~>LGA~0!ynNa$h~`98U27-Z+81SxB%topgWrBfV;CvX6^C4jfX2;G@j}A4~Tae+w`!0gx= zLIYt71zITk6@x7t`s9Auu`{%AVy%okUio-=VXY2*Qg`BP7;`WX44g7BvF%*?|1Cb5 zbGfshzD4YUfneY-4Dht9$|W**Z~c)=dTqkE#}E;}P8JZXwG{)k6=Ngk$dww+o@5Ps XcI*r#i|92R7(W6^NKC=N2n>7y3Fs}R literal 0 HcmV?d00001 diff --git a/api/src/.DS_Store b/api/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..79b1a1dc65d6ce92cc0a85b6da30f9b2bd397bc1 GIT binary patch literal 8196 zcmeHMzi-n(6n;+A)*%8aRHU$3bO4D$(w6c=EFlCYgb<-H0BYkVq!x)C*-oP^dch_phhvOts} zA{`sEGig*Yh56YQDGAYX8dgI*kwvw7ZK1U8G@22#YETL&1(X6x0i}Ra;9pPxb2cmb zh>^SUqSW zR1-@KEeMC-U~t&Hu)V+r;iLuOq=_?YVuhmdvm?&naMJRDRkcz;DG*hFt=*?+ogA|1 zadiEj`Z4TpIK`q_cTBYFzh8WNx%>9x)hMPi7Sr62-xK7}1*HTJk9;bFk569cZ9-z@ zbv#Pul=}X8S8$5yui@-5+aDR?msn%`(t@8)F7&G7SH)hKBjt~dM#?a`jxqk zM~C=QFW}oiMl1L+rfq2I!VdABJ;C|LB4xgn4})B%X#{#t+wtfy-!;Z}3jI1@TLs@C zmYMdjU*`66@=HJGp*~~mo|~bb;iYPdrk4|y)&D2%ky)&uUcXvIXN}0PwQ#@QE9_zm;AEd@(N}50Xw?u zICZnXUpDVq)%NPl>@~;s%a&brd4N@^0`l;_WmlYb!D-nQkH?k*hn~_?t23EycWL?J zys@-=X=~o-US7=28|RlUY;C3V<8#?7cUGU&8@BV55y$i^rfE7H91rSe*o$0O=qXPg zc@>9|b$;I&=p5-w&iQ`0klsn2_eft&-@MuKd>4H3RH6>@!S0C$W$7Lt0b1BcUT|E* z)5S)uEUk#Fu~v^ZfHP5B@Sejx)dZ%3;|^>G2=*k^kYg5Y0c+D)8-uN3Fr{6 zw2ZT}F^XNk6CF)YZjZvroaS!q^yi`2K4o^}upyqrPJdv_L~vypw*J39`u+cby?%9J zN&%$+=7MCgR4hP={-ixD3R`O%*w(PI!f?I7@(@%E!rJ+A9Cq-*5c`Jk<%R7979Nzp d{vts9mkN#ZYW|nM+N$|~@cnw5-=hby`U6H2Nwoj~ literal 0 HcmV?d00001 diff --git a/api/src/controllers/migration.controller.ts b/api/src/controllers/migration.controller.ts index 9f46dc4ac..1a94b17ba 100644 --- a/api/src/controllers/migration.controller.ts +++ b/api/src/controllers/migration.controller.ts @@ -1,5 +1,5 @@ import { Request, Response } from "express"; -import { migrationService } from "../services/migration.service.js"; +import { migrationService } from "../services/migration.service.js" /** * Creates a test stack. @@ -55,10 +55,16 @@ const getLogs = async (req: Request, res: Response): Promise => { res.status(200).json(resp); }; +const saveLocales = async (req:Request, res: Response):Promise =>{ + const resp = await migrationService.createSourceLocales(req) + res.status(200).json(resp); +} + export const migrationController = { createTestStack, deleteTestStack, startTestMigration, startMigration, getLogs, + saveLocales }; diff --git a/api/src/routes/migration.routes.ts b/api/src/routes/migration.routes.ts index e22a87cf0..f6c434580 100644 --- a/api/src/routes/migration.routes.ts +++ b/api/src/routes/migration.routes.ts @@ -65,5 +65,10 @@ router.get( ) +router.post( + "/localeMapper/:projectId", + asyncRouter(migrationController.saveLocales) +) + export default router; diff --git a/api/src/services/.DS_Store b/api/src/services/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..920eccd281b1d52c1a8028b23d7aae48a4fd1bde GIT binary patch literal 6148 zcmeHK%}T>S5T30?s$P2V;4v>?q=NTY;z{vRyxX+34YVdSt5#jm++gN zp|qrh3L+viF#GM!&d=uCkj)a2YtQ>Fq9zeFpp3O6G+Tt{Su0Xg%OTMD90Pi$89mXQ z#uaZf{6z+M?~bWQncum!{TmNkonAJ{WzntAU4D}+j+1egV7~Eo`>|ZUzF+V5?eFcI zkJjr)NJ*zOp_GO+r7qsG)UP?Df(Ed>VBAA5#7vRTlDl~^nC}X5p3i?k68h-@<)?xO7KHnucCQytNOF_&)oP+`;)aez& zNjU6*`bCPRpoEjt%ZJm-PH!mAS4aN9yOWCqtu+RWflUSuWZ2~M|7Q37e>2EN#(**K zuNZLkxD&VWNP4zb9*)o20Qv}JVZTyv6@rdGis8#g@fp+$>;ZRxkzy$b3&ef|JPp => { } +export const createSourceLocales = async (req: Request) => { + + console.info("ENTERED MIGRATION API LINE 415") + + const projectFilePath = path.join(process.cwd(), 'database', 'project.json'); // Adjusted path to project.json + const projectId = req.params.projectId; + + console.info("Request Object LINE 420",req.body) + const locales = req.body.locale + + try { + // Check if the project.json file exists + if (!fs.existsSync(projectFilePath)) { + console.error(`project.json not found at ${projectFilePath}`); + throw new Error(`project.json not found.`); + } + + // const data = await fs.promises.readFile(projectFilePath, 'utf8'); + // const projects = JSON.parse(data); + + // Find the project with the specified projectId + const project: any = ProjectModelLowdb.chain.get("projects").find({ id: projectId }).value(); + if (project) { + const index = ProjectModelLowdb.chain.get("projects").findIndex({ id: projectId }).value(); + if (index > -1) { + console.info("INSIDE API IF STATEMENT LINE 437",index ); + + ProjectModelLowdb.update((data: any) => { + // console.info("DATA LINE 439 ", data?.projects?.[index]) + data.projects[index].source_locales = locales; + // console.info(data.projects[index] ) + }); + } // Write back the updated projects + } else { + console.error(`Project with id ${projectId} not found.`); + } + } catch (err) { + console.error('Error updating project.json:', err); + } +} + export const migrationService = { createTestStack, deleteTestStack, startTestMigration, startMigration, getLogs, + createSourceLocales }; diff --git a/package-lock.json b/package-lock.json index ae8a316bf..1ed2d4fab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -121,6 +121,16 @@ "integrity": "sha512-dISoDXWWQwUquiKsyZ4Ng+HX2KsPL7LyHKHQwgGFEA3IaKac4Obd+h2a/a6waisAoepJlBcx9paWqjA8/HVjCw==", "dev": true }, + "node_modules/@types/xml2js": { + "version": "0.4.14", + "resolved": "https://registry.npmjs.org/@types/xml2js/-/xml2js-0.4.14.tgz", + "integrity": "sha512-4YnrRemBShWRO2QjvUin8ESA41rH+9nQGLUGZV/1IDhi3SL9OhdpNC/MrulTWuptXKwhx/aDxE7toV0f/ypIXQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -828,6 +838,13 @@ "node": ">=8" } }, + "node_modules/undici-types": { + "version": "6.20.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz", + "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==", + "dev": true, + "license": "MIT" + }, "node_modules/validate-branch-name": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/validate-branch-name/-/validate-branch-name-1.3.1.tgz", diff --git a/package.json b/package.json index 6b6a76662..742eff064 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "husky": "^4.3.8", "prettier": "^2.4.1", "rimraf": "^3.0.2", - "validate-branch-name": "^1.3.0" + "validate-branch-name": "^1.3.0", + "xml2js":"^0.4.14" }, "husky": { "hooks": {} diff --git a/upload-api/migration-sitecore/index.js b/upload-api/migration-sitecore/index.js index a4cd9a931..772c9c68e 100644 --- a/upload-api/migration-sitecore/index.js +++ b/upload-api/migration-sitecore/index.js @@ -1,15 +1,18 @@ // eslint-disable-next-line @typescript-eslint/no-var-requires -const contentTypes = require("./libs/contenttypes.js"); +import contentTypes from "./libs/contenttypes.js"; // eslint-disable-next-line @typescript-eslint/no-var-requires -const ExtractConfiguration = require("./libs/configuration.js") +import ExtractConfiguration from "./libs/configuration.js" // eslint-disable-next-line @typescript-eslint/no-var-requires -const reference = require("./libs/reference.js"); +import reference from "./libs/reference.js"; // eslint-disable-next-line @typescript-eslint/no-var-requires -const ExtractFiles = require("./libs/convert.js") +import ExtractFiles from "./libs/convert.js" -module.exports = { +import findAndExtractLanguages from './libs/extractLocales.js' + +export { contentTypes, ExtractConfiguration, reference, - ExtractFiles + ExtractFiles, + findAndExtractLanguages } diff --git a/upload-api/src/config/index.ts b/upload-api/src/config/index.ts index 95520dec5..540ea078e 100644 --- a/upload-api/src/config/index.ts +++ b/upload-api/src/config/index.ts @@ -2,7 +2,7 @@ export default { plan: { dropdown: { optionLimit: 100 } }, - cmsType: 'Wordpress', + cmsType: 'Sitecore', isLocalPath: true, awsData: { awsRegion: 'us-east-2', @@ -12,6 +12,6 @@ export default { bucketName: 'migartion-test', buketKey: 'project/package 45.zip' }, - localPath: '/home/gaurishn/Documents/contentstack/sitetitle.xml' //package 45.zip' + localPath: '/Users/shobhit.upadhyay/Downloads/package 47.zip' //package 45.zip' // localPath: '/Users/umesh.more/Documents/ui-migration/migration-v2-node-server/upload-api/extracted_files/package 45.zip' }; diff --git a/upload-api/src/constants/index.ts b/upload-api/src/constants/index.ts index b1a7d5853..6f2ccf3f5 100644 --- a/upload-api/src/constants/index.ts +++ b/upload-api/src/constants/index.ts @@ -22,7 +22,8 @@ export const HTTP_TEXTS = { VALIDATION_SUCCESSFULL: ' File validated successfully.', ZIP_FILE_SAVE: 'Issue While Saving Zip File.', XML_FILE_SAVE: 'Issue While Saving XML File.', - MAPPER_SAVED: 'Mapping process completed successfull.' + MAPPER_SAVED: 'Mapping process completed successfull.', + LOCALE_SAVED: 'Source locales stored successfully' }; export const HTTP_RESPONSE_HEADERS = { diff --git a/upload-api/src/controllers/sitecore/index.ts b/upload-api/src/controllers/sitecore/index.ts index 8e71af502..278c991fe 100644 --- a/upload-api/src/controllers/sitecore/index.ts +++ b/upload-api/src/controllers/sitecore/index.ts @@ -6,7 +6,7 @@ import logger from "../../utils/logger"; import { HTTP_CODES, HTTP_TEXTS, MIGRATION_DATA_CONFIG } from "../../constants"; // eslint-disable-next-line @typescript-eslint/no-var-requires -const { contentTypes, ExtractConfiguration, reference, ExtractFiles } = require('migration-sitecore'); +const { contentTypes, ExtractConfiguration, reference, ExtractFiles, findAndExtractLanguages } = require('migration-sitecore'); const { CONTENT_TYPES_DIR_NAME, @@ -17,6 +17,10 @@ const { const createSitecoreMapper = async (filePath: string = "", projectId: string | string[], app_token: string | string[], affix: string | string[], config: object) => { try { const newPath = path.join(filePath, 'items'); + + const localeData = await findAndExtractLanguages(path.join(filePath, 'items','master','sitecore','content')); + logger.info('Fetched Locales: ', localeData) + await ExtractFiles(newPath); await ExtractConfiguration(newPath); await contentTypes(newPath, affix, config); @@ -57,9 +61,31 @@ const createSitecoreMapper = async (filePath: string = "", projectId: string | s message: HTTP_TEXTS?.MAPPER_SAVED, }); } + + const mapperConfig = { + method: 'post', + maxBodyLength: Infinity, + url: `${process.env.NODE_BACKEND_API}/v2/migration/localeMapper/${projectId}`, + headers: { + app_token, + 'Content-Type': 'application/json' + }, + data: { + locale:Array.from(localeData) + }, + }; + + const mapRes = await axios.request(mapperConfig) + if(mapRes?.status==200){ + logger.info('Validation success', { + status: HTTP_CODES?.OK, + message: HTTP_TEXTS?.LOCALE_SAVED, + }); + } + } } catch (err: any) { - console.error("🚀 ~ createSitecoreMapper ~ err:", err?.response?.data ?? err) + console.error("🚀 ~ createSitecoreMapper ~ err:", err?.response?.data ?? err, err) logger.warn('Validation error:', { status: HTTP_CODES?.UNAUTHORIZED, message: HTTP_TEXTS?.VALIDATION_ERROR, From 46d326663b91250087935f9be31e5c9142cf60c0 Mon Sep 17 00:00:00 2001 From: shobhit upadhyay Date: Wed, 5 Mar 2025 12:33:27 +0530 Subject: [PATCH 2/6] added ds_store in gitignore --- api/.gitignore | 3 +++ api/production.env | 3 --- ui/.env.local | 6 ------ 3 files changed, 3 insertions(+), 9 deletions(-) delete mode 100644 api/production.env delete mode 100644 ui/.env.local diff --git a/api/.gitignore b/api/.gitignore index b2104e9d2..6179ebf9a 100644 --- a/api/.gitignore +++ b/api/.gitignore @@ -17,6 +17,9 @@ dist/ # Mono auto generated files mono_crash.* +#MAC DS_Store File +/api/.DS_Store + # Build results [Dd]ebug/ [Dd]ebugPublic/ diff --git a/api/production.env b/api/production.env deleted file mode 100644 index ceeb1a0bd..000000000 --- a/api/production.env +++ /dev/null @@ -1,3 +0,0 @@ -APP_TOKEN_KEY=MIGRATION_V2 -PORT=5001 - diff --git a/ui/.env.local b/ui/.env.local deleted file mode 100644 index 9be1549ab..000000000 --- a/ui/.env.local +++ /dev/null @@ -1,6 +0,0 @@ -REACT_APP_WEBSITE_BASE_URL="http://localhost:3000/" -REACT_APP_BASE_API_URL="http://localhost:5001/" -REACT_APP_API_VERSION=v2 -REACT_APP_HOST="http://localhost:3000" -REACT_APP_UPLOAD_SERVER="http://localhost:4002/" -REACT_APP_OFFLINE_CMS=true \ No newline at end of file From 15eba1d284c59ec10008dc2975d962539d28fe6e Mon Sep 17 00:00:00 2001 From: shobhit upadhyay Date: Wed, 5 Mar 2025 12:37:20 +0530 Subject: [PATCH 3/6] removed logs --- upload-api/src/controllers/sitecore/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/upload-api/src/controllers/sitecore/index.ts b/upload-api/src/controllers/sitecore/index.ts index 278c991fe..bd7ac74ee 100644 --- a/upload-api/src/controllers/sitecore/index.ts +++ b/upload-api/src/controllers/sitecore/index.ts @@ -42,7 +42,6 @@ const createSitecoreMapper = async (filePath: string = "", projectId: string | s fieldMapping.contentTypes.push(element); } } - // console.log("🚀 ~ createSitecoreMapper ~ fieldMapping:", fieldMapping) const config = { method: 'post', maxBodyLength: Infinity, From 54d0abd7e3569f372fdc93a69a012102d16feab4 Mon Sep 17 00:00:00 2001 From: shobhit upadhyay Date: Wed, 5 Mar 2025 17:25:17 +0530 Subject: [PATCH 4/6] feature/backend locale mapper sitecore --- api/src/controllers/migration.controller.ts | 8 +- api/src/routes/migration.routes.ts | 21 +++++ api/src/services/migration.service.ts | 85 ++++++++++++++++--- upload-api/migration-sitecore/index.js | 2 +- .../migration-sitecore/libs/extractLocales.js | 29 +++++++ upload-api/src/controllers/sitecore/index.ts | 9 +- 6 files changed, 135 insertions(+), 19 deletions(-) create mode 100644 upload-api/migration-sitecore/libs/extractLocales.js diff --git a/api/src/controllers/migration.controller.ts b/api/src/controllers/migration.controller.ts index 1a94b17ba..7c2c1abe4 100644 --- a/api/src/controllers/migration.controller.ts +++ b/api/src/controllers/migration.controller.ts @@ -60,11 +60,17 @@ const saveLocales = async (req:Request, res: Response):Promise =>{ res.status(200).json(resp); } +const saveMappedLocales = async (req:Request, res:Response):Promise =>{ + const resp = await migrationService.updateLocaleMapper(req); + res.status(200).json(resp); +} + export const migrationController = { createTestStack, deleteTestStack, startTestMigration, startMigration, getLogs, - saveLocales + saveLocales, + saveMappedLocales }; diff --git a/api/src/routes/migration.routes.ts b/api/src/routes/migration.routes.ts index f6c434580..fdcefaee6 100644 --- a/api/src/routes/migration.routes.ts +++ b/api/src/routes/migration.routes.ts @@ -65,10 +65,31 @@ router.get( ) +/** + * Route for updating the source locales from legacy CMS + * @route POST /validator + * @group Migration + * @param {string} projectID - Current project ID + * @body {Object} locales - Fetched Locales + * @returns {Promise} - A promise which resolves when the locales are updated in the DB + */ router.post( "/localeMapper/:projectId", asyncRouter(migrationController.saveLocales) ) +/** + * Route for updating the mapped locales by user + * @route POST /validator + * @group Migration + * @param {string} projectID - Current project ID + * @body {Object} locales - Mapped Locales + * @returns {Promise} - A promise which resolves when the locales are updated in the DB + */ +router.post( + "/updateLocales/:projectId", + asyncRouter(migrationController.saveMappedLocales) +) + export default router; diff --git a/api/src/services/migration.service.ts b/api/src/services/migration.service.ts index 5dc2d53d3..3ca247478 100644 --- a/api/src/services/migration.service.ts +++ b/api/src/services/migration.service.ts @@ -410,14 +410,18 @@ const getLogs = async (req: Request): Promise => { } +/** + * @description - This function takes all the fetched locales from the exported data of the legacy CMS and stores/updates them in the project.json in DB + * + * @param req - A request body object with fetched locales [] as payload along with project ID in params + * @return - void + * @throws Exception if the project ID is invalid or the when the path to project.json is incorrect + */ export const createSourceLocales = async (req: Request) => { - console.info("ENTERED MIGRATION API LINE 415") - const projectFilePath = path.join(process.cwd(), 'database', 'project.json'); // Adjusted path to project.json const projectId = req.params.projectId; - console.info("Request Object LINE 420",req.body) const locales = req.body.locale try { @@ -426,36 +430,91 @@ export const createSourceLocales = async (req: Request) => { console.error(`project.json not found at ${projectFilePath}`); throw new Error(`project.json not found.`); } - - // const data = await fs.promises.readFile(projectFilePath, 'utf8'); - // const projects = JSON.parse(data); // Find the project with the specified projectId const project: any = ProjectModelLowdb.chain.get("projects").find({ id: projectId }).value(); if (project) { const index = ProjectModelLowdb.chain.get("projects").findIndex({ id: projectId }).value(); if (index > -1) { - console.info("INSIDE API IF STATEMENT LINE 437",index ); ProjectModelLowdb.update((data: any) => { - // console.info("DATA LINE 439 ", data?.projects?.[index]) data.projects[index].source_locales = locales; - // console.info(data.projects[index] ) }); } // Write back the updated projects } else { - console.error(`Project with id ${projectId} not found.`); + logger.error(`Project with ID: ${projectId} not found`,{ + status: HTTP_CODES?.NOT_FOUND, + message: HTTP_TEXTS?.INVALID_ID + }) } - } catch (err) { - console.error('Error updating project.json:', err); + } catch (err: any) { + console.error("🚀 ~ createSourceLocales ~ err:", err?.response?.data ?? err, err) + logger.warn('Bad Request', { + status: HTTP_CODES?.BAD_REQUEST, + message: HTTP_TEXTS?.INTERNAL_ERROR, + }); + throw new ExceptionFunction( + err?.message || HTTP_TEXTS.INTERNAL_ERROR, + err?.statusCode || err?.status || HTTP_CODES.SERVER_ERROR + ); } } + +/** + * @description - Function retrieves the mapped locales and updates them in the project.json in DB + * @param req - A request body object with mapped locales as payload and project ID in the params + * @return - void + * @throws Exception if the project ID is invalid or the when the path to project.json is incorrect + */ +export const updateLocaleMapper = async (req:Request) =>{ + const mapperObject = req.body.mapper; + const projectFilePath = path.join(process.cwd(), 'database', 'project.json'); // Adjusted path to project.json + const projectId = req.params.projectId; + + try { + // Check if the project.json file exists + if (!fs.existsSync(projectFilePath)) { + console.error(`project.json not found at ${projectFilePath}`); + throw new Error(`project.json not found.`); + } + + // Find the project with the specified projectId + const project: any = ProjectModelLowdb.chain.get("projects").find({ id: projectId }).value(); + if (project) { + const index = ProjectModelLowdb.chain.get("projects").findIndex({ id: projectId }).value(); + if (index > -1) { + ProjectModelLowdb.update((data: any) => { + data.projects[index].master_locale = mapperObject?.master_locale; + data.projects[index].locales = mapperObject?.locales; + }); + } // Write back the updated projects + } else { + logger.error(`Project with ID: ${projectId} not found`,{ + status: HTTP_CODES?.NOT_FOUND, + message: HTTP_TEXTS?.INVALID_ID + }) + } + } catch (err: any) { + console.error("🚀 ~ createSourceLocales ~ err:", err?.response?.data ?? err, err) + logger.warn('Bad Request', { + status: HTTP_CODES?.BAD_REQUEST, + message: HTTP_TEXTS?.INTERNAL_ERROR, + }); + throw new ExceptionFunction( + err?.message || HTTP_TEXTS.INTERNAL_ERROR, + err?.statusCode || err?.status || HTTP_CODES.SERVER_ERROR + ); + } + +} + export const migrationService = { createTestStack, deleteTestStack, startTestMigration, startMigration, getLogs, - createSourceLocales + createSourceLocales, + updateLocaleMapper }; diff --git a/upload-api/migration-sitecore/index.js b/upload-api/migration-sitecore/index.js index 772c9c68e..0f5977b86 100644 --- a/upload-api/migration-sitecore/index.js +++ b/upload-api/migration-sitecore/index.js @@ -7,7 +7,7 @@ import reference from "./libs/reference.js"; // eslint-disable-next-line @typescript-eslint/no-var-requires import ExtractFiles from "./libs/convert.js" -import findAndExtractLanguages from './libs/extractLocales.js' +import {findAndExtractLanguages} from './libs/extractLocales.js' export { contentTypes, diff --git a/upload-api/migration-sitecore/libs/extractLocales.js b/upload-api/migration-sitecore/libs/extractLocales.js new file mode 100644 index 000000000..8526f1389 --- /dev/null +++ b/upload-api/migration-sitecore/libs/extractLocales.js @@ -0,0 +1,29 @@ +import fs from 'fs' +import path from 'path' + +const uniqueLanguages = new Set(); // Define uniqueLanguages globally or pass it as a parameter + +export const findAndExtractLanguages = (dir) => { + const items = fs.readdirSync(dir, { withFileTypes: true }); + + for (const item of items) { + const fullPath = path.join(dir, item.name); + + if (item.isDirectory()) { + findAndExtractLanguages(fullPath); // Proper recursion + } else if (item.isFile() && item.name === "data.json.json") { + try { + const rawData = fs.readFileSync(fullPath, "utf8"); + const jsonData = JSON.parse(rawData); + const language = jsonData?.item?.$?.language; + + if (language) { + uniqueLanguages.add(language); + } + } catch (error) { + console.error(`Error reading ${fullPath}:`, error.message); + } + } + } + return uniqueLanguages; +}; diff --git a/upload-api/src/controllers/sitecore/index.ts b/upload-api/src/controllers/sitecore/index.ts index bd7ac74ee..f4b129af3 100644 --- a/upload-api/src/controllers/sitecore/index.ts +++ b/upload-api/src/controllers/sitecore/index.ts @@ -19,7 +19,8 @@ const createSitecoreMapper = async (filePath: string = "", projectId: string | s const newPath = path.join(filePath, 'items'); const localeData = await findAndExtractLanguages(path.join(filePath, 'items','master','sitecore','content')); - logger.info('Fetched Locales: ', localeData) + console.log("Fetched Locales: ", localeData); + await ExtractFiles(newPath); await ExtractConfiguration(newPath); @@ -76,15 +77,15 @@ const createSitecoreMapper = async (filePath: string = "", projectId: string | s const mapRes = await axios.request(mapperConfig) if(mapRes?.status==200){ - logger.info('Validation success', { + logger.info('Locales Saved', { status: HTTP_CODES?.OK, message: HTTP_TEXTS?.LOCALE_SAVED, - }); + }); } } } catch (err: any) { - console.error("🚀 ~ createSitecoreMapper ~ err:", err?.response?.data ?? err, err) + console.error("🚀 ~ createSitecoreMapper ~ err:", err?.response?.data ?? err) logger.warn('Validation error:', { status: HTTP_CODES?.UNAUTHORIZED, message: HTTP_TEXTS?.VALIDATION_ERROR, From b28255f1993eab3d5e50adab6f274888b487eb52 Mon Sep 17 00:00:00 2001 From: shobhit upadhyay Date: Thu, 6 Mar 2025 11:50:54 +0530 Subject: [PATCH 5/6] merge conflict resolved --- .github/workflows/repo-sync.yml | 32 +++++++++--- api/src/services/contentful.service.ts | 55 ++++++++++++--------- api/src/services/contentful/jsonRTE.ts | 4 +- api/src/services/migration.service.ts | 8 +-- api/src/utils/content-type-creator.utils.ts | 2 +- api/src/utils/test-folder-creator.utils.ts | 39 ++++++++------- 6 files changed, 83 insertions(+), 57 deletions(-) diff --git a/.github/workflows/repo-sync.yml b/.github/workflows/repo-sync.yml index 8390d55f5..0e5aeddcc 100644 --- a/.github/workflows/repo-sync.yml +++ b/.github/workflows/repo-sync.yml @@ -14,9 +14,9 @@ env: 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 RSYNC_CONTENTFUL_API_SRC_SERVICES_EXCLUDES: "--exclude 'src/services/wordpress.service.ts' --exclude 'src/services/sitecore.service.ts'" # Include only contentful services 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 - 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 - 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 - 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 + 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 + 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 + 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 jobs: sync-on-merge: runs-on: ubuntu-latest @@ -57,7 +57,13 @@ jobs: ui: - 'ui/**' upload-api: - - 'upload-api/**' + - 'upload-api/src/**' + migration-sitecore: + - 'upload-api/migration-sitecore/**' + migration-contentful: + - 'upload-api/migration-contentful/**' + migration-wordpress: + - 'upload-api/migration-wordpress/**' index: - 'index.js' @@ -75,16 +81,19 @@ jobs: steps.file_changes.outputs.cli == 'true' || steps.file_changes.outputs.ui == 'true' || steps.file_changes.outputs.upload-api == 'true' || + steps.file_changes.outputs.migration-sitecore == 'true' || steps.file_changes.outputs.index == 'true' ) run: | git clone https://x-access-token:${{ secrets.GH_PAT }}@github.com/${{ env.SITECORE_REPO }}.git cd migration-tool-sitecore git checkout -b sync-from-migration-v2-${{ github.event.pull_request.number }} + git pull origin ${{ env.BRANCH }} rsync -av --delete ${{ env.RSYNC_SITECORE_API_SRC_SERVICES_EXCLUDES }} ../api/ ./api/ rsync -av --delete ../cli/ ./cli/ rsync -av --delete ../ui/ ./ui/ - rsync -av --delete ${{ env.RSYNC_SITECORE_UPLOAD_API_SRC_EXCLUDES }} ../upload-api/ ./upload-api/ + rsync -av --delete ${{ env.RSYNC_SITECORE_UPLOAD_API_SRC_EXCLUDES }} ../upload-api/src/ ./upload-api/src/ + rsync -av --delete ../upload-api/migration-sitecore/ ./upload-api/migration-sitecore/ git add . git commit -m "Sync changes from migration-v2 PR #${{ github.event.pull_request.number }}" git push origin sync-from-migration-v2-${{ github.event.pull_request.number }} @@ -97,6 +106,7 @@ jobs: steps.file_changes.outputs.cli == 'true' || steps.file_changes.outputs.ui == 'true' || steps.file_changes.outputs.upload-api == 'true' || + steps.file_changes.outputs.migration-sitecore == 'true' || steps.file_changes.outputs.index == 'true' ) run: | @@ -116,16 +126,19 @@ jobs: steps.file_changes.outputs.cli == 'true' || steps.file_changes.outputs.ui == 'true' || steps.file_changes.outputs.upload-api == 'true' || + steps.file_changes.outputs.migration-contentful == 'true' || steps.file_changes.outputs.index == 'true' ) run: | git clone https://x-access-token:${{ secrets.GH_PAT }}@github.com/${{ env.CONTENTFUL_REPO }}.git cd migration-tool-contentful git checkout -b sync-from-migration-v2-${{ github.event.pull_request.number }} + git pull origin ${{ env.BRANCH }} rsync -av --delete ${{ env.RSYNC_CONTENTFUL_API_SRC_SERVICES_EXCLUDES }} ../api/ ./api/ rsync -av --delete ../cli/ ./cli/ rsync -av --delete ../ui/ ./ui/ - rsync -av --delete ${{ env.RSYNC_CONTENTFUL_UPLOAD_API_SRC_EXCLUDES }} ../upload-api/ ./upload-api/ + rsync -av --delete ${{ env.RSYNC_CONTENTFUL_UPLOAD_API_SRC_EXCLUDES }} ../upload-api/src/ ./upload-api/src/ + rsync -av --delete ../upload-api/migration-contentful/ ./upload-api/migration-contentful/ git add . git commit -m "Sync changes from migration-v2 PR #${{ github.event.pull_request.number }}" git push origin sync-from-migration-v2-${{ github.event.pull_request.number }} @@ -138,6 +151,7 @@ jobs: steps.file_changes.outputs.cli == 'true' || steps.file_changes.outputs.ui == 'true' || steps.file_changes.outputs.upload-api == 'true' || + steps.file_changes.outputs.migration-contentful == 'true' || steps.file_changes.outputs.index == 'true' ) run: | @@ -157,16 +171,19 @@ jobs: steps.file_changes.outputs.cli == 'true' || steps.file_changes.outputs.ui == 'true' || steps.file_changes.outputs.upload-api == 'true' || + steps.file_changes.outputs.migration-wordpress == 'true' || steps.file_changes.outputs.index == 'true' ) run: | git clone https://x-access-token:${{ secrets.GH_PAT }}@github.com/${{ env.WORDPRESS_REPO }}.git cd migration-tool-wordpress git checkout -b sync-from-migration-v2-${{ github.event.pull_request.number }} + git pull origin ${{ env.BRANCH }} rsync -av --delete ${{ env.RSYNC_WORDPRESS_API_SRC_SERVICES_EXCLUDES }} ../api/ ./api/ rsync -av --delete ../cli/ ./cli/ rsync -av --delete ../ui/ ./ui/ - rsync -av --delete ${{ env.RSYNC_WORDPRESS_UPLOAD_API_SRC_EXCLUDES }} ../upload-api/ ./upload-api/ + rsync -av --delete ${{ env.RSYNC_WORDPRESS_UPLOAD_API_SRC_EXCLUDES }} ../upload-api/src/ ./upload-api/src/ + rsync -av --delete ../upload-api/migration-wordpress/ ./upload-api/migration-wordpress/ git add . git commit -m "Sync changes from migration-v2 PR #${{ github.event.pull_request.number }}" git push origin sync-from-migration-v2-${{ github.event.pull_request.number }} @@ -179,6 +196,7 @@ jobs: steps.file_changes.outputs.cli == 'true' || steps.file_changes.outputs.ui == 'true' || steps.file_changes.outputs.upload-api == 'true' || + steps.file_changes.outputs.migration-wordpress == 'true' || steps.file_changes.outputs.index == 'true' ) run: | diff --git a/api/src/services/contentful.service.ts b/api/src/services/contentful.service.ts index 97c223d37..4c28afae2 100644 --- a/api/src/services/contentful.service.ts +++ b/api/src/services/contentful.service.ts @@ -10,7 +10,7 @@ import { JSDOM } from "jsdom"; import { jsonToHtml, jsonToMarkdown, htmlToJson } from '@contentstack/json-rte-serializer'; -import { CHUNK_SIZE, MIGRATION_DATA_CONFIG } from "../constants/index.js"; +import { CHUNK_SIZE, MIGRATION_DATA_CONFIG, LOCALE_MAPPER } from "../constants/index.js"; import { Locale } from "../models/types.js"; import jsonRTE from "./contentful/jsonRTE.js"; import { getAllLocales, getLogMessage } from "../utils/index.js"; @@ -234,7 +234,7 @@ const processField = ( return assetsData; } else { const id = lang_value?.sys?.id; - if (id in assetId) { + if (assetId && id in assetId) { return assetId?.[id] } return null; @@ -253,7 +253,7 @@ const processField = ( return refs; } const id = lang_value?.sys?.id; - if (id in entryId) return [[entryId?.[id]]]; + if (entryId && id in entryId) return [[entryId?.[id]]]; return null; } @@ -331,11 +331,9 @@ const processField = ( break; } } - - - }; + // Helper function to clean up brackets in non-numeric lang_value const cleanBrackets = (lang_value: any) => { const myJSON = JSON.stringify(lang_value); @@ -439,11 +437,11 @@ const saveAsset = async ( const publishDetails: { environment: any; version: number; locale: any }[] = []; const assetsSave = path.join(DATA, destination_stack_id, ASSETS_DIR_NAME); - const environmentsId = await readFile(path.join(DATA, destination_stack_id, ENVIRONMENTS_DIR_NAME), ENVIRONMENTS_FILE_NAME); + const environmentsId = await readFile(path.join(DATA, destination_stack_id, ENVIRONMENTS_DIR_NAME), ENVIRONMENTS_FILE_NAME) ?? {}; const localeId = await readFile(path.join(DATA, destination_stack_id, LOCALE_DIR_NAME), LOCALE_CF_LANGUAGE); if (assets.fields.file && assets.fields.title) { - Object.values(environmentsId).forEach((env: any) => { + Object?.values?.(environmentsId)?.length && Object.values(environmentsId).forEach((env: any) => { if (env?.name === assets?.sys?.environment?.sys?.id) { Object.values(localeId).forEach((locale: any) => { publishDetails.push({ @@ -699,6 +697,18 @@ const createEnvironment = async (packagePath: any, destination_stack_id: string, } }; +const mapLocales = ({ masterLocale, locale, locales }: any) => { + if (locales?.masterLocale?.[masterLocale ?? ''] === locale) { + return Object?.keys(locales?.masterLocale)?.[0] + } + for (const [key, value] of Object?.entries?.(locales) ?? {}) { + if (typeof value !== 'object' && value === locale) { + return key; + } + } + return locale.toLowerCase(); +} + /** * Creates and processes entries from a given package file and saves them to the destination stack directory. * @@ -725,7 +735,8 @@ const createEnvironment = async (packagePath: any, destination_stack_id: string, * * @throws Will log errors encountered during file reading, processing, or writing of entries. */ -const createEntry = async (packagePath: any, destination_stack_id: string, projectId: string, contentTypes: any, mapperKeys: any): Promise => { +const createEntry = async (packagePath: any, destination_stack_id: string, projectId: string, contentTypes: any, mapperKeys: any, master_locale: string): Promise => { + console.info("🚀 ~ createEntry ~ master_locale:", master_locale) const srcFunc = 'createEntry'; try { 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 if (entries && entries.length > 0) { const assetId = await readFile(assetsSave, ASSETS_SCHEMA_FILE) ?? []; const entryId = await readFile(path.join(DATA, destination_stack_id, REFERENCES_DIR_NAME), REFERENCES_FILE_NAME); - const environmentsId = await readFile(environmentSave, ENVIRONMENTS_FILE_NAME); + const environmentsId = await readFile(environmentSave, ENVIRONMENTS_FILE_NAME) ?? {}; const displayField: { [key: string]: any } = {} content.map((item: any) => { displayField[item.name.toLowerCase().replace(/[^a-z0-9]+/g, "_")] = @@ -784,13 +795,15 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje }); const pathName = getDisplayName(name, displayField); locales.forEach((locale) => { - const publishDetails = Object?.values?.(environmentsId) + const localeCode = mapLocales({ masterLocale: master_locale, locale, locales: LOCALE_MAPPER }); + console.info("🚀 ~ locales.forEach ~ localeCode:", localeCode); + const publishDetails = Object?.values?.(environmentsId)?.length ? Object?.values?.(environmentsId) .filter((env: any) => env?.name === environment_id) ?.map((env: any) => ({ environment: env?.uid, version: 1, - locale: locale.toLowerCase(), - })); + locale: locale?.toLowerCase(), + })) : []; const title = entryData[name][locale][id][pathName] || ""; const urlTitle = title @@ -817,21 +830,18 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje ); }); }); - return entryData; }, {} ); - const writePromises = []; - - for (const [newKey, values] of Object.entries(result)) { + for await (const [newKey, values] of Object.entries(result)) { const currentCT = contentTypes?.find((ct: any) => ct?.otherCmsUid === newKey); const ctName = currentCT?.contentstackUid in mapperKeys ? mapperKeys?.[currentCT?.contentstackUid] : (currentCT?.contentstackUid ?? newKey.replace(/([A-Z])/g, "_$1").toLowerCase()); - for (const [localeKey, localeValues] of Object.entries( + for await (const [localeKey, localeValues] of Object.entries( values as { [key: string]: any } )) { - const chunks = await makeChunks(localeValues); + const chunks = makeChunks(localeValues); for (const [entryKey, entryValue] of Object.entries(localeValues)) { const message = getLogMessage( srcFunc, @@ -846,14 +856,13 @@ const createEntry = async (packagePath: any, destination_stack_id: string, proje entriesSave, ctName, localeKey.toLowerCase() ); - for (const [chunkId, chunkData] of Object.entries(chunks)) { + for await (const [chunkId, chunkData] of Object.entries(chunks)) { refs[chunkIndex++] = `${chunkId}-entries.json`; - writePromises.push(writeFile(filePath, `${chunkId}-entries.json`, chunkData)) + await writeFile(filePath, `${chunkId}-entries.json`, chunkData) } - writePromises.push(writeFile(filePath, ENTRIES_MASTER_FILE, refs)); + await writeFile(filePath, ENTRIES_MASTER_FILE, refs); } } - await Promise.all(writePromises); } else { const message = getLogMessage( srcFunc, diff --git a/api/src/services/contentful/jsonRTE.ts b/api/src/services/contentful/jsonRTE.ts index f4bf92cd2..ec998be50 100755 --- a/api/src/services/contentful/jsonRTE.ts +++ b/api/src/services/contentful/jsonRTE.ts @@ -250,7 +250,7 @@ function parseBlockReference(obj: any, lang?: LangType, destination_stack_id?: S function parseInlineReference(obj: any, lang?: LangType, destination_stack_id?: StackId): any { 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)); - const entry = Object.entries(entryId).find(([arrayKey, arrayValue]) => arrayKey === lang && arrayValue[obj.data.target.sys.id]); + const entry = entryId && Object.entries(entryId).find(([arrayKey, arrayValue]) => arrayKey === lang && arrayValue[obj.data.target.sys.id]); if (entry) { const [arrayKey, arrayValue] = entry; @@ -315,8 +315,6 @@ function parseBlockAsset(obj: any, lang?: LangType, destination_stack_id?: Stack } - - function parseBlockquote(obj: any): any { const children = obj.content.map((e: any) => parsers.get(e.nodeType)?.(e)).filter(Boolean); return { diff --git a/api/src/services/migration.service.ts b/api/src/services/migration.service.ts index 3ca247478..15ea20cdc 100644 --- a/api/src/services/migration.service.ts +++ b/api/src/services/migration.service.ts @@ -259,7 +259,7 @@ const startTestMigration = async (req: Request): Promise => { 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); + await contentfulService?.createEntry(file_path, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale); await contentfulService?.createVersionFile(project?.current_test_stack_id, projectId); break; } @@ -299,8 +299,8 @@ const startMigration = async (req: Request): Promise => { await customLogger(projectId, project?.destination_stack_id, 'info', message); await setLogFilePath(loggerPath); const contentTypes = await fieldAttacher({ orgId, projectId, destinationStackId: project?.destination_stack_id, region, user_id }); - await marketPlaceAppService?.createAppManifest({ orgId, destinationStackId: project?.current_test_stack_id, region, userId: user_id }); - await extensionService?.createExtension({ destinationStackId: project?.current_test_stack_id }); + await marketPlaceAppService?.createAppManifest({ orgId, destinationStackId: project?.destination_stack_id, region, userId: user_id }); + await extensionService?.createExtension({ destinationStackId: project?.destination_stack_id }); switch (cms) { case CMS.SITECORE_V8: case CMS.SITECORE_V9: @@ -337,7 +337,7 @@ const startMigration = async (req: Request): Promise => { 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?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys); + await contentfulService?.createEntry(file_path, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale); await contentfulService?.createVersionFile(project?.destination_stack_id, projectId); break; } diff --git a/api/src/utils/content-type-creator.utils.ts b/api/src/utils/content-type-creator.utils.ts index 290130ca7..664240182 100644 --- a/api/src/utils/content-type-creator.utils.ts +++ b/api/src/utils/content-type-creator.utils.ts @@ -748,7 +748,7 @@ export const contenTypeMaker = async ({ contentType, destinationStackId, project if (currentCt?.uid) { ct = await mergeTwoCts(ct, currentCt); } - if (ct?.uid) { + if (ct?.uid && ct?.schema?.length) { if (contentType?.type === 'global_field') { const globalSave = path.join(MIGRATION_DATA_CONFIG.DATA, destinationStackId, GLOBAL_FIELDS_DIR_NAME); const message = getLogMessage(srcFunc, `Global Field ${ct?.uid} has been successfully Transformed.`, {}); diff --git a/api/src/utils/test-folder-creator.utils.ts b/api/src/utils/test-folder-creator.utils.ts index cdbafae4c..f3d95b32a 100644 --- a/api/src/utils/test-folder-creator.utils.ts +++ b/api/src/utils/test-folder-creator.utils.ts @@ -8,7 +8,6 @@ const { ENTRIES_DIR_NAME, ASSETS_DIR_NAME, ASSETS_SCHEMA_FILE, - CONTENT_TYPES_DIR_NAME, CONTENT_TYPES_SCHEMA_FILE, ENTRIES_MASTER_FILE, GLOBAL_FIELDS_DIR_NAME, @@ -240,22 +239,24 @@ const sortGlobalField = async (baseDir: string, finalData: any) => { } } -const sortContentType = async (baseDir: string, finalData: any) => { - const contentTypePath: string = path.join(process.cwd(), baseDir, CONTENT_TYPES_DIR_NAME); - const contentSave = path.join(baseDir, CONTENT_TYPES_DIR_NAME); - const ctData = await JSON.parse(await fs.promises.readFile(path.join(contentTypePath, CONTENT_TYPES_SCHEMA_FILE), 'utf8')); - await sortGlobalField(baseDir, finalData); - const contentTypes: any = []; - for await (const ct of finalData) { - const findCtData = ctData?.find((ele: any) => ele?.uid === ct?.contentType); - await lookForReference(findCtData, finalData); - contentTypes?.push(findCtData); - } - await deleteFolderAsync(contentTypePath); - for await (const ctItem of contentTypes) { - await saveContent(ctItem, contentSave); - } -} +//this code can be used in feature + +// const sortContentType = async (baseDir: string, finalData: any) => { +// const contentTypePath: string = path.join(process.cwd(), baseDir, CONTENT_TYPES_DIR_NAME); +// const contentSave = path.join(baseDir, CONTENT_TYPES_DIR_NAME); +// const ctData = await JSON.parse(await fs.promises.readFile(path.join(contentTypePath, CONTENT_TYPES_SCHEMA_FILE), 'utf8')); +// await sortGlobalField(baseDir, finalData); +// const contentTypes: any = []; +// for await (const ct of finalData) { +// const findCtData = ctData?.find((ele: any) => ele?.uid === ct?.contentType); +// await lookForReference(findCtData, finalData); +// contentTypes?.push(findCtData); +// } +// await deleteFolderAsync(contentTypePath); +// for await (const ctItem of contentTypes) { +// await saveContent(ctItem, contentSave); +// } +// } @@ -275,7 +276,7 @@ export const testFolderCreator = async ({ destinationStackId }: any) => { const pathParts = normalizedPath.split(path.sep); const ct = pathParts?.[0]; // First directory const locale = pathParts?.[1]; // Second directory - allData?.push({ contentType: ct, count: Object?.keys?.(entryData)?.length, entryData, filePath, locale }) + allData?.push({ contentType: ct, count: Object?.keys?.(entryData)?.length ?? 0, entryData, filePath, locale }) } } } @@ -292,7 +293,7 @@ export const testFolderCreator = async ({ destinationStackId }: any) => { finalData?.push({ contentType: et?.contentType, entryObj, locale: et?.locale }); }); await sortAssets(baseDir); - await sortContentType(baseDir, finalData); + // await sortContentType(baseDir, finalData); await deleteFolderAsync(entryDelete); for await (const entry of finalData) { const fileMeta = { "1": `${entry?.locale}.json` }; From b9cfb5c707e740711ab9f2fd4d5dcfb5c71d4a60 Mon Sep 17 00:00:00 2001 From: shobhit upadhyay Date: Thu, 6 Mar 2025 12:05:41 +0530 Subject: [PATCH 6/6] update workflow --- .github/workflows/repo-sync.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/repo-sync.yml b/.github/workflows/repo-sync.yml index 0e5aeddcc..ca59d16b6 100644 --- a/.github/workflows/repo-sync.yml +++ b/.github/workflows/repo-sync.yml @@ -118,7 +118,7 @@ jobs: env: GH_TOKEN: ${{ secrets.GH_PAT }} - - name: Sync changes to wordpress-repo (if applicable) + - name: Sync changes to contentful-repo (if applicable) if: | env.merged == 'true' && (