@contentstack/cli-cm-import 1.24.0 → 1.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
47
47
  $ csdx COMMAND
48
48
  running command...
49
49
  $ csdx (--version)
50
- @contentstack/cli-cm-import/1.24.0 linux-x64 node-v22.16.0
50
+ @contentstack/cli-cm-import/1.25.1 linux-x64 node-v22.17.0
51
51
  $ csdx --help [COMMAND]
52
52
  USAGE
53
53
  $ csdx COMMAND
@@ -30,6 +30,7 @@ const config = {
30
30
  types: [
31
31
  'locales',
32
32
  'environments',
33
+ 'stack',
33
34
  'assets',
34
35
  'taxonomies',
35
36
  'extensions',
@@ -9,6 +9,7 @@ const entries_1 = tslib_1.__importDefault(require("lodash/entries"));
9
9
  const isEqual_1 = tslib_1.__importDefault(require("lodash/isEqual"));
10
10
  const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
11
11
  const utils_1 = require("../../utils");
12
+ const cloneDeep_1 = tslib_1.__importDefault(require("lodash/cloneDeep"));
12
13
  class BaseClass {
13
14
  constructor({ importConfig, stackAPIClient }) {
14
15
  this.client = stackAPIClient;
@@ -197,9 +198,16 @@ class BaseClass {
197
198
  return this.stack
198
199
  .globalField(globalFieldUid, { api_version: '3.2' })
199
200
  .fetch()
200
- .then(async (response) => {
201
- response.parent = (apiData === null || apiData === void 0 ? void 0 : apiData.uid) ? apiData : apiData.global_field;
202
- await response.update().then(onSuccess).catch(onReject);
201
+ .then(async (gf) => {
202
+ const _a = (0, cloneDeep_1.default)(apiData), { uid } = _a, updatePayload = tslib_1.__rest(_a, ["uid"]);
203
+ Object.assign(gf, updatePayload);
204
+ try {
205
+ const response = await gf.update();
206
+ return onSuccess(response);
207
+ }
208
+ catch (error) {
209
+ return onReject(error);
210
+ }
203
211
  })
204
212
  .catch(onReject);
205
213
  case 'create-environments':
@@ -74,6 +74,11 @@ class ContentTypesImport extends base_class_1.default {
74
74
  if (this.isExtensionsUpdate) {
75
75
  (0, utils_1.log)(this.importConfig, 'Successfully updated the extensions.', 'success');
76
76
  }
77
+ this.pendingGFs = utils_1.fsUtil.readFile(this.gFsPendingPath);
78
+ if (!this.pendingGFs || (0, lodash_1.isEmpty)(this.pendingGFs)) {
79
+ (0, utils_1.log)(this.importConfig, 'No pending global fields found to update', 'info');
80
+ return;
81
+ }
77
82
  await this.updatePendingGFs().catch((error) => {
78
83
  (0, utils_1.log)(this.importConfig, `Error while updating pending global field ${(0, utils_1.formatError)(error)}`, 'error');
79
84
  });
@@ -165,8 +170,9 @@ class ContentTypesImport extends base_class_1.default {
165
170
  }
166
171
  async updatePendingGFs() {
167
172
  this.pendingGFs = utils_1.fsUtil.readFile(this.gFsPendingPath);
173
+ (0, utils_1.log)(this.importConfig, `Found ${this.pendingGFs.length} pending global fields to update`, 'info');
168
174
  this.gFs = utils_1.fsUtil.readFile(path.resolve(this.gFsFolderPath, this.gFsConfig.fileName));
169
- const onSuccess = ({ response: globalField, apiData: { uid } = undefined }) => {
175
+ const onSuccess = ({ response, apiData: { uid } = undefined }) => {
170
176
  (0, utils_1.log)(this.importConfig, `Updated the global field ${uid} with content type references`, 'info');
171
177
  };
172
178
  const onReject = ({ error, apiData: { uid } = undefined }) => {
@@ -46,10 +46,10 @@ class ImportGlobalFields extends base_class_1.default {
46
46
  }
47
47
  this.installedExtensions = ((await utils_1.fsUtil.readFile(this.marketplaceAppMapperPath)) || { extension_uid: {} }).extension_uid;
48
48
  await this.seedGFs();
49
- if ((_a = this.seedGFs) === null || _a === void 0 ? void 0 : _a.length)
50
- utils_1.fsUtil.writeFile(this.gFsPendingPath, this.pendingGFs);
51
49
  (0, utils_1.log)(this.importConfig, 'Created Global Fields', 'success');
52
50
  await this.updateGFs();
51
+ if ((_a = this.pendingGFs) === null || _a === void 0 ? void 0 : _a.length)
52
+ utils_1.fsUtil.writeFile(this.gFsPendingPath, this.pendingGFs);
53
53
  (0, utils_1.log)(this.importConfig, 'Updated Global Fields', 'success');
54
54
  if (this.importConfig.replaceExisting && this.existingGFs.length > 0) {
55
55
  await this.replaceGFs().catch((error) => {
@@ -133,6 +133,8 @@ class ImportGlobalFields extends base_class_1.default {
133
133
  await (0, utils_1.removeReferenceFields)(globalField.schema, flag, this.stack);
134
134
  if (flag.supressed) {
135
135
  this.pendingGFs.push(globalField.uid);
136
+ (0, utils_1.log)(this.importConfig, `Global field '${globalField.uid}' will be updated later`, 'info');
137
+ return resolve(true);
136
138
  }
137
139
  return this.stack
138
140
  .globalField(globalField.uid, { api_version: '3.2' })
@@ -0,0 +1,10 @@
1
+ import BaseClass from './base-class';
2
+ import { ModuleClassParams } from '../../types';
3
+ export default class ImportStack extends BaseClass {
4
+ private stackSettingsPath;
5
+ private envUidMapperPath;
6
+ private stackSettings;
7
+ private envUidMapper;
8
+ constructor({ importConfig, stackAPIClient }: ModuleClassParams);
9
+ start(): Promise<void>;
10
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const node_path_1 = require("node:path");
5
+ const utils_1 = require("../../utils");
6
+ const base_class_1 = tslib_1.__importDefault(require("./base-class"));
7
+ class ImportStack extends base_class_1.default {
8
+ constructor({ importConfig, stackAPIClient }) {
9
+ super({ importConfig, stackAPIClient });
10
+ this.stackSettings = null;
11
+ this.envUidMapper = {};
12
+ this.stackSettingsPath = (0, node_path_1.join)(this.importConfig.backupDir, 'stack', 'settings.json');
13
+ this.envUidMapperPath = (0, node_path_1.join)(this.importConfig.backupDir, 'mapper', 'environments', 'uid-mapping.json');
14
+ }
15
+ async start() {
16
+ var _a, _b;
17
+ (0, utils_1.log)(this.importConfig, 'Migrating stack...', 'info');
18
+ if (utils_1.fileHelper.fileExistsSync(this.envUidMapperPath)) {
19
+ this.envUidMapper = utils_1.fsUtil.readFile(this.envUidMapperPath, true);
20
+ }
21
+ else {
22
+ throw new Error('Please run the environments migration first.');
23
+ }
24
+ if (utils_1.fileHelper.fileExistsSync(this.stackSettingsPath)) {
25
+ this.stackSettings = utils_1.fsUtil.readFile(this.stackSettingsPath, true);
26
+ }
27
+ else {
28
+ (0, utils_1.log)(this.importConfig, 'No stack Found!', 'info');
29
+ return;
30
+ }
31
+ if (((_a = this.stackSettings) === null || _a === void 0 ? void 0 : _a.live_preview) && ((_b = this.stackSettings) === null || _b === void 0 ? void 0 : _b.live_preview['default-env'])) {
32
+ const oldEnvUid = this.stackSettings.live_preview['default-env'];
33
+ const mappedEnvUid = this.envUidMapper[oldEnvUid];
34
+ this.stackSettings.live_preview['default-env'] = mappedEnvUid;
35
+ }
36
+ try {
37
+ await this.stack.addSettings(this.stackSettings);
38
+ (0, utils_1.log)(this.importConfig, 'Successfully imported stack', 'success');
39
+ }
40
+ catch (error) {
41
+ (0, utils_1.log)(this.importConfig, `Stack failed to be imported! ${(0, utils_1.formatError)(error)}`, 'error');
42
+ }
43
+ }
44
+ }
45
+ exports.default = ImportStack;
@@ -24,6 +24,6 @@ exports.gfSchemaTemplate = {
24
24
  "multiple": false
25
25
  }
26
26
  ],
27
- "description": "Seed "
27
+ "description": ""
28
28
  }
29
29
  };
@@ -199,5 +199,5 @@
199
199
  ]
200
200
  }
201
201
  },
202
- "version": "1.24.0"
202
+ "version": "1.25.1"
203
203
  }
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-import",
3
3
  "description": "Contentstack CLI plugin to import content into stack",
4
- "version": "1.24.0",
4
+ "version": "1.25.1",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
8
8
  "@contentstack/cli-audit": "~1.13.0",
9
9
  "@contentstack/cli-command": "~1.5.0",
10
10
  "@contentstack/cli-utilities": "~1.12.0",
11
- "@contentstack/management": "~1.21.4",
11
+ "@contentstack/management": "~1.22.0",
12
12
  "@contentstack/cli-variants": "~1.2.1",
13
13
  "@oclif/core": "^4.3.0",
14
14
  "big-json": "^3.2.0",