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
Binary file modified .DS_Store
Binary file not shown.
Binary file modified api/.DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ dist/
# Mono auto generated files
mono_crash.*

#MAC DS_Store File
/api/.DS_Store

# Build results
[Dd]ebug/
[Dd]ebugPublic/
Expand Down
3 changes: 0 additions & 3 deletions api/production.env

This file was deleted.

Binary file modified api/src/.DS_Store
Binary file not shown.
14 changes: 13 additions & 1 deletion api/src/controllers/migration.controller.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -55,10 +55,22 @@ const getLogs = async (req: Request, res: Response): Promise<void> => {
res.status(200).json(resp);
};

const saveLocales = async (req:Request, res: Response):Promise<void> =>{
const resp = await migrationService.createSourceLocales(req)
res.status(200).json(resp);
}

const saveMappedLocales = async (req:Request, res:Response):Promise<void> =>{
const resp = await migrationService.updateLocaleMapper(req);
res.status(200).json(resp);
}

export const migrationController = {
createTestStack,
deleteTestStack,
startTestMigration,
startMigration,
getLogs,
saveLocales,
saveMappedLocales
};
26 changes: 26 additions & 0 deletions api/src/routes/migration.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +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<void>} - 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<void>} - A promise which resolves when the locales are updated in the DB
*/
router.post(
"/updateLocales/:projectId",
asyncRouter(migrationController.saveMappedLocales)
)


export default router;
Binary file added api/src/services/.DS_Store
Binary file not shown.
102 changes: 101 additions & 1 deletion api/src/services/migration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { extensionService } from "./extension.service.js";




/**
* Creates a test stack.
*
Expand Down Expand Up @@ -411,10 +410,111 @@ const getLogs = async (req: Request): Promise<any> => {

}

/**
* @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) => {

const projectFilePath = path.join(process.cwd(), 'database', 'project.json'); // Adjusted path to project.json
const projectId = req.params.projectId;

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.`);
}

// 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].source_locales = 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
);
}
}


/**
* @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,
updateLocaleMapper
};
2 changes: 2 additions & 0 deletions api/src/services/sitecore.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import { orgService } from './org.service.js';
import { getLogMessage } from '../utils/index.js';
import customLogger from '../utils/custom-logger.utils.js';


const append = "a";


const baseDirName = MIGRATION_DATA_CONFIG.DATA
const {
ENTRIES_DIR_NAME,
Expand Down
4 changes: 3 additions & 1 deletion api/src/services/wordpress.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import customLogger from "../utils/custom-logger.utils.js";
import { getLogMessage } from "../utils/index.js";
import { Advanced } from "../models/FieldMapper.js";

const { JSDOM } = jsdom;

const { JSDOM } = jsdom;
const virtualConsole = new jsdom.VirtualConsole();
// Get the current file's path
const __filename = fileURLToPath(import.meta.url);



// Get the current directory
const __dirname = path.dirname(__filename);

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const envContents = {
'Upload-API': uploadAPIEnvContent,
};


// Function to create env files
const createEnvFiles = () => {
// Loop through each key in the envFilePaths object
Expand Down
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
Expand Down
6 changes: 0 additions & 6 deletions ui/.env.local

This file was deleted.

1 change: 1 addition & 0 deletions upload-api/migration-contentful/config/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
},
"fileName": "en-us.json"



}
2 changes: 2 additions & 0 deletions upload-api/migration-sitecore/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const MIGRATION_DATA_CONFIG = {

EXPORT_INFO_FILE: "export-info.json"
}



module.exports = {
MIGRATION_DATA_CONFIG
Expand Down
15 changes: 9 additions & 6 deletions upload-api/migration-sitecore/index.js
Original file line number Diff line number Diff line change
@@ -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
}
29 changes: 29 additions & 0 deletions upload-api/migration-sitecore/libs/extractLocales.js
Original file line number Diff line number Diff line change
@@ -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;
};
6 changes: 3 additions & 3 deletions upload-api/migration-wordpress/config/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
"dirName": "posts",
"fileName": "en-us.json",
"masterfile": "posts.json"
}
}




}
}
}
6 changes: 2 additions & 4 deletions upload-api/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default {
plan: {
dropdown: { optionLimit: 100 }
},
cmsType: 'Wordpress',
cmsType: 'Sitecore',
isLocalPath: true,
awsData: {
awsRegion: 'us-east-2',
Expand All @@ -12,8 +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'
};
3 changes: 2 additions & 1 deletion upload-api/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Loading