Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,7 @@ MigrationBackup/

uploade-api/node_modules
uploade-api/build
package-lock.json
package-lock.json
ui/.env
uplaode-api/sitecoreMigrationData
uplaode-api/extracted_files
5 changes: 0 additions & 5 deletions api/example.env

This file was deleted.

4 changes: 4 additions & 0 deletions api/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import fs from "fs";

const connectToDatabase = async () => {
try {
// await mongoose.connect(config.MONGODB_URI, {
// ...(config.APP_ENV === "production" ? { autoIndex: false } : {}),
// });
//check if the database folder exists
if (!fs.existsSync("./database")) {
fs.mkdirSync("./database");
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/services/contentMapper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const putTestData = async (req: Request) => {
return { id, isDeleted: true, ...field };
});
FieldMapperModel.update((data: any) => {
data.field_mapper = [...data?.field_mapper, ...fields];
data.field_mapper = [...data?.field_mapper ?? [], ...fields];
});
contentTypes[index].fieldMapping = fieldIds;
});
Expand All @@ -44,7 +44,7 @@ const putTestData = async (req: Request) => {
const contentType = contentTypes.map((item: any) => {
const id = uuidv4();
contentIds.push(id);
return { id, ...item };
return { ...item, id };
});

await ContentTypesMapperModelLowdb.update((data: any) => {
Expand Down
3 changes: 2 additions & 1 deletion uplaode-api/.env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PORT=4002
PORT=4002
NODE_BACKEND_API =http://localhost:5000
3 changes: 2 additions & 1 deletion uplaode-api/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
"root": true,
"env": {
"browser": true,
"node": true,
"es2021": true
},
"extends": ["prettier", "eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2022,
"project": ["./tsconfig.json"],
"project": [],
"sourceType": "module"
},
"plugins": ["@typescript-eslint", "prettier"],
Expand Down
7 changes: 7 additions & 0 deletions uplaode-api/migration-sitecore/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
csMigrationData
node_modules
logs
sitecoreMigrationData
Alaska
data
_
135 changes: 135 additions & 0 deletions uplaode-api/migration-sitecore/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/* eslint-disable @typescript-eslint/no-var-requires */
var path = require("path"),
chalk = require("chalk"),
fs = require("fs"),
inquirer = require("inquirer"),
sequence = require("when/sequence"),
helper = require("./utils/helper");

_ = require("lodash");
const Messages = require("./utils/message");
const messages = new Messages("wordpress").msgs;

config = require("./config");
global.errorLogger = require("./utils/logger")("error").error;
global.successLogger = require("./utils/logger")("success").log;
global.warnLogger = require("./utils/logger")("warn").log;

var modulesList = [
// "convert",
// "configuration",
// "assets",
"contenttypes",
"reference",
// "template",
"entries",
// "staticHtml",
]; //to create entries
// var contentList = ["convert"]; // to create content type for the entries
var _export = [];

const migFunction = () => {
try {
global.filePath = undefined;
// Module List for Entries
for (var i = 0, total = modulesList.length; i < total; i++) {
var ModuleExport = require("./libs/" + modulesList[i] + ".js");
var moduleExport = new ModuleExport();
_export.push(
(function (moduleExport) {
return function () {
return moduleExport.start();
};
})(moduleExport)
);
}

// Content List
//create schema for the entries we have created
// for (var i = 0, total = contentList.length; i < total; i++) {
// var ContentExport = require("./content_types/" + contentList[i] + ".js");
// var contentExport = new ContentExport();
// _export.push(
// (function (contentExport) {
// return function () {
// return contentExport.start();
// };
// })(contentExport)
// );
// }
} catch (error) {
console.log(error.message);
}

var taskResults = sequence(_export);

taskResults
.then(async function (results) {
console.log(chalk.green("\Data exporting has been completed"));
})
.catch(function (error) {
errorLogger(error);
});
};

// to check if file exist or not
// const fileCheck = (csFileName, csFilePath) => {
// const allowedExtension = ".xml";
// const extension = path.extname(global.config.xml_filename);
// if (allowedExtension === extension) {
// if (fs.existsSync(global.config.xml_filename)) {
// migFunction();
// } else {
// console.log(
// chalk.red(`Please check`),
// chalk.yellow(`File name "${csFileName}"`),
// chalk.red(`or`),
// chalk.yellow(`Filepath "${csFilePath}"`),
// chalk.red(`are valid or not and try again!`)
// );
// XMLMigration();
// }
// } else {
// console.log(chalk.red("use only .xml extension file"));
// }
// };

module.exports = XMLMigration = async () => {
const question = [
{
type: "input",
name: "csFilePath",
message: messages.promptFilePath,
validate: (csFilePath) => {
if (!csFilePath || csFilePath.trim() === "") {
console.log(chalk.red("Please insert filepath!"));
return false;
}
this.name = csFilePath;
return true;
},
},
];

inquirer.prompt(question).then(async (answer) => {
try {
global.config.sitecore_folder =
// answer?.csFilePath
// "/Users/umesh.more/Downloads/history-only/items"
// "/Users/umesh.more/Downloads/package 75/items/master/sitecore/content/Common/Configuration"
// "/Users/umesh.more/Downloads/package 81/items";
// "/Users/umesh.more/Downloads/package 82/items",
// "/Users/umesh.more/Documents/package 2/items"
// "/Users/umesh.more/Downloads/package 77/items"
// "/Users/umesh.more/Downloads/package 45/items/master/sitecore/content"
// "/Users/umesh.more/Downloads/package 45/items/master/sitecore/content"
// "/Users/umesh.more/Documents/package/items"
"/Users/umesh.more/Downloads/package 45/items"
// "/Users/umesh.more/Downloads/package 45/items/master/sitecore/templates"
// "/Users/umesh.more/Downloads/package 45/items/master/sitecore/content/Common/Configuration"
migFunction();
} catch (error) {
console.log(chalk.red(error.message));
}
});
};
5 changes: 5 additions & 0 deletions uplaode-api/migration-sitecore/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
import contentTypes from "./libs/contenttypes.js";

// module.exports = { contentTypes = contentTypes?.ExtractContentTypes };
export default contentTypes;
15 changes: 15 additions & 0 deletions uplaode-api/migration-sitecore/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const contentTypes = require("./libs/contenttypes.js");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const ExtractConfiguration = require("./libs/configuration.js")
// eslint-disable-next-line @typescript-eslint/no-var-requires
const reference = require("./libs/reference.js");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const ExtractFiles = require("./libs/convert.js")

module.exports = {
contentTypes,
ExtractConfiguration,
reference,
ExtractFiles
}
72 changes: 72 additions & 0 deletions uplaode-api/migration-sitecore/libs/configuration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require("path");
const read = require("fs-readdir-recursive");
const helper = require("../utils/helper");


const assignFolderName = ({ path }) => {
const spliter = "/sitecore";
const newPath = path.split(spliter)?.[1];
return `${spliter}${newPath}`;
}




function ExtractConfiguration(sitecore_folder) {
const xml_folder = read(sitecore_folder);
const obj = {};
const treeObj = {};
for (let i = 0; i < xml_folder?.length; i++) {
if ((xml_folder?.[i]?.includes("data.json") || xml_folder?.[i]?.includes("data.json.json")) && !xml_folder?.[i]?.includes("undefined.json")) {
const path = xml_folder?.[i]
const data = helper?.readFile(`${sitecore_folder}/${xml_folder?.[i]}`)
if (data?.item?.$?.template === "configuration group") {
let newPath = path?.split("/{")?.[0];
const groupPath = read(`${sitecore_folder}/${newPath}`)
let arrayValue = [];
let multiValueArrayTree = [];
groupPath?.forEach((item) => {
if ((item?.includes("data.json") || item?.includes("data.json.json")) && !item?.includes("undefined.json")) {
const conf = helper?.readFile(`${sitecore_folder}/${newPath}/${item}`)
const value = conf?.item?.fields?.field?.find((item) => item?.$?.key === "value")
if (value) {
arrayValue.push({ key: conf?.item?.$?.name, value: value?.content !== "" ? value?.content : conf?.item?.$?.name })
} else {
arrayValue.push({ value: conf?.item?.$?.name })
}
multiValueArrayTree.push({ key: conf?.item?.$?.name, value: conf?.item?.$?.id })
}
})
obj[assignFolderName({ path: `${sitecore_folder}/${newPath}` })] = arrayValue;
treeObj[assignFolderName({ path: `${sitecore_folder}/${newPath}` })] = multiValueArrayTree;
}
}
}
helper.writeFile(
path.join(
process.cwd(),
"sitecoreMigrationData/MapperData",
),
JSON.stringify(obj, null, 4),
"configuration",
(err) => {
if (err) throw err;
}
);
helper.writeFile(
path.join(
process.cwd(),
"sitecoreMigrationData/MapperData",
),
JSON.stringify(treeObj, null, 4),
"configurationTree",
(err) => {
if (err) throw err;
}
);
}



module.exports = ExtractConfiguration;
Loading