Skip to content

Commit af43060

Browse files
Merge pull request #1979 from contentstack/fix/dx-3097-import-stack-settings
dx | 3097 import stack settings
2 parents 6695de3 + 15b64da commit af43060

File tree

9 files changed

+746
-745
lines changed

9 files changed

+746
-745
lines changed

.talismanrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
fileignoreconfig:
22
- filename: pnpm-lock.yaml
3-
checksum: 97a6a5b7d3ddb046ccd03d135c0421e674a4dbbc3f9466380481c5e3dac1ebd3
3+
checksum: 550a609e4555f12348d39594897ebcd9f7173ea11ac34ad8c7ac4a714325f203
44
- filename: packages/contentstack-import/test/integration/auth-token-modules/environments.test.js
55
checksum: bc6f06b75d082aaf99e2f2f4b932b143765e2f14086967fb8973fe1b2ca6c03e
66
- filename: packages/contentstack-import/test/integration/environments.test.js
77
checksum: e71f033dad8944ffeafdf22d0514bda1d20c43e8fea0d62c96e774f3414beb31
88
- filename: package-lock.json
9-
checksum: 8699ac1d7b2d3af92b6a95cbb9898ad5bb4e7eb17527824cd6ecdd14e6cfde5a
9+
checksum: a9cc009416b91e63c630ff934fbbf65f13ee3be24cc12be1a33ec234fd64f5c0
1010
- filename: packages/contentstack-auth/test/unit/tokens-validation.test.ts
1111
checksum: 676052e30d31a771ce68302d89b050d176bbef50f3abc7e9cdd4384f0e274e10
1212
- filename: packages/contentstack-import/test/integration/auth-token.test.js

package-lock.json

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

packages/contentstack-clone/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dependencies": {
88
"@colors/colors": "^1.6.0",
99
"@contentstack/cli-cm-export": "~1.17.0",
10-
"@contentstack/cli-cm-import": "~1.24.0",
10+
"@contentstack/cli-cm-import": "~1.25.0",
1111
"@contentstack/cli-command": "~1.5.0",
1212
"@contentstack/cli-utilities": "~1.12.0",
1313
"@oclif/core": "^4.3.0",

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.24.0",
4+
"version": "1.25.0",
55
"author": "Contentstack",
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"dependencies": {

packages/contentstack-import/src/config/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const config: DefaultConfig = {
3030
types: [
3131
'locales',
3232
'environments',
33+
'stack',
3334
'assets',
3435
'taxonomies',
3536
'extensions',
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { join } from 'node:path';
2+
import { log, formatError, fileHelper, fsUtil } from '../../utils';
3+
import BaseClass from './base-class';
4+
import { ModuleClassParams } from '../../types';
5+
6+
export default class ImportStack extends BaseClass { // classname
7+
private stackSettingsPath: string;
8+
private envUidMapperPath: string;
9+
private stackSettings: Record<string, any> | null = null;
10+
private envUidMapper: Record<string, string> = {};
11+
12+
constructor({ importConfig, stackAPIClient }: ModuleClassParams) {
13+
super({ importConfig, stackAPIClient });
14+
this.stackSettingsPath = join(this.importConfig.backupDir, 'stack', 'settings.json');
15+
this.envUidMapperPath = join(this.importConfig.backupDir, 'mapper', 'environments', 'uid-mapping.json');
16+
}
17+
18+
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+
27+
if (fileHelper.fileExistsSync(this.stackSettingsPath)) {
28+
this.stackSettings = fsUtil.readFile(this.stackSettingsPath, true) as Record<string, any>;
29+
} else {
30+
log(this.importConfig, 'No stack Found!', 'info');
31+
return;
32+
}
33+
34+
if (this.stackSettings.live_preview && this.stackSettings.live_preview['default-env']) {
35+
const oldEnvUid = this.stackSettings.live_preview['default-env'];
36+
const mappedEnvUid = this.envUidMapper[oldEnvUid];
37+
this.stackSettings.live_preview['default-env'] = mappedEnvUid;
38+
}
39+
40+
try {
41+
await this.stack.addSettings(this.stackSettings);
42+
log(this.importConfig, 'Successfully imported stack', 'success');
43+
} catch (error) {
44+
log(this.importConfig, `Stack failed to be imported! ${formatError(error)}`, 'error');
45+
}
46+
}
47+
}

packages/contentstack-seed/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"author": "Contentstack",
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"dependencies": {
8-
"@contentstack/cli-cm-import": "~1.24.0",
8+
"@contentstack/cli-cm-import": "~1.25.0",
99
"@contentstack/cli-command": "~1.5.0",
1010
"@contentstack/cli-utilities": "~1.12.0",
1111
"@contentstack/management": "~1.21.4",

packages/contentstack/package.json

Lines changed: 3 additions & 3 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.42.0",
4+
"version": "1.43.0",
55
"author": "Contentstack",
66
"bin": {
77
"csdx": "./bin/run.js"
@@ -30,7 +30,7 @@
3030
"@contentstack/cli-cm-clone": "~1.14.2",
3131
"@contentstack/cli-cm-export": "~1.17.0",
3232
"@contentstack/cli-cm-export-to-csv": "~1.8.2",
33-
"@contentstack/cli-cm-import": "~1.24.0",
33+
"@contentstack/cli-cm-import": "~1.25.0",
3434
"@contentstack/cli-cm-import-setup": "1.3.0",
3535
"@contentstack/cli-cm-migrate-rte": "~1.5.2",
3636
"@contentstack/cli-cm-seed": "~1.11.2",
@@ -40,7 +40,7 @@
4040
"@contentstack/cli-migration": "~1.7.3",
4141
"@contentstack/cli-utilities": "~1.12.0",
4242
"@contentstack/cli-variants": "~1.2.2",
43-
"@contentstack/management": "~1.21.4",
43+
"@contentstack/management": "~1.22.0",
4444
"@oclif/core": "^4.3.0",
4545
"@oclif/plugin-help": "^6.2.28",
4646
"@oclif/plugin-not-found": "^3.2.53",

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)