Skip to content
Merged

Dev #305

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f4f8cb5
removed csdx utilities code
RohitKini Sep 12, 2024
817163a
Merge branch 'dev' of https://github.com/contentstack/migration-v2-no…
RohitKini Sep 16, 2024
f14ecdd
added updated code
umeshmore45 Sep 16, 2024
049724c
Merge branch 'feature/merge_two' of https://github.com/contentstack/m…
RohitKini Sep 16, 2024
1c49aa6
added uid
umeshmore45 Sep 17, 2024
61d9485
logger functionality
RohitKini Sep 18, 2024
c8206fd
Merge branch 'feature/merge_two' of https://github.com/contentstack/m…
RohitKini Sep 18, 2024
4ff1b0a
logger functionality
RohitKini Sep 18, 2024
3bf2249
logger functionality
RohitKini Sep 18, 2024
461362d
added updated code
umeshmore45 Sep 19, 2024
5c605e6
added cli code
umeshmore45 Sep 19, 2024
74d321d
added bin
umeshmore45 Sep 19, 2024
a26cd52
Merge branch 'dev' of https://github.com/contentstack/migration-v2-no…
RohitKini Sep 24, 2024
c456e3e
stacks limit check
RohitKini Sep 26, 2024
175eab7
Merge pull request #296 from contentstack/feature/rohit-updates
RohitKini Sep 26, 2024
1e11f79
Merge pull request #297 from contentstack/feature/merge_two
umeshmore45 Sep 30, 2024
e30acee
added create test route
RohitKini Sep 30, 2024
57ca484
Merge pull request #299 from contentstack/feature/rohit-updates
RohitKini Sep 30, 2024
10819d2
[CMG-311], [CMG-326]
sayalijoshi27 Oct 1, 2024
a0ae36f
Done changes in Contentmapper removed existing ct and global field st…
sayalijoshi27 Oct 1, 2024
ff43e2e
added test
umeshmore45 Oct 2, 2024
ff2deea
[CMG-82] - Create Project modal validation behaviour separated for na…
sayalijoshi27 Oct 3, 2024
ba89476
code added
umeshmore45 Oct 3, 2024
47bedd7
Merge pull request #300 from contentstack/feature/test-mig2
umeshmore45 Oct 3, 2024
418bb4d
Test Migration API integrated
sayalijoshi27 Oct 3, 2024
cd0581c
Merge pull request #301 from contentstack/bugfix/content-mapper
RohitKini Oct 4, 2024
cf19a63
Merge branch 'dev' of https://github.com/contentstack/migration-v2-no…
sayalijoshi27 Oct 4, 2024
e5bd5e9
Test Migration API integrated
sayalijoshi27 Oct 3, 2024
bdcb680
rebased
umeshmore45 Oct 4, 2024
0e59657
Merge pull request #302 from contentstack/rebase
sayalijoshi27 Oct 4, 2024
8d34f28
Test migration button disabld and loader aaded
sayalijoshi27 Oct 4, 2024
1fc3d70
Merge pull request #303 from contentstack/feature/test-migration
RohitKini Oct 4, 2024
b5cf124
addded test ture boolean code
umeshmore45 Oct 4, 2024
561e04f
Merge pull request #304 from contentstack/feature/lowdb-fix
umeshmore45 Oct 4, 2024
2899517
Test Migration button disable changes
sayalijoshi27 Oct 4, 2024
8956f37
Merge pull request #306 from contentstack/feature/test-migration
sayalijoshi27 Oct 4, 2024
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
Prev Previous commit
Next Next commit
addded test ture boolean code
  • Loading branch information
umeshmore45 committed Oct 4, 2024
commit b5cf1240cad5c3afc3aea7d14c3c64a0be024061
7 changes: 4 additions & 3 deletions api/src/models/project-lowdb.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from 'path';
import { JSONFile } from "lowdb/node";
import LowWithLodash from "../utils/lowdb-lodash.utils.js";

Expand Down Expand Up @@ -27,11 +28,11 @@ interface LegacyCMS {
is_localPath: boolean;
}

interface StackDetails{
interface StackDetails {
uid: string;
label: string;
master_locale: string;
created_at: string;
created_at: string;
isNewStack: boolean;
}

Expand Down Expand Up @@ -84,7 +85,7 @@ const defaultData: ProjectDocument = { projects: [] };
* Represents the database instance for the project.
*/
const db = new LowWithLodash(
new JSONFile<ProjectDocument>("database/project.json"),
new JSONFile<ProjectDocument>(path.join(process.cwd(), "database/project.json")),
defaultData
);

Expand Down
49 changes: 22 additions & 27 deletions api/src/services/migration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,6 @@ const deleteTestStack = async (req: Request): Promise<LoginServiceType> => {
}
};

const cliLogger = (child: any) => {
if (child.code !== 0) {
console.info(`Error: Failed to install @contentstack/cli. Exit code: ${child.code}`);
console.info(`stderr: ${child.stderr}`);
} else {
console.info(child?.stdout);
}
};

function createDirectoryAndFile(filePath: string) {
// Get the directory from the file path
Expand All @@ -228,7 +220,7 @@ function createDirectoryAndFile(filePath: string) {
}


const runCli = async (rg: string, user_id: string, stack_uid: any) => {
const runCli = async (rg: string, user_id: string, stack_uid: any, projectId: string) => {
try {
const regionPresent = CS_REGIONS?.find((item: string) => item === rg) ?? 'NA';
await AuthenticationModel.read();
Expand All @@ -244,14 +236,25 @@ const runCli = async (rg: string, user_id: string, stack_uid: any) => {
createDirectoryAndFile(loggerPath);
await setLogFilePath(loggerPath);
shell.cd(path.join(process.cwd(), '..', 'cli', 'packages', 'contentstack'));
const pwd = shell.exec('pwd');
cliLogger(pwd);
const region = shell.exec(`node bin/run config:set:region ${regionPresent}`);
cliLogger(region);
const login = shell.exec(`node bin/run login -a ${userData?.authtoken} -e ${userData?.email}`);
cliLogger(login);
shell.exec('pwd');
shell.exec(`node bin/run config:set:region ${regionPresent}`);
shell.exec(`node bin/run login -a ${userData?.authtoken} -e ${userData?.email}`);
const exportData = shell.exec(`node bin/run cm:stacks:import -k ${stack_uid} -d ${sourcePath} --backup-dir=${backupPath} --yes`, { async: true });
cliLogger(exportData);
exportData.on('exit', (code) => {
console.info(`Process exited with code: ${code}`);
if (code === 1) {
const projectIndex = ProjectModelLowdb.chain.get("projects").findIndex({ id: projectId }).value();
if (projectIndex > -1) {
ProjectModelLowdb?.data.projects[projectIndex].test_stacks.map((item: any) => {
if (item?.stackUid === stack_uid) {
item.isMigrated = true;
}
return item;
})
ProjectModelLowdb.write();
}
}
});
} else {
console.info('user not found.')
}
Expand All @@ -264,22 +267,14 @@ const fieldMapping = async (req: Request): Promise<any> => {
const { orgId, projectId } = req?.params ?? {};
const { region, user_id } = req?.body?.token_payload ?? {};
const project = ProjectModelLowdb.chain.get("projects").find({ id: projectId }).value();
if (project?.extract_path && project?.current_test_stack_id) {
const packagePath = project?.extract_path;
const packagePath = project?.extract_path;
if (packagePath && project?.current_test_stack_id) {
const contentTypes = await fieldAttacher({ orgId, projectId, destinationStackId: project?.current_test_stack_id });
await siteCoreService?.createEntry({ packagePath, contentTypes, destinationStackId: project?.current_test_stack_id });
await siteCoreService?.createLocale(req, project?.current_test_stack_id);
await siteCoreService?.createVersionFile(project?.current_test_stack_id);
await testFolderCreator?.({ destinationStackId: project?.current_test_stack_id });
await runCli(region, user_id, project?.current_test_stack_id);
// const projectIndex = ProjectModelLowdb.chain.get("projects").findIndex({ id: projectId }).value();
// if (projectIndex > -1) {
// ProjectModelLowdb.update((data: any) => {
// const index = data.projects[projectIndex].test_stacks.findIndex((item: any) => item?.stackUid === project?.current_test_stack_id);
// console.info("🚀 ~ ProjectModelLowdb.update ~ index:", index)
// data.projects[projectIndex].current_test_stack_id = '';
// });
// }
await runCli(region, user_id, project?.current_test_stack_id, projectId);
}
}

Expand Down