Skip to content

Commit 507d5f5

Browse files
Merge pull request #2065 from contentstack/development
DX | 18-08-2025 | Staging
2 parents cf5af13 + 2d39114 commit 507d5f5

File tree

7 files changed

+346
-336
lines changed

7 files changed

+346
-336
lines changed

.talismanrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fileignoreconfig:
22
- filename: package-lock.json
3-
checksum: c73d080bfbbf03bc2597891f956367bfd71f5f2f8d03525175426015265edc91
3+
checksum: 07a3376fa918a903c224cc37372571ca77a6675b596fe6c54c2f38624aafbbde
44
- filename: pnpm-lock.yaml
55
checksum: 0ca85066946c49994a4353c9f64b8f380d5d2050194e3e57ad7ccd7faa030d36
66
- filename: packages/contentstack-import-setup/test/unit/backup-handler.test.ts

package-lock.json

Lines changed: 314 additions & 309 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-import/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@contentstack/cli-cm-import",
33
"description": "Contentstack CLI plugin to import content into stack",
4-
"version": "1.26.1",
4+
"version": "1.26.2",
55
"author": "Contentstack",
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"dependencies": {

packages/contentstack-import/src/commands/cm/stacks/import.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,10 @@ export default class ImportCommand extends Command {
144144
// initialize the importer
145145
// start import
146146
let backupDir: string;
147+
let importConfig: ImportConfig;
147148
try {
148149
const { flags } = await this.parse(ImportCommand);
149-
let importConfig: ImportConfig = await setupImportConfig(flags);
150+
importConfig = await setupImportConfig(flags);
150151
// Prepare the context object
151152
const context = this.createImportContext(importConfig.apiKey, importConfig.authenticationMethod);
152153
importConfig.context = { ...context };
@@ -180,11 +181,9 @@ export default class ImportCommand extends Command {
180181
}
181182
}
182183

183-
// Set backupDir early so it's available in error handling
184-
backupDir = importConfig.backupDir;
185-
186184
const moduleImporter = new ModuleImporter(managementAPIClient, importConfig);
187185
const result = await moduleImporter.start();
186+
backupDir = importConfig.backupDir;
188187

189188
if (!result?.noSuccessMsg) {
190189
const successMessage = importConfig.stackName
@@ -198,8 +197,8 @@ export default class ImportCommand extends Command {
198197
} catch (error) {
199198
handleAndLogError(error);
200199
log.info(`The log has been stored at '${getLogPath()}'`);
201-
if (backupDir) {
202-
log.info(`The backup content has been stored at '${backupDir}'`);
200+
if (importConfig?.backupDir) {
201+
log.info(`The backup content has been stored at '${importConfig?.backupDir}'`);
203202
} else {
204203
log.info('No backup directory was created due to early termination');
205204
}
Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { join } from 'node:path';
2-
import { log, formatError, fileHelper, fsUtil } from '../../utils';
2+
import { fileHelper, fsUtil } from '../../utils';
33
import BaseClass from './base-class';
44
import { ModuleClassParams } from '../../types';
5+
import { log, handleAndLogError } from '@contentstack/cli-utilities';
56

6-
export default class ImportStack extends BaseClass { // classname
7+
export default class ImportStack extends BaseClass {
8+
// classname
79
private stackSettingsPath: string;
810
private envUidMapperPath: string;
911
private stackSettings: Record<string, any> | null = null;
@@ -16,24 +18,28 @@ export default class ImportStack extends BaseClass { // classname
1618
}
1719

1820
async start(): Promise<void> {
19-
log(this.importConfig, 'Migrating stack...', 'info');
20-
21-
if (fileHelper.fileExistsSync(this.envUidMapperPath)) {
22-
this.envUidMapper = fsUtil.readFile(this.envUidMapperPath, true) as Record<string, string>;
23-
} else {
24-
throw new Error('Please run the environments migration first.');
25-
}
26-
2721
if (this.importConfig.management_token) {
28-
log(this.importConfig, 'Skipping stack settings import: Operation is not supported when using a management token.', 'info');
29-
log(this.importConfig, 'Successfully imported stack', 'success');
22+
log.info(
23+
'Skipping stack settings import: Operation is not supported when using a management token.',
24+
this.importConfig.context,
25+
);
3026
return;
3127
}
3228

3329
if (fileHelper.fileExistsSync(this.stackSettingsPath)) {
3430
this.stackSettings = fsUtil.readFile(this.stackSettingsPath, true) as Record<string, any>;
3531
} else {
36-
log(this.importConfig, 'No stack Found!', 'info');
32+
log.info('No stack setting found!', this.importConfig.context);
33+
return;
34+
}
35+
36+
if (fileHelper.fileExistsSync(this.envUidMapperPath)) {
37+
this.envUidMapper = fsUtil.readFile(this.envUidMapperPath, true) as Record<string, string>;
38+
} else {
39+
log.warn(
40+
'Skipping stack settings import. Please run the environments migration first.',
41+
this.importConfig.context,
42+
);
3743
return;
3844
}
3945

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

4652
try {
4753
await this.stack.addSettings(this.stackSettings);
48-
log(this.importConfig, 'Successfully imported stack', 'success');
54+
log.success('Successfully imported stack', this.importConfig.context);
4955
} catch (error) {
50-
log(this.importConfig, `Stack failed to be imported! ${formatError(error)}`, 'error');
56+
handleAndLogError(error, { ...this.importConfig.context });
5157
}
5258
}
53-
}
59+
}

packages/contentstack/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@contentstack/cli",
33
"description": "Command-line tool (CLI) to interact with Contentstack",
4-
"version": "1.44.2",
4+
"version": "1.44.3",
55
"author": "Contentstack",
66
"bin": {
77
"csdx": "./bin/run.js"
@@ -30,7 +30,7 @@
3030
"@contentstack/cli-cm-clone": "~1.15.0",
3131
"@contentstack/cli-cm-export": "~1.18.1",
3232
"@contentstack/cli-cm-export-to-csv": "~1.9.0",
33-
"@contentstack/cli-cm-import": "~1.26.1",
33+
"@contentstack/cli-cm-import": "~1.26.2",
3434
"@contentstack/cli-cm-import-setup": "1.4.1",
3535
"@contentstack/cli-cm-migrate-rte": "~1.6.0",
3636
"@contentstack/cli-cm-seed": "~1.12.0",

pnpm-lock.yaml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)