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
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fileignoreconfig:
- filename: package-lock.json
checksum: c73d080bfbbf03bc2597891f956367bfd71f5f2f8d03525175426015265edc91
checksum: 07a3376fa918a903c224cc37372571ca77a6675b596fe6c54c2f38624aafbbde
- filename: pnpm-lock.yaml
checksum: 0ca85066946c49994a4353c9f64b8f380d5d2050194e3e57ad7ccd7faa030d36
- filename: packages/contentstack-import-setup/test/unit/backup-handler.test.ts
Expand Down
623 changes: 314 additions & 309 deletions package-lock.json

Large diffs are not rendered by default.

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.26.1",
"version": "1.26.2",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
11 changes: 5 additions & 6 deletions packages/contentstack-import/src/commands/cm/stacks/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ export default class ImportCommand extends Command {
// initialize the importer
// start import
let backupDir: string;
let importConfig: ImportConfig;
try {
const { flags } = await this.parse(ImportCommand);
let importConfig: ImportConfig = await setupImportConfig(flags);
importConfig = await setupImportConfig(flags);
// Prepare the context object
const context = this.createImportContext(importConfig.apiKey, importConfig.authenticationMethod);
importConfig.context = { ...context };
Expand Down Expand Up @@ -180,11 +181,9 @@ export default class ImportCommand extends Command {
}
}

// Set backupDir early so it's available in error handling
backupDir = importConfig.backupDir;

const moduleImporter = new ModuleImporter(managementAPIClient, importConfig);
const result = await moduleImporter.start();
backupDir = importConfig.backupDir;

if (!result?.noSuccessMsg) {
const successMessage = importConfig.stackName
Expand All @@ -198,8 +197,8 @@ export default class ImportCommand extends Command {
} catch (error) {
handleAndLogError(error);
log.info(`The log has been stored at '${getLogPath()}'`);
if (backupDir) {
log.info(`The backup content has been stored at '${backupDir}'`);
if (importConfig?.backupDir) {
log.info(`The backup content has been stored at '${importConfig?.backupDir}'`);
} else {
log.info('No backup directory was created due to early termination');
}
Expand Down
38 changes: 22 additions & 16 deletions packages/contentstack-import/src/import/modules/stack.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { join } from 'node:path';
import { log, formatError, fileHelper, fsUtil } from '../../utils';
import { fileHelper, fsUtil } from '../../utils';
import BaseClass from './base-class';
import { ModuleClassParams } from '../../types';
import { log, handleAndLogError } from '@contentstack/cli-utilities';

export default class ImportStack extends BaseClass { // classname
export default class ImportStack extends BaseClass {
// classname
private stackSettingsPath: string;
private envUidMapperPath: string;
private stackSettings: Record<string, any> | null = null;
Expand All @@ -16,24 +18,28 @@ export default class ImportStack extends BaseClass { // classname
}

async start(): Promise<void> {
log(this.importConfig, 'Migrating stack...', 'info');

if (fileHelper.fileExistsSync(this.envUidMapperPath)) {
this.envUidMapper = fsUtil.readFile(this.envUidMapperPath, true) as Record<string, string>;
} else {
throw new Error('Please run the environments migration first.');
}

if (this.importConfig.management_token) {
log(this.importConfig, 'Skipping stack settings import: Operation is not supported when using a management token.', 'info');
log(this.importConfig, 'Successfully imported stack', 'success');
log.info(
'Skipping stack settings import: Operation is not supported when using a management token.',
this.importConfig.context,
);
return;
}

if (fileHelper.fileExistsSync(this.stackSettingsPath)) {
this.stackSettings = fsUtil.readFile(this.stackSettingsPath, true) as Record<string, any>;
} else {
log(this.importConfig, 'No stack Found!', 'info');
log.info('No stack setting found!', this.importConfig.context);
return;
}

if (fileHelper.fileExistsSync(this.envUidMapperPath)) {
this.envUidMapper = fsUtil.readFile(this.envUidMapperPath, true) as Record<string, string>;
} else {
log.warn(
'Skipping stack settings import. Please run the environments migration first.',
this.importConfig.context,
);
return;
}

Expand All @@ -45,9 +51,9 @@ export default class ImportStack extends BaseClass { // classname

try {
await this.stack.addSettings(this.stackSettings);
log(this.importConfig, 'Successfully imported stack', 'success');
log.success('Successfully imported stack', this.importConfig.context);
} catch (error) {
log(this.importConfig, `Stack failed to be imported! ${formatError(error)}`, 'error');
handleAndLogError(error, { ...this.importConfig.context });
}
}
}
}
4 changes: 2 additions & 2 deletions packages/contentstack/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli",
"description": "Command-line tool (CLI) to interact with Contentstack",
"version": "1.44.2",
"version": "1.44.3",
"author": "Contentstack",
"bin": {
"csdx": "./bin/run.js"
Expand Down Expand Up @@ -30,7 +30,7 @@
"@contentstack/cli-cm-clone": "~1.15.0",
"@contentstack/cli-cm-export": "~1.18.1",
"@contentstack/cli-cm-export-to-csv": "~1.9.0",
"@contentstack/cli-cm-import": "~1.26.1",
"@contentstack/cli-cm-import": "~1.26.2",
"@contentstack/cli-cm-import-setup": "1.4.1",
"@contentstack/cli-cm-migrate-rte": "~1.6.0",
"@contentstack/cli-cm-seed": "~1.12.0",
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

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

Loading