@contentstack/cli-cm-import 1.2.0 → 1.2.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
@@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-import
37
37
  $ csdx COMMAND
38
38
  running command...
39
39
  $ csdx (-v|--version|version)
40
- @contentstack/cli-cm-import/1.2.0 darwin-arm64 node-v18.11.0
40
+ @contentstack/cli-cm-import/1.2.1 darwin-arm64 node-v18.11.0
41
41
  $ csdx --help [COMMAND]
42
42
  USAGE
43
43
  $ csdx COMMAND
@@ -1 +1 @@
1
- {"version":"1.2.0","commands":{"cm:stacks:import":{"id":"cm:stacks:import","description":"Import script for importing the content into the new stack\n...\nOnce you export content from the source stack, import it to your destination stack by using the cm:stacks:import command.\n","usage":"cm:stacks:import [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--backup-dir <value>] [--branch <value>] [--import-webhook-status disable|current]","pluginName":"@contentstack/cli-cm-import","pluginType":"core","aliases":["cm:import"],"examples":["csdx cm:stacks:import --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>","csdx cm:stacks:import --config <path/of/config/dir>","csdx cm:stacks:import --module <single module name>","csdx cm:stacks:import --module <single module name> --backup-dir <backup dir>","csdx cm:stacks:import --alias <management_token_alias>","csdx cm:stacks:import --alias <management_token_alias> --data-dir <path/of/export/destination/dir>","csdx cm:stacks:import --alias <management_token_alias> --config <path/of/config/file>","csdx cm:stacks:import --branch <branch name> --yes"],"flags":{"config":{"name":"config","type":"option","char":"c","description":"[optional] path of config file"},"stack-uid":{"name":"stack-uid","type":"option","char":"s","description":"API key of the target stack","hidden":true},"stack-api-key":{"name":"stack-api-key","type":"option","char":"k","description":"API key of the target stack"},"data":{"name":"data","type":"option","description":"path and location where data is stored","hidden":true},"data-dir":{"name":"data-dir","type":"option","char":"d","description":"path and location where data is stored"},"alias":{"name":"alias","type":"option","char":"a","description":"alias of the management token"},"management-token-alias":{"name":"management-token-alias","type":"option","description":"alias of the management token","hidden":true},"auth-token":{"name":"auth-token","type":"boolean","char":"A","description":"to use auth token","hidden":true,"allowNo":false},"module":{"name":"module","type":"option","char":"m","description":"[optional] specific module name"},"backup-dir":{"name":"backup-dir","type":"option","char":"b","description":"[optional] backup directory name when using specific module"},"branch":{"name":"branch","type":"option","char":"B","description":"[optional] branch name"},"import-webhook-status":{"name":"import-webhook-status","type":"option","description":"Webhook state","required":false,"options":["disable","current"],"default":"disable"},"yes":{"name":"yes","type":"boolean","char":"y","description":"[optional] Override marketplace prompts","required":false,"allowNo":false}},"args":[]}}}
1
+ {"version":"1.2.1","commands":{"cm:stacks:import":{"id":"cm:stacks:import","description":"Import script for importing the content into the new stack\n...\nOnce you export content from the source stack, import it to your destination stack by using the cm:stacks:import command.\n","usage":"cm:stacks:import [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--backup-dir <value>] [--branch <value>] [--import-webhook-status disable|current]","pluginName":"@contentstack/cli-cm-import","pluginType":"core","aliases":["cm:import"],"examples":["csdx cm:stacks:import --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>","csdx cm:stacks:import --config <path/of/config/dir>","csdx cm:stacks:import --module <single module name>","csdx cm:stacks:import --module <single module name> --backup-dir <backup dir>","csdx cm:stacks:import --alias <management_token_alias>","csdx cm:stacks:import --alias <management_token_alias> --data-dir <path/of/export/destination/dir>","csdx cm:stacks:import --alias <management_token_alias> --config <path/of/config/file>","csdx cm:stacks:import --branch <branch name> --yes"],"flags":{"config":{"name":"config","type":"option","char":"c","description":"[optional] path of config file"},"stack-uid":{"name":"stack-uid","type":"option","char":"s","description":"API key of the target stack","hidden":true},"stack-api-key":{"name":"stack-api-key","type":"option","char":"k","description":"API key of the target stack"},"data":{"name":"data","type":"option","description":"path and location where data is stored","hidden":true},"data-dir":{"name":"data-dir","type":"option","char":"d","description":"path and location where data is stored"},"alias":{"name":"alias","type":"option","char":"a","description":"alias of the management token"},"management-token-alias":{"name":"management-token-alias","type":"option","description":"alias of the management token","hidden":true},"auth-token":{"name":"auth-token","type":"boolean","char":"A","description":"to use auth token","hidden":true,"allowNo":false},"module":{"name":"module","type":"option","char":"m","description":"[optional] specific module name"},"backup-dir":{"name":"backup-dir","type":"option","char":"b","description":"[optional] backup directory name when using specific module"},"branch":{"name":"branch","type":"option","char":"B","description":"[optional] branch name"},"import-webhook-status":{"name":"import-webhook-status","type":"option","description":"Webhook state","required":false,"options":["disable","current"],"default":"disable"},"yes":{"name":"yes","type":"boolean","char":"y","description":"[optional] Override marketplace prompts","required":false,"allowNo":false}},"args":[]}}}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-import",
3
3
  "description": "Contentstack CLI plugin to import content into stack",
4
- "version": "1.2.0",
4
+ "version": "1.2.1",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
@@ -106,7 +106,7 @@ class ContentTypesImport {
106
106
  // write field rules
107
107
  if (this.fieldRules.length > 0) {
108
108
  try {
109
- await fileHelper.writeFile(path.join(this.contentTypesFolderPath, 'field_rules_uid.json', this.fieldRules));
109
+ await fileHelper.writeFile(path.join(this.contentTypesFolderPath, 'field_rules_uid.json'), this.fieldRules);
110
110
  } catch (error) {
111
111
  addlogs(this.importConfig, `Failed to write field rules ${formatError(error)}`, 'success');
112
112
  }
@@ -156,24 +156,28 @@ class ContentTypesImport {
156
156
 
157
157
  async updateGlobalFields({ uid }) {
158
158
  const globalField = find(this.globalFields, { uid });
159
- supress(globalField.schema, this.importConfig.preserveStackVersion, this.installedExtensions);
160
- let globalFieldObj = this.stackAPIClient.globalField(globalField);
161
- Object.assign(globalFieldObj, cloneDeep(globalField));
162
- try {
163
- const globalFieldResponse = await globalFieldObj.update();
164
- const existingGlobalField = findIndex(this.existingGlobalFields, (existingGlobalFieldUId) => {
165
- return globalFieldResponse.uid === existingGlobalFieldUId;
166
- });
167
-
168
- // Improve write the updated global fields once all updates are completed
169
- this.existingGlobalFields.splice(existingGlobalField, 1, globalField);
170
- await fileHelper.writeFile(this.globalFieldMapperFolderPath, this.existingGlobalFields).catch((error) => {
171
- addlogs(this.importConfig, `failed to write updated the global field ${uid} ${formatError(error)}`);
172
- });
173
- addlogs(this.importConfig, `Updated the global field ${uid} with content type references `);
174
- return true;
175
- } catch (error) {
176
- addlogs(this.importConfig, `failed to update the global field ${uid} ${formatError(error)}`);
159
+ if (globalField) {
160
+ supress(globalField.schema, this.importConfig.preserveStackVersion, this.installedExtensions);
161
+ let globalFieldObj = this.stackAPIClient.globalField(globalField);
162
+ Object.assign(globalFieldObj, cloneDeep(globalField));
163
+ try {
164
+ const globalFieldResponse = await globalFieldObj.update();
165
+ const existingGlobalField = findIndex(this.existingGlobalFields, (existingGlobalFieldUId) => {
166
+ return globalFieldResponse.uid === existingGlobalFieldUId;
167
+ });
168
+
169
+ // Improve write the updated global fields once all updates are completed
170
+ this.existingGlobalFields.splice(existingGlobalField, 1, globalField);
171
+ await fileHelper.writeFile(this.globalFieldMapperFolderPath, this.existingGlobalFields).catch((error) => {
172
+ addlogs(this.importConfig, `failed to write updated the global field ${uid} ${formatError(error)}`);
173
+ });
174
+ addlogs(this.importConfig, `Updated the global field ${uid} with content type references `);
175
+ return true;
176
+ } catch (error) {
177
+ addlogs(this.importConfig, `failed to update the global field ${uid} ${formatError(error)}`);
178
+ }
179
+ } else {
180
+ addlogs(this.importConfig, `Global field ${uid} does not exist, and hence failed to update.`);
177
181
  }
178
182
  }
179
183
 
@@ -109,7 +109,7 @@ module.exports = class ImportCustomRoles {
109
109
  addlogs(self.config, chalk.red(`custom-role: ${customRole.name} failed`), 'error');
110
110
  }
111
111
 
112
- addlogs(self.self.config, formatError(error), 'error');
112
+ addlogs(self.config, formatError(error), 'error');
113
113
  }
114
114
  }
115
115
  addlogs(self.config, chalk.green('Custom-roles have been imported successfully!'), 'success');