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
10 changes: 8 additions & 2 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fileignoreconfig:
- filename: package-lock.json
checksum: 59d20d0ac10b0d5d4014817c8453e4aa9fe0be396f7902999373273a9d471658
checksum: b7a69ac42575d552fa99e0f7b62fa16485cdb8bb83efec3c5d46c22537e8bc37
- filename: pnpm-lock.yaml
checksum: 7cade45c0e4ff4755b6e7d0f7ce0e40fa5b62131513d9f800635ef4288fdc058
checksum: 62fc7744149464cc3a0b285544e90739d48e8e1384ac211d4799389c3c78db10
- filename: packages/contentstack-import-setup/test/unit/backup-handler.test.ts
checksum: 0582d62b88834554cf12951c8690a73ef3ddbb78b82d2804d994cf4148e1ef93
- filename: packages/contentstack-import-setup/test/config.json
Expand Down Expand Up @@ -81,4 +81,10 @@ fileignoreconfig:
checksum: 7024f22a6ed3908d7cf074bbd8e7107e2d9f43bbcc42939b28d360c89d44cc29
- filename: packages/contentstack-bulk-publish/src/util/generate-bulk-publish-url.js
checksum: 5f7c1e2fac3e7fab21e861d609c54ca7191ee09fd076dd0adc66604043bf7a43
- filename: packages/contentstack-import/src/utils/interactive.ts
checksum: b401a6166313c184712ff623ea8d95a5548fb3d8b8229c053ae44a1850b54a72
- filename: packages/contentstack-import-setup/src/utils/backup-handler.ts
checksum: 7db02c6f2627400b28fc96d505bf074d477080a45ba13943709d4845b6ca0908
- filename: packages/contentstack-import/src/utils/backup-handler.ts
checksum: 4f7a8bea92ebffbc34a0979b3a63fef327562a899b773481d67a675140cfa4bf
version: "1.0"
899 changes: 442 additions & 457 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/contentstack-bootstrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"test:report": "nyc --reporter=lcov mocha \"test/**/*.test.js\""
},
"dependencies": {
"@contentstack/cli-cm-seed": "~1.12.1",
"@contentstack/cli-cm-seed": "~1.12.2",
"@contentstack/cli-command": "~1.6.1",
"@contentstack/cli-utilities": "~1.14.0",
"@oclif/core": "^4.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-clone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $ npm install -g @contentstack/cli-cm-clone
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-clone/1.15.0 darwin-arm64 node-v22.13.1
@contentstack/cli-cm-clone/1.16.1 darwin-arm64 node-v22.13.1
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@contentstack/cli-cm-clone",
"description": "Contentstack stack clone plugin",
"version": "1.16.0",
"version": "1.16.1",
"author": "Contentstack",
"bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues",
"dependencies": {
"@colors/colors": "^1.6.0",
"@contentstack/cli-cm-export": "~1.20.1",
"@contentstack/cli-cm-import": "~1.27.0",
"@contentstack/cli-cm-import": "~1.28.0",
"@contentstack/cli-command": "~1.6.1",
"@contentstack/cli-utilities": "~1.14.0",
"@oclif/core": "^4.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import-setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import-setup
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-import-setup/1.4.0 darwin-arm64 node-v22.13.1
@contentstack/cli-cm-import-setup/1.5.0 darwin-arm64 node-v22.13.1
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import-setup/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-import-setup",
"description": "Contentstack CLI plugin to setup the mappers and configurations for the import command",
"version": "1.4.2",
"version": "1.5.0",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
16 changes: 7 additions & 9 deletions packages/contentstack-import-setup/src/utils/backup-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ export default async function backupHandler(importConfig: ImportConfig): Promise
return importConfig.useBackedupDir;
}

const sourceDir = importConfig.branchDir || importConfig.contentDir;

let backupDirPath: string;
const subDir = isSubDirectory(importConfig);
const subDir = isSubDirectory(importConfig, sourceDir);

if (subDir) {
backupDirPath = path.resolve(
sanitizePath(importConfig.contentDir),
'..',
'_backup_' + Math.floor(Math.random() * 1000),
);
backupDirPath = path.resolve(sanitizePath(sourceDir), '..', '_backup_' + Math.floor(Math.random() * 1000));
if (importConfig.createBackupDir) {
cliux.print(
`Warning!!! Provided backup directory path is a sub directory of the content directory, Cannot copy to a sub directory. Hence new backup directory created - ${backupDirPath}`,
Expand All @@ -42,7 +40,7 @@ export default async function backupHandler(importConfig: ImportConfig): Promise
if (backupDirPath) {
cliux.print('Copying content to the backup directory...');
return new Promise((resolve, reject) => {
return copy(importConfig.contentDir, backupDirPath, (error: any) => {
return copy(sourceDir, backupDirPath, (error: any) => {
if (error) {
trace(error, 'error', true);
return reject(error);
Expand All @@ -58,8 +56,8 @@ export default async function backupHandler(importConfig: ImportConfig): Promise
* @param importConfig
* @returns
*/
function isSubDirectory(importConfig: ImportConfig) {
const parent = importConfig.contentDir;
function isSubDirectory(importConfig: ImportConfig, sourceDir: string) {
const parent = sourceDir;
const child = importConfig.createBackupDir ? importConfig.createBackupDir : process.cwd();
const relative = path.relative(parent, child);

Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-import/1.27.0 darwin-arm64 node-v22.14.0
@contentstack/cli-cm-import/1.28.0 darwin-arm64 node-v22.14.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-import",
"description": "Contentstack CLI plugin to import content into stack",
"version": "1.27.0",
"version": "1.28.0",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
36 changes: 24 additions & 12 deletions packages/contentstack-import/src/import/module-importer.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { resolve } from 'path';
import { AuditFix } from '@contentstack/cli-audit';
import messages, { $t } from '@contentstack/cli-audit/lib/messages';
import { addLocale, cliux, ContentstackClient, Logger } from '@contentstack/cli-utilities';
import { addLocale, cliux, ContentstackClient, Logger, log } from '@contentstack/cli-utilities';

import startModuleImport from './modules';
import startJSModuleImport from './modules-js';
import { ImportConfig, Modules } from '../types';
import {
backupHandler,
log,
masterLocalDetails,
sanitizeStack,
initLogger,
setupBranchConfig,
executeImportPathLogic,
} from '../utils';

class ModuleImporter {
Expand All @@ -36,6 +36,8 @@ class ModuleImporter {
this.importConfig.org_uid = stackDetails.org_uid as string;
}

await this.resolveImportPath();

await setupBranchConfig(this.importConfig, this.stackAPIClient);
if (this.importConfig.branchAlias && this.importConfig.branchName) {
this.stackAPIClient = this.managementAPIClient.stack({
Expand Down Expand Up @@ -84,7 +86,7 @@ class ModuleImporter {
}

async import() {
log(this.importConfig, `Starting to import content version ${this.importConfig.contentVersion}`, 'info');
log.info(`Starting to import content version ${this.importConfig.contentVersion}`);

// checks for single module or all modules
if (this.importConfig.singleModuleImport) {
Expand All @@ -94,7 +96,7 @@ class ModuleImporter {
}

async importByModuleByName(moduleName: Modules) {
log(this.importConfig, `Starting import of ${moduleName} module`, 'info');
log.info(`Starting import of ${moduleName} module`);
// import the modules by name
// calls the module runner which inturn calls the module itself
// NOTE: Implement a mechanism to determine whether module is new or old
Expand All @@ -120,17 +122,27 @@ class ModuleImporter {
// use the algorithm to determine the parallel and sequential execution of modules
for (let moduleName of this.importConfig.modules.types) {
if (this.importConfig.globalModules.includes(moduleName) && this.importConfig['exclude-global-modules']) {
log(
this.importConfig,
`Skipping the import of the global module '${moduleName}', as it already exists in the stack.`,
'warn',
);
log.warn(`Skipping the import of the global module '${moduleName}', as it already exists in the stack.`);
continue;
}
await this.importByModuleByName(moduleName);
}
}

/**
* Resolves the import path based on directory structure and user configuration
* @returns Promise<void>
*/
private async resolveImportPath(): Promise<void> {
try {
const resolvedPath = await executeImportPathLogic(this.importConfig, this.stackAPIClient);
log.debug(`Import path resolved to: ${resolvedPath}`);
} catch (error) {
log.error(`Failed to resolve import path: ${error}`);
// Continue with original path if resolution fails
}
}

/**
* The `auditImportData` function performs an audit process on imported data, using a specified
* configuration, and returns a boolean indicating whether a fix is needed.
Expand Down Expand Up @@ -166,9 +178,9 @@ class ModuleImporter {
});
}
args.push('--modules', 'field-rules');
log(this.importConfig, 'Starting audit process', 'info');
log.info('Starting audit process');
const result = await AuditFix.run(args);
log(this.importConfig, 'Audit process completed', 'info');
log.info('Audit process completed');

if (result) {
const { hasFix, config } = result;
Expand All @@ -194,7 +206,7 @@ class ModuleImporter {

return true;
} catch (error) {
log(this.importConfig, `Audit failed with following error. ${error}`, 'error');
log.error(`Audit failed with following error. ${error}`);
}
}
}
Expand Down
33 changes: 17 additions & 16 deletions packages/contentstack-import/src/utils/backup-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@ import { ImportConfig } from '../types';

export default async function backupHandler(importConfig: ImportConfig): Promise<string> {
log.debug('Starting backup handler process');

if (importConfig.hasOwnProperty('useBackedupDir')) {
log.debug(`Using existing backup directory: ${importConfig.useBackedupDir}`);
return importConfig.useBackedupDir;
}

const sourceDir = importConfig.branchDir || importConfig.contentDir;
log.debug(
`Using source directory for backup: ${sourceDir} (branchDir: ${importConfig.branchDir}, contentDir: ${importConfig.contentDir})`,
);

let backupDirPath: string;
const subDir = isSubDirectory(importConfig);
const subDir = isSubDirectory(importConfig, sourceDir);

if (subDir) {
backupDirPath = path.resolve(
sanitizePath(importConfig.contentDir),
'..',
'_backup_' + Math.floor(Math.random() * 1000),
);
backupDirPath = path.resolve(sanitizePath(sourceDir), '..', '_backup_' + Math.floor(Math.random() * 1000));
log.debug(`Detected subdirectory configuration, creating backup at: ${backupDirPath}`);

if (importConfig.createBackupDir) {
cliux.print(
`Warning!!! Provided backup directory path is a sub directory of the content directory, Cannot copy to a sub directory. Hence new backup directory created - ${backupDirPath}`,
Expand All @@ -36,15 +37,15 @@ export default async function backupHandler(importConfig: ImportConfig): Promise
// NOTE: If the backup folder's directory is provided, create it at that location; otherwise, the default path (working directory).
backupDirPath = path.join(process.cwd(), '_backup_' + Math.floor(Math.random() * 1000));
log.debug(`Using default backup directory: ${backupDirPath}`);

if (importConfig.createBackupDir) {
log.debug(`Custom backup directory specified: ${importConfig.createBackupDir}`);

if (fileHelper.fileExistsSync(importConfig.createBackupDir)) {
log.debug(`Removing existing backup directory: ${importConfig.createBackupDir}`);
fileHelper.removeDirSync(importConfig.createBackupDir);
}

log.debug(`Creating backup directory: ${importConfig.createBackupDir}`);
fileHelper.makeDirectory(importConfig.createBackupDir);
backupDirPath = importConfig.createBackupDir;
Expand All @@ -54,9 +55,9 @@ export default async function backupHandler(importConfig: ImportConfig): Promise
if (backupDirPath) {
log.debug(`Starting content copy to backup directory: ${backupDirPath}`);
cliux.print('Copying content to the backup directory...');

return new Promise((resolve, reject) => {
return copy(importConfig.contentDir, backupDirPath, (error: any) => {
return copy(sourceDir, backupDirPath, (error: any) => {
if (error) {
trace(error, 'error', true);
return reject(error);
Expand All @@ -74,10 +75,10 @@ export default async function backupHandler(importConfig: ImportConfig): Promise
* @param importConfig
* @returns
*/
function isSubDirectory(importConfig: ImportConfig) {
function isSubDirectory(importConfig: ImportConfig, sourceDir: string) {
log.debug('Checking if backup directory is a subdirectory');
const parent = importConfig.contentDir;

const parent = sourceDir;
const child = importConfig.createBackupDir ? importConfig.createBackupDir : process.cwd();
const relative = path.relative(parent, child);

Expand Down
Loading
Loading