@contentstack/cli-cm-import 1.5.8 → 1.5.9

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.5.8 linux-x64 node-v16.20.0
50
+ @contentstack/cli-cm-import/1.5.9 linux-x64 node-v16.20.0
51
51
  $ csdx --help [COMMAND]
52
52
  USAGE
53
53
  $ csdx COMMAND
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.8",
2
+ "version": "1.5.9",
3
3
  "commands": {
4
4
  "cm:stacks:import": {
5
5
  "id": "cm:stacks:import",
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-import",
3
3
  "description": "Contentstack CLI plugin to import content into stack",
4
- "version": "1.5.8",
4
+ "version": "1.5.9",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
8
- "@contentstack/cli-command": "^1.2.8",
9
- "@contentstack/cli-utilities": "^1.4.4",
8
+ "@contentstack/cli-command": "^1.2.9",
9
+ "@contentstack/cli-utilities": "^1.4.5",
10
10
  "@oclif/config": "^1.18.3",
11
11
  "big-json": "^3.2.0",
12
12
  "bluebird": "^3.7.2",
package/src/app.js CHANGED
@@ -47,13 +47,13 @@ exports.initial = (configData) => {
47
47
  importRes.then(resolve).catch(reject);
48
48
  })
49
49
  .catch((error) => {
50
- addlogs(config, `Failed to import contents ${util.formatError(error)}`, 'error');
50
+ addlogs(config, `Failed to import contents. ${util.formatError(error)}`, 'error');
51
51
  reject(error);
52
52
  process.exit(1);
53
53
  });
54
54
  } else {
55
55
  let filename = path.basename(config.data);
56
- addlogs(config, chalk.red(filename + ' Folder does not Exist'), 'error');
56
+ addlogs(config, chalk.red(`'${filename}' Folder does not exist'`), 'error');
57
57
  }
58
58
  };
59
59
 
@@ -95,7 +95,7 @@ let singleImport = async (APIClient, stackAPIClient, moduleName, types, config)
95
95
  }
96
96
  }
97
97
  if (!(importResponse && importResponse.empty)) {
98
- addlogs(config, moduleName + ' imported successfully!', 'success');
98
+ addlogs(config, `Module '${moduleName}' imported successfully!`, 'success');
99
99
  }
100
100
  addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'success');
101
101
  return true;
@@ -103,9 +103,9 @@ let singleImport = async (APIClient, stackAPIClient, moduleName, types, config)
103
103
  addlogs(config, 'Please provide valid module name.', 'error');
104
104
  }
105
105
  } catch (error) {
106
- addlogs(config, 'Failed to migrate ' + moduleName, 'error');
106
+ addlogs(config, `Failed to migrate '${moduleName}'`, 'error');
107
107
  addlogs(config, util.formatError(error), 'error');
108
- addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'error');
108
+ addlogs(config, `The log for this is stored at '${path.join(config.oldPath, 'logs', 'import')}'`, 'error');
109
109
  }
110
110
  };
111
111
 
@@ -148,15 +148,11 @@ let allImport = async (APIClient, stackAPIClient, config, types) => {
148
148
  } catch (error) {
149
149
  addlogs(
150
150
  config,
151
- chalk.red(
152
- 'Failed to migrate stack: ' +
153
- (config.destinationStackName || config.target_stack) +
154
- '. Please check error logs for more info',
155
- ),
151
+ `Failed to migrate stack '${(config.destinationStackName || config.target_stack)}'. Please check error logs for more info`,
156
152
  'error',
157
153
  );
158
154
  addlogs(config, util.formatError(error), 'error');
159
- addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'error');
155
+ addlogs(config, `The log for this is stored at '${path.join(config.oldPath, 'logs', 'import')}'`, 'error');
160
156
  }
161
157
  };
162
158
 
@@ -193,8 +189,8 @@ const validateIfBranchExist = async (stackAPIClient, config, branch) => {
193
189
  .catch((_err) => {});
194
190
  if (data && typeof data === 'object') {
195
191
  if (data.error_message) {
196
- addlogs(config, chalk.red(data.error_message), 'error');
197
- addlogs(config, chalk.red('No branch found with the name ' + branch), 'error');
192
+ addlogs(config, data.error_message, 'error');
193
+ addlogs(config, `No branch found with the name '${branch}`, 'error');
198
194
  reject({ message: 'No branch found with the name ' + branch, error: error_message });
199
195
  } else {
200
196
  resolve(data);
@@ -203,7 +199,7 @@ const validateIfBranchExist = async (stackAPIClient, config, branch) => {
203
199
  reject({ message: 'No branch found with the name ' + branch, error: {} });
204
200
  }
205
201
  } catch (error) {
206
- addlogs(config, chalk.red('No branch found with the name ' + branch), 'error');
202
+ addlogs(config, `No branch found with the name '${branch}`, 'error');
207
203
  reject({ message: 'No branch found with the name ' + branch, error });
208
204
  }
209
205
  });
@@ -1,7 +1,7 @@
1
1
  const _ = require('lodash');
2
2
  const defaultConfig = require('../../../config/default');
3
3
  const { Command } = require('@contentstack/cli-command');
4
- const { flags, printFlagDeprecation, isAuthenticated } = require('@contentstack/cli-utilities');
4
+ const { flags, printFlagDeprecation, isAuthenticated, cliux } = require('@contentstack/cli-utilities');
5
5
  const {
6
6
  configWithMToken,
7
7
  parameterWithMToken,
@@ -51,7 +51,7 @@ class ImportCommand extends Command {
51
51
 
52
52
  result.then(resolve).catch(reject);
53
53
  } else {
54
- console.log('management Token is not present please add managment token first');
54
+ cliux.print(`error: management Token is not present please add managment token first`, {color: 'red'});
55
55
  }
56
56
  } else if (isAuthenticated()) {
57
57
  let result;
@@ -66,7 +66,7 @@ class ImportCommand extends Command {
66
66
 
67
67
  result.then(resolve).catch(reject);
68
68
  } else {
69
- console.log('Login or provide the alias for management token');
69
+ cliux.print(`error: Login or provide the alias for management token`, {color: 'red'});
70
70
  }
71
71
  });
72
72
  }
@@ -97,7 +97,7 @@ module.exports = class ImportAssets {
97
97
  // hence, upload each asset with its version
98
98
  if (self.config.versioning) {
99
99
  return self.uploadVersionedAssets(assetUid, currentAssetFolderPath).catch(function (error) {
100
- addlogs(self.config, (chalk.red('Asset upload failed \n' + error), 'error'));
100
+ addlogs(self.config, `Asset upload failed.\n ${error}`, 'error');
101
101
  });
102
102
  }
103
103
 
@@ -111,7 +111,7 @@ module.exports = class ImportAssets {
111
111
  } else {
112
112
  addlogs(
113
113
  self.config,
114
- self.assets[assetUid].parent_uid + " parent_uid was not found! Thus, setting it as 'null'",
114
+ `'${self.assets[assetUid].parent_uid}' parent_uid was not found! Thus, setting it as 'null'`,
115
115
  'error',
116
116
  );
117
117
  }
@@ -135,13 +135,13 @@ module.exports = class ImportAssets {
135
135
  // log them onto /mapper/assets/success.json
136
136
  })
137
137
  .catch(function (error) {
138
- addlogs(self.config, chalk.red('Asset upload failed \n' + error, 'error'));
138
+ addlogs(self.config, `Asset upload failed.\n ${error}`, 'error');
139
139
  return error;
140
140
  // asset failed to upload
141
141
  // log them onto /mapper/assets/fail.json
142
142
  });
143
143
  }
144
- addlogs(self.config, currentAssetFolderPath + ' does not exist!', 'error');
144
+ addlogs(self.config, `'${currentAssetFolderPath}' does not exist!`, 'error');
145
145
  },
146
146
  { concurrency: self.assetConfig.assetBatchLimit },
147
147
  ).then(function () {
@@ -195,7 +195,8 @@ module.exports = class ImportAssets {
195
195
  } else {
196
196
  addlogs(
197
197
  self.config,
198
- (lastVersion.parent_uid + " parent_uid was not found! Thus, setting it as 'null'", 'error'),
198
+ `'${lastVersion.parent_uid}' parent_uid was not found! Thus, setting it as 'null'`,
199
+ 'error'
199
200
  );
200
201
  versionedAssetMetadata.forEach(function (assetMetadata) {
201
202
  assetMetadata.parent_uid = null;
@@ -247,7 +248,7 @@ module.exports = class ImportAssets {
247
248
  .catch(function (error) {
248
249
  // failed to upload asset
249
250
  // write it on fail logs, but do not stop the process
250
- addlogs(self.config, chalk.red('Failed to upload asset\n' + error), 'error');
251
+ addlogs(self.config, `Failed to upload asset\n ${error}`, 'error');
251
252
  return resolve();
252
253
  });
253
254
  });
@@ -377,7 +378,7 @@ module.exports = class ImportAssets {
377
378
  .catch(function (err) {
378
379
  let error = JSON.parse(err.message);
379
380
  if (error.errors.authorization || error.errors.api_key) {
380
- addlogs(self.config, chalk.red('Api_key or management_token is not valid'), 'error');
381
+ addlogs(self.config, 'Api_key or management_token is not valid', 'error');
381
382
  return reject(error);
382
383
  }
383
384
 
@@ -483,7 +484,7 @@ module.exports = class ImportAssets {
483
484
  error = { errorMessage: err.message };
484
485
  }
485
486
 
486
- addlogs(self.config, chalk.red('Asset ' + assetUid + ' not published, ' + error.errorMessage), 'error');
487
+ addlogs(self.config, `Asset '${assetUid}' not published, ${error.errorMessage}`, 'error');
487
488
  return reject(err);
488
489
  }
489
490
 
@@ -106,12 +106,24 @@ class ContentTypesImport {
106
106
  try {
107
107
  await fileHelper.writeFile(path.join(this.contentTypesFolderPath, 'field_rules_uid.json'), this.fieldRules);
108
108
  } catch (error) {
109
- addlogs(this.importConfig, `Failed to write field rules ${formatError(error)}`, 'success');
109
+ addlogs(this.importConfig, `Failed to write field rules ${formatError(error)}`, 'error');
110
110
  }
111
111
  }
112
112
 
113
113
  addlogs(this.importConfig, chalk.green('Content types imported successfully'), 'success');
114
114
  } catch (error) {
115
+ let message_content_type = "";
116
+ if (error.request !== undefined && JSON.parse(error.request.data).content_type !== undefined) {
117
+ if (JSON.parse(error.request.data).content_type.uid) {
118
+ message_content_type =
119
+ ' Update the content type with content_type_uid - ' + JSON.parse(error.request.data).content_type.uid;
120
+ } else if (JSON.parse(error.request.data).content_type.title) {
121
+ message_content_type =
122
+ ' Update the content type with content_type_title - ' + JSON.parse(error.request.data).content_type.title;
123
+ }
124
+ error.errorMessage = error.errorMessage + message_content_type;
125
+ }
126
+ addlogs(this.importConfig, formatError(error.errorMessage), 'error');
115
127
  addlogs(this.importConfig, formatError(error), 'error');
116
128
  throw new Error('Failed to import content types');
117
129
  }
@@ -149,7 +161,7 @@ class ContentTypesImport {
149
161
  const contentTypeResponse = this.stackAPIClient.contentType(contentType.uid);
150
162
  Object.assign(contentTypeResponse, cloneDeep(contentType));
151
163
  await contentTypeResponse.update();
152
- addlogs(this.importConfig, contentType.uid + ' updated with references', 'success');
164
+ addlogs(this.importConfig, `'${contentType.uid}' updated with references`, 'success');
153
165
  }
154
166
 
155
167
  async updateGlobalFields(uid) {
@@ -167,15 +179,15 @@ class ContentTypesImport {
167
179
  // Improve write the updated global fields once all updates are completed
168
180
  this.existingGlobalFields.splice(existingGlobalField, 1, globalField);
169
181
  await fileHelper.writeFile(this.globalFieldMapperFolderPath, this.existingGlobalFields).catch((error) => {
170
- addlogs(this.importConfig, `failed to write updated the global field ${uid} ${formatError(error)}`);
182
+ addlogs(this.importConfig, `failed to write updated the global field '${uid}'. ${formatError(error)}`);
171
183
  });
172
- addlogs(this.importConfig, `Updated the global field ${uid} with content type references `);
184
+ addlogs(this.importConfig, `Updated the global field '${uid}' with content type references `);
173
185
  return true;
174
186
  } catch (error) {
175
- addlogs(this.importConfig, `failed to update the global field ${uid} ${formatError(error)}`);
187
+ addlogs(this.importConfig, `failed to update the global field '${uid}'. ${formatError(error)}`);
176
188
  }
177
189
  } else {
178
- addlogs(this.importConfig, `Global field ${uid} does not exist, and hence failed to update.`);
190
+ addlogs(this.importConfig, `Global field '${uid}' does not exist, and hence failed to update.`);
179
191
  }
180
192
  }
181
193
 
@@ -49,7 +49,7 @@ module.exports = class ImportCustomRoles {
49
49
  mkdirp.sync(customRolesMapperPath);
50
50
 
51
51
  if (!self.customRoles) {
52
- addlogs(self.config, chalk.white('No custom-roles found'), 'error');
52
+ addlogs(self.config, chalk.white('No custom-roles found'), 'info');
53
53
  return;
54
54
  }
55
55
  self.customRolesUids = Object.keys(self.customRoles);
@@ -71,7 +71,7 @@ module.exports = class ImportCustomRoles {
71
71
  if (uid in self.customRolesUidMapper) {
72
72
  addlogs(
73
73
  self.config,
74
- chalk.white(`The custom-role ${customRole.name} already exists. Skipping it to avoid duplicates!`),
74
+ chalk.white(`The custom-role '${customRole.name}' already exists. Skipping it to avoid duplicates!`),
75
75
  'success',
76
76
  );
77
77
  continue;
@@ -98,14 +98,13 @@ module.exports = class ImportCustomRoles {
98
98
  self.fails.push(customRole);
99
99
 
100
100
  if (((error && error.errors && error.errors.name) || '').includes('is not a unique.')) {
101
- addlogs(self.config, chalk.red(`${customRole.name} role already exists`), 'info');
101
+ addlogs(self.config, `custom-role '${customRole.name}' already exists`, 'error');
102
102
  } else {
103
103
  if (!(error && error.errors && error.errors.name)) {
104
- addlogs(self.config, chalk.red(`custom-role: ${customRole.name} already exists`), 'error');
104
+ addlogs(self.config, `custom-role '${customRole.name}' already exists`, 'error');
105
105
  } else {
106
- addlogs(self.config, chalk.red(`custom-role: ${customRole.name} failed`), 'error');
106
+ addlogs(self.config, `custom-role '${customRole.name}' failed`, 'error');
107
107
  }
108
-
109
108
  addlogs(self.config, formatError(error), 'error');
110
109
  }
111
110
  }
@@ -113,7 +112,7 @@ module.exports = class ImportCustomRoles {
113
112
  addlogs(self.config, chalk.green('Custom-roles have been imported successfully!'), 'success');
114
113
  } catch (error) {
115
114
  helper.writeFileSync(customRolesFailsPath, self.fails);
116
- addlogs(self.config, chalk.red('Custom-roles import failed'), 'error');
115
+ addlogs(self.config, 'Custom-roles import failed', 'error');
117
116
  addlogs(self.config, formatError(error), 'error');
118
117
 
119
118
  throw error;
@@ -103,7 +103,7 @@ module.exports = class ImportEntries {
103
103
  }
104
104
  }
105
105
  } catch (error) {
106
- addlogs(this.config, `Failed to read the content types to import entries ${util.formatError(error)}`);
106
+ addlogs(this.config, `Failed to read the content types to import entries ${util.formatError(error)}`, 'error');
107
107
  process.exit(0);
108
108
  }
109
109
  }
@@ -148,7 +148,7 @@ module.exports = class ImportEntries {
148
148
  (self.config.hasOwnProperty('onlylocales') && self.config.onlylocales.indexOf(lang) !== -1) ||
149
149
  !self.config.hasOwnProperty('onlylocales')
150
150
  ) {
151
- addlogs(self.config, `Starting to create entries ${lang} locale`, 'info');
151
+ addlogs(self.config, `Starting to create entries '${lang}' locale`, 'info');
152
152
  await self.createEntries(lang, mappedAssetUids, mappedAssetUrls);
153
153
  addlogs(self.config, 'Entries created successfully', 'info');
154
154
  try {
@@ -156,7 +156,8 @@ module.exports = class ImportEntries {
156
156
  } catch (error) {
157
157
  addlogs(
158
158
  self.config,
159
- `Failed get the existing entries to update the mapper ${util.formatError(error)}, 'error`,
159
+ `Failed get the existing entries to update the mapper ${util.formatError(error)}`,
160
+ 'error',
160
161
  );
161
162
  }
162
163
  addlogs(self.config, 'Starting to update entries with references', 'info');
@@ -164,7 +165,7 @@ module.exports = class ImportEntries {
164
165
  addlogs(self.config, "Successfully imported '" + lang + "' entries!", 'success');
165
166
  counter++;
166
167
  } else {
167
- addlogs(self.config, lang + ' has not been configured for import, thus skipping it', 'success');
168
+ addlogs(self.config,`'${lang}' has not been configured for import, thus skipping it`, 'success');
168
169
  counter++;
169
170
  }
170
171
  },
@@ -189,7 +190,8 @@ module.exports = class ImportEntries {
189
190
  } catch (error) {
190
191
  addlogs(
191
192
  self.config,
192
- `Failed to update the field rules for content type ${schema.uid} ${util.formatError(error)}`,
193
+ `Failed to update the field rules for content type '${schema.uid}' ${util.formatError(error)}`,
194
+ 'error'
193
195
  );
194
196
  }
195
197
  }
@@ -254,7 +256,7 @@ module.exports = class ImportEntries {
254
256
  'success',
255
257
  );
256
258
  } else {
257
- addlogs(this.config, `Creating entries for content type ${ctUid} in language ${lang} ...`, 'success');
259
+ addlogs(this.config, `Creating entries for content type '${ctUid}' in language '${lang}' ...`, 'success');
258
260
  for (let eUid in entries) {
259
261
  if (eUid) {
260
262
  try {
@@ -281,7 +283,7 @@ module.exports = class ImportEntries {
281
283
  self.installedExtensions,
282
284
  );
283
285
  } catch (error) {
284
- addlogs(this.config, 'Failed to update entry while creating entry id ' + eUid);
286
+ addlogs(this.config, `Failed to update entry while creating entry id '${eUid}'`, 'error');
285
287
  addlogs(this.config, util.formatError(error), 'error');
286
288
  }
287
289
  }
@@ -479,13 +481,7 @@ module.exports = class ImportEntries {
479
481
  } else {
480
482
  addlogs(
481
483
  this.config,
482
- chalk.white(
483
- 'Unable to find entry file path for ' +
484
- ctUid +
485
- " content type!\nThe file '" +
486
- eFilePath +
487
- "' does not exist!",
488
- ),
484
+ `Unable to find entry file path for '${ctUid}' content type!\nThe file '${eFilePath}' does not exist!`,
489
485
  'error',
490
486
  );
491
487
  }
@@ -499,7 +495,7 @@ module.exports = class ImportEntries {
499
495
  return resolve();
500
496
  })
501
497
  .catch((error) => {
502
- addlogs(this.config, chalk.red("Failed to create entries in '" + lang + "' language"), 'error');
498
+ addlogs(this.config, `Failed to create entries in '${lang}' language`, 'error');
503
499
  return reject(error);
504
500
  });
505
501
  });
@@ -568,7 +564,7 @@ module.exports = class ImportEntries {
568
564
  // map failed reference uids @mapper/language/unmapped-uids.json
569
565
  let refUidMapperPath = path.join(this.entryMapperPath, lang);
570
566
 
571
- addlogs(this.config, 'staring to update the entry for reposting');
567
+ addlogs(this.config, 'Starting to update the entry for reposting');
572
568
 
573
569
  entries = _.map(entries, (entry) => {
574
570
  try {
@@ -598,6 +594,7 @@ module.exports = class ImportEntries {
598
594
  addlogs(
599
595
  this.config,
600
596
  `Failed to update the entry ${uid} references while reposting ${util.formatError(error)}`,
597
+ 'error'
601
598
  );
602
599
  }
603
600
  });
@@ -645,14 +642,7 @@ module.exports = class ImportEntries {
645
642
  .catch((error) => {
646
643
  addlogs(
647
644
  this.config,
648
- chalk.red(
649
- 'Entry Uid: ' +
650
- entry.uid +
651
- ' of Content Type: ' +
652
- ctUid +
653
- ' failed to update in locale: ' +
654
- lang,
655
- ),
645
+ `Entry Uid '${entry.uid}' of Content Type '${ctUid}' failed to update in locale '${lang}'`,
656
646
  'error',
657
647
  );
658
648
 
@@ -685,7 +675,7 @@ module.exports = class ImportEntries {
685
675
  })
686
676
  .catch((error) => {
687
677
  // error while executing entry in batch
688
- addlogs(this.config, chalk.red('Failed re-post entries at batch no: ' + (index + 1)), 'error');
678
+ addlogs(this.config, `Failed re-post entries at batch no: '${(index + 1)}`, 'error');
689
679
  addlogs(this.config, util.formatError(error), 'error');
690
680
  // throw error;
691
681
  });
@@ -706,7 +696,8 @@ module.exports = class ImportEntries {
706
696
  // error while updating entries with references
707
697
  addlogs(
708
698
  this.config,
709
- chalk.red(`Failed re-post entries of content type ${ctUid} locale ${lang}`, 'error'),
699
+ `Failed re-post entries of content type ${ctUid} locale ${lang}`,
700
+ 'error',
710
701
  );
711
702
  addlogs(this.config, util.formatError(error), 'error');
712
703
  // throw error;
@@ -723,7 +714,7 @@ module.exports = class ImportEntries {
723
714
  })
724
715
  .catch((error) => {
725
716
  // error while updating entry references
726
- addlogs(this.config, chalk.red('Failed to re post entries in ' + lang + ' language'), 'error');
717
+ addlogs(this.config, `Failed to re post entries in '${lang}' language`, 'error');
727
718
  return reject(error);
728
719
  });
729
720
  });
@@ -792,9 +783,9 @@ module.exports = class ImportEntries {
792
783
  .then((_updatedcontentType) => {
793
784
  // empty function
794
785
  })
795
- .catch((_error) => {
786
+ .catch((error) => {
796
787
  addlogs(this.config, util.formatError(error), 'error');
797
- reject(`Failed suppress content type ${schema.uid} reference fields`);
788
+ reject(`Failed suppress content type '${schema.uid}' reference fields`);
798
789
  });
799
790
  // update 5 content types at a time
800
791
  },
@@ -890,7 +881,7 @@ module.exports = class ImportEntries {
890
881
  return resolveContentType();
891
882
  })
892
883
  .catch((error) => {
893
- addlogs(this.config, chalk.red('Failed to re-update ' + schema.uid), 'error');
884
+ addlogs(this.config, `Failed to re-update '${schema.uid}`, 'error');
894
885
  addlogs(this.config, error, 'error');
895
886
  return rejectContentType(error);
896
887
  });
@@ -951,7 +942,7 @@ module.exports = class ImportEntries {
951
942
  addlogs(this.config, 'Removed bugged entry from master ' + JSON.stringify(entry), 'success');
952
943
  })
953
944
  .catch((error) => {
954
- addlogs(this.config, chalk.red('Failed to remove bugged entry from master language'), 'error');
945
+ addlogs(this.config, 'Failed to remove bugged entry from master language', 'error');
955
946
  addlogs(this.config, util.formatError(error), 'error');
956
947
  });
957
948
  },
@@ -976,6 +967,7 @@ module.exports = class ImportEntries {
976
967
  .catch((error) => {
977
968
  // error while removing bugged entries from stack
978
969
  addlogs(this.config, util.formatError(error), 'error');
970
+ addlogs(this.config, error, 'error');
979
971
  });
980
972
  });
981
973
  }
@@ -1057,7 +1049,7 @@ module.exports = class ImportEntries {
1057
1049
  } else {
1058
1050
  return;
1059
1051
  }
1060
-
1052
+
1061
1053
  return Promise.map(
1062
1054
  batches,
1063
1055
  async (batch, index) => {
@@ -1097,7 +1089,7 @@ module.exports = class ImportEntries {
1097
1089
  // addlogs(this.config, 'Entry ' + eUid + ' published successfully in ' + ctUid + ' content type', 'success')
1098
1090
  addlogs(
1099
1091
  this.config,
1100
- 'Entry ' + eUid + ' published successfully in ' + ctUid + ' content type',
1092
+ `Entry '${eUid}' published successfully in '${ctUid}' content type`,
1101
1093
  'success',
1102
1094
  );
1103
1095
  return resolveEntryPublished(result);
@@ -1106,7 +1098,8 @@ module.exports = class ImportEntries {
1106
1098
  .catch((err) => {
1107
1099
  addlogs(
1108
1100
  this.config,
1109
- `failed to publish entry ${eUid} content type ${ctUid} ${util.formatError(err)}`,
1101
+ `failed to publish entry '${eUid}' content type '${ctUid}' ${util.formatError(err)}`,
1102
+ 'error'
1110
1103
  );
1111
1104
  return resolveEntryPublished('');
1112
1105
  });
@@ -1126,6 +1119,7 @@ module.exports = class ImportEntries {
1126
1119
  .catch((error) => {
1127
1120
  // error while executing entry in batch
1128
1121
  addlogs(this.config, util.formatError(error), 'error');
1122
+ addlogs(this.config, error, 'error');
1129
1123
  });
1130
1124
  },
1131
1125
  {
@@ -1134,10 +1128,10 @@ module.exports = class ImportEntries {
1134
1128
  )
1135
1129
  .then(() => {
1136
1130
  // addlogs(this.config, 'Entries published successfully in ' + ctUid + ' content type', 'success')
1137
- addlogs('Entries published successfully in ' + ctUid + ' content type');
1131
+ addlogs(this.config, `Entries published successfully in '${ctUid}' content type`, 'info');
1138
1132
  })
1139
1133
  .catch((error) => {
1140
- addlogs(this.config, `failed to publish entry in content type ${ctUid} ${util.formatError(error)}`);
1134
+ addlogs(this.config, `failed to publish entry in content type '${ctUid}' ${util.formatError(error)}`, 'error');
1141
1135
  });
1142
1136
  },
1143
1137
  {
@@ -1149,7 +1143,7 @@ module.exports = class ImportEntries {
1149
1143
  // addlogs('Published entries successfully in ' +);
1150
1144
  })
1151
1145
  .catch((error) => {
1152
- addlogs(`Failed to publish few entries in ${lang} ${util.formatError(error)}`);
1146
+ addlogs(this.config, `Failed to publish few entries in '${lang}' ${util.formatError(error)}`, 'error');
1153
1147
  });
1154
1148
  },
1155
1149
  {
@@ -1160,7 +1154,7 @@ module.exports = class ImportEntries {
1160
1154
  return resolve();
1161
1155
  })
1162
1156
  .catch((error) => {
1163
- addlogs(`Failed to publish entries ${util.formatError(error)}`);
1157
+ addlogs(this.config,`Failed to publish entries. ${util.formatError(error)}`, 'error');
1164
1158
  });
1165
1159
  });
1166
1160
  }
@@ -71,13 +71,11 @@ module.exports = class ImportEnvironments {
71
71
  let error = JSON.parse(err.message);
72
72
 
73
73
  if (error.errors.name) {
74
- addlogs(self.config, chalk.white("Environment: '" + env.name + "' already exists"), 'error');
74
+ addlogs(self.config, `Environment '${env.name}' already exists`, 'error');
75
75
  } else {
76
76
  addlogs(
77
77
  config,
78
- chalk.white(
79
- "Environment: '" + env.name + "' failed to be import\n " + JSON.stringify(error.errors),
80
- ),
78
+ `Environment '${env.name}' failed to be import\n ${JSON.stringify(error.errors)}`,
81
79
  'error',
82
80
  );
83
81
  }
@@ -86,7 +84,7 @@ module.exports = class ImportEnvironments {
86
84
  // the environment has already been created
87
85
  addlogs(
88
86
  config,
89
- chalk.white("The environment: '" + env.name + "' already exists. Skipping it to avoid duplicates!"),
87
+ `The environment ${env.name} already exists. Skipping it to avoid duplicates!`,
90
88
  'success',
91
89
  );
92
90
  }
@@ -100,7 +98,7 @@ module.exports = class ImportEnvironments {
100
98
  })
101
99
  .catch(function (error) {
102
100
  helper.writeFileSync(envFailsPath, self.fails);
103
- addlogs(self.config, chalk.red(`Failed to import environment ${formatError(error)}`), 'error');
101
+ addlogs(self.config, `Failed to import environment, ${formatError(error)}`, 'error');
104
102
  reject(error);
105
103
  });
106
104
  });
@@ -69,11 +69,11 @@ module.exports = class ImportExtensions {
69
69
  let error = JSON.parse(err.message);
70
70
  self.fails.push(ext);
71
71
  if (error.errors.title) {
72
- addlogs(self.config, chalk.white("Extension: '" + ext.title + "' already exists"), 'success');
72
+ addlogs(self.config, `Extension '${ext.title}' already exists`, 'error');
73
73
  } else {
74
74
  addlogs(
75
75
  config,
76
- chalk.white("Extension: '" + ext.title + "' failed to be import\n " + JSON.stringify(error.errors)),
76
+ chalk.white(`Extension '${ext.title}' failed to be import\n ${JSON.stringify(error.errors)}`),
77
77
  'error',
78
78
  );
79
79
  }
@@ -100,7 +100,7 @@ module.exports = class ImportExtensions {
100
100
  .catch(function (error) {
101
101
  // error while importing extensions
102
102
  helper.writeFileSync(extFailsPath, self.fails);
103
- addlogs(self.config, chalk.red(`Extension import failed ${util.formatError(error)}`), 'error');
103
+ addlogs(self.config, `Extension import failed ${util.formatError(error)}`, 'error');
104
104
  reject(error);
105
105
  });
106
106
  });
@@ -65,11 +65,11 @@ module.exports = class ImportGlobalFields {
65
65
  let snipUids = Object.keys(self.globalfields);
66
66
  return Promise.map(
67
67
  snipUids,
68
- function (snipUid) {
68
+ async function (snipUid) {
69
69
  let flag = { supressed: false };
70
70
  let snip = self.globalfields[snipUid];
71
71
  extension_supress(snip.schema, self.config.preserveStackVersion, self.installedExtensions);
72
- removeReferenceFields(snip.schema, flag);
72
+ await removeReferenceFields(snip.schema, flag, self.stackAPIClient);
73
73
 
74
74
  if (flag.supressed) {
75
75
  // eslint-disable-next-line no-undef
@@ -96,9 +96,9 @@ module.exports = class ImportGlobalFields {
96
96
  let error = JSON.parse(err.message);
97
97
  if (error.errors.title) {
98
98
  // eslint-disable-next-line no-undef
99
- addlogs(self.config, chalk.white(snip.uid + ' globalfield already exists'), 'error');
99
+ addlogs(self.config, `Globalfield '${snip.uid} already exists'`, 'error');
100
100
  } else {
101
- addlogs(self.config, chalk.red(`Globalfield failed to import ${formatError(error)}`), 'error');
101
+ addlogs(self.config, `Globalfield failed to import ${formatError(error)}`, 'error');
102
102
  }
103
103
 
104
104
  self.fails.push(snip);
@@ -119,7 +119,7 @@ module.exports = class ImportGlobalFields {
119
119
  // globalfields have imported successfully
120
120
  helper.writeFileSync(globalfieldsSuccessPath, self.success);
121
121
  helper.writeFileSync(globalFieldsPending, _globalField_pending);
122
- addlogs(self.config, chalk.green('globalfields have been imported successfully!'), 'success');
122
+ addlogs(self.config, chalk.green('Globalfields have been imported successfully!'), 'success');
123
123
  return resolve();
124
124
  })
125
125
  .catch(function (err) {
@@ -127,7 +127,7 @@ module.exports = class ImportGlobalFields {
127
127
  // error while importing globalfields
128
128
  addlogs(self.config, err, 'error');
129
129
  helper.writeFileSync(globalfieldsFailsPath, self.fails);
130
- addlogs(self.config, chalk.red('globalfields import failed'), 'error');
130
+ addlogs(self.config, `Globalfields import failed. ${formatError(err)}`, 'error');
131
131
  return reject(error);
132
132
  });
133
133
  });
@@ -76,16 +76,16 @@ module.exports = class ImportLabels {
76
76
  .catch(function (error) {
77
77
  self.fails.push(label);
78
78
  if (error.errors.name) {
79
- addlogs(self.config, chalk.red("Label: '" + label.name + "' already exist"), 'error');
79
+ addlogs(self.config,`Label '${label.name}' already exist`, 'error');
80
80
  } else {
81
- addlogs(self.config, chalk.red("Label: '" + label.name + "' failed to be imported\n"), 'error');
81
+ addlogs(self.config,`Label '${label.name}' failed to be imported\n`, 'error');
82
82
  }
83
83
  });
84
84
  } else {
85
85
  // the label has already been created
86
86
  addlogs(
87
87
  self.config,
88
- chalk.white("The label: '" + label.name + "' already exists. Skipping it to avoid duplicates!"),
88
+ chalk.white(`The label '${label.name}' already exists. Skipping it to avoid duplicates!'`),
89
89
  'success',
90
90
  );
91
91
  }
@@ -104,7 +104,7 @@ module.exports = class ImportLabels {
104
104
  return resolve();
105
105
  })
106
106
  .catch(function (error) {
107
- addlogs(self.config, chalk.red(`Failed to import label ${formatError(error)}`), 'error');
107
+ addlogs(self.config, `Failed to import label, ${formatError(error)}`, 'error');
108
108
  // eslint-disable-next-line no-console
109
109
  return reject(error);
110
110
  });
@@ -113,7 +113,7 @@ module.exports = class ImportLabels {
113
113
  // error while importing labels
114
114
  helper.writeFileSync(labelUidMapperPath, self.labelUidMapper);
115
115
  helper.writeFileSync(labelFailsPath, self.fails);
116
- addlogs(self.config, chalk.red(`Failed to import label ${formatError(error)}`), 'error');
116
+ addlogs(self.config, `Failed to import label, ${formatError(error)}`, 'error');
117
117
  return reject(error);
118
118
  });
119
119
  });
@@ -91,16 +91,20 @@ module.exports = class ImportLanguages {
91
91
  .catch(function (err) {
92
92
  let error = JSON.parse(err.message);
93
93
  if (error.hasOwnProperty('errorCode') && error.errorCode === 247) {
94
- addlogs(self.config, error.errors.code[0], 'success');
94
+ if(error.errors.code){
95
+ addlogs(self.config, error.errors.code[0], 'error');
96
+ }else{
97
+ addlogs(self.config, err, 'error');
98
+ }
95
99
  return err;
96
100
  }
97
101
  self.fails.push(lang);
98
- addlogs(self.config, chalk.red("Language: '" + lang.code + "' failed to be import\n"), 'error');
102
+ addlogs(self.config, `Language '${lang.code}' failed to import\n`, 'error');
99
103
  addlogs(self.config, formatError(err), 'error');
100
104
  });
101
105
  } else {
102
106
  // the language has already been created
103
- addlogs(self.config, chalk.yellow("The language: '" + lang.code + "' already exists."), 'error');
107
+ addlogs(self.config, `The language '${lang.code}' already exists.`, 'error');
104
108
  }
105
109
 
106
110
  // import 2 languages at a time
@@ -124,8 +128,7 @@ module.exports = class ImportLanguages {
124
128
  .catch(function (error) {
125
129
  // error while importing languages
126
130
  helper.writeFileSync(langFailsPath, self.fails);
127
- addlogs(self.config, chalk.red('Language import failed'), 'error');
128
- addlogs(self.config, formatError(error), 'error');
131
+ addlogs(self.config, `Language import failed. ${formatError(error)}`, 'error');
129
132
  reject('failed to import Languages');
130
133
  });
131
134
  });
@@ -515,16 +515,21 @@ module.exports = class ImportMarketplaceApps {
515
515
  return Promise.resolve();
516
516
  }
517
517
 
518
- return this.httpClient
519
- .put(`${this.developerHubBaseUrl}/installations/${uid}`, payload)
520
- .then(({ data }) => {
521
- if (data.message) {
522
- log(this.config, formatError(data.message), 'success');
523
- } else {
524
- log(this.config, `${app.manifest.name} app config updated successfully.!`, 'success');
525
- }
526
- })
527
- .catch((error) => log(this.config, formatError(error), 'error'));
518
+ let installation = this.client
519
+ .organization(this.config.org_uid)
520
+ .app(app.manifest.uid)
521
+ .installation(uid)
522
+
523
+ installation = Object.assign(installation, payload)
524
+
525
+ return installation
526
+ .update()
527
+ .then(async data => {
528
+ if (data) {
529
+ log(this.config, `${app.manifest.name} app config updated successfully.!`, 'success');
530
+ }
531
+ })
532
+ .catch((error) => log(this.config, formatError(error), 'error'))
528
533
  }
529
534
 
530
535
  validateAppName(name) {
@@ -80,7 +80,7 @@ module.exports = class ImportWebhooks {
80
80
  self.fails.push(web);
81
81
  addlogs(
82
82
  self.config,
83
- chalk.red("Webhooks: '" + web.name + "' failed to be import\n" + formatError(error)),
83
+ `Webhooks '${web.name}' failed to be import.\n ${formatError(error)}`,
84
84
  'error',
85
85
  );
86
86
  });
@@ -105,7 +105,7 @@ module.exports = class ImportWebhooks {
105
105
  .catch(function (error) {
106
106
  // error while importing environments
107
107
  helper.writeFileSync(webFailsPath, self.fails);
108
- addlogs(self.config, chalk.red('Webhooks import failed'), 'error');
108
+ addlogs(self.config, `Webhooks import failed. ${formatError(error)}`, 'error');
109
109
  return reject(error);
110
110
  });
111
111
  });
@@ -97,7 +97,7 @@ module.exports = class importWorkflows {
97
97
  } catch (error) {
98
98
  addlogs(
99
99
  self.config,
100
- chalk.red('Error while importing workflows roles. ' + formatError(error)),
100
+ `Error while importing workflows roles. ${formatError(error)}`,
101
101
  'error',
102
102
  );
103
103
  reject({ message: 'Error while importing workflows roles' });
@@ -128,24 +128,22 @@ module.exports = class importWorkflows {
128
128
  .catch(function (error) {
129
129
  self.fails.push(workflow);
130
130
  if (error.errors.name) {
131
- addlogs(self.config, chalk.red("workflow: '" + workflow.name + "' already exist"), 'error');
131
+ addlogs(self.config, `workflow ${workflow.name} already exist`, 'error');
132
132
  } else if (error.errors['workflow_stages.0.users']) {
133
133
  addlogs(
134
134
  self.config,
135
- chalk.red(
136
- "Failed to import Workflows as you've specified certain roles in the Stage transition and access rules section. We currently don't import roles to the stack.",
137
- ),
135
+ "Failed to import Workflows as you've specified certain roles in the Stage transition and access rules section. We currently don't import roles to the stack.",
138
136
  'error',
139
137
  );
140
138
  } else {
141
- addlogs(self.config, chalk.red("workflow: '" + workflow.name + "' failed"), 'error');
139
+ addlogs(self.config, `workflow ${workflow.name} failed.`, 'error');
142
140
  }
143
141
  });
144
142
  } else {
145
143
  // the workflow has already been created
146
144
  addlogs(
147
145
  self.config,
148
- chalk.white("The Workflows: '" + workflow.name + "' already exists. Skipping it to avoid duplicates!"),
146
+ chalk.white( `The Workflows ${workflow.name} already exists. Skipping it to avoid duplicates!`),
149
147
  'success',
150
148
  );
151
149
  }
@@ -160,8 +158,7 @@ module.exports = class importWorkflows {
160
158
  })
161
159
  .catch(function (error) {
162
160
  helper.writeFileSync(workflowFailsPath, self.fails);
163
- addlogs(self.config, chalk.red('Workflows import failed'), 'error');
164
- addlogs(self.config, formatError(error), 'error');
161
+ addlogs(self.config, `Workflows import failed. ${formatError(error)}`, 'error');
165
162
  return reject(error);
166
163
  });
167
164
  });
@@ -91,7 +91,10 @@ function init(_logPath) {
91
91
  errorLogger = winston.createLogger({
92
92
  transports: [
93
93
  new winston.transports.File(errorTransport),
94
- new winston.transports.Console({ level: 'error', format: winston.format.simple() }),
94
+ new winston.transports.Console({
95
+ level: 'error',
96
+ format: winston.format.combine(winston.format.colorize({ all: true, colors:{ error: 'red'} }), winston.format.simple()),
97
+ }),
95
98
  ],
96
99
  levels: { error: 0 },
97
100
  });
@@ -1,7 +1,7 @@
1
- var _ = require('lodash');
1
+ const _ = require('lodash');
2
2
 
3
3
  /* eslint-disable no-empty */
4
- var removeReferenceFields = (module.exports = function (schema, flag) {
4
+ const removeReferenceFields = (module.exports = async function (schema, flag, stackAPIClient) {
5
5
  for (let i = 0; i < schema.length; i++) {
6
6
  if (schema[i].data_type === 'group') {
7
7
  removeReferenceFields(schema[i].schema, flag);
@@ -11,27 +11,41 @@ var removeReferenceFields = (module.exports = function (schema, flag) {
11
11
  }
12
12
  } else if (schema[i].data_type === 'reference') {
13
13
  flag.supressed = true;
14
- schema.splice(i, 1);
15
- --i;
16
- if (schema.length < 1) {
17
- schema.push({
18
- data_type: 'text',
19
- display_name: 'dummyTest',
20
- uid: 'dummy_test',
21
- field_metadata: {
22
- description: '',
23
- default_value: '',
24
- version: 3,
25
- },
26
- format: '',
27
- error_messages: {
14
+ // Check if content-type exists
15
+ // If exists, then no change should be required.
16
+ let isContentTypeError = false;
17
+ for (let j = 0; j < schema[i].reference_to.length; j++) {
18
+ try {
19
+ await stackAPIClient.contentType(schema[i].reference_to[j]).fetch();
20
+ } catch (error) {
21
+ // Else warn and modify the schema object.
22
+ isContentTypeError = true;
23
+ console.warn(`Content-type ${schema[i].reference_to[j]} does not exist. Removing the field from schema`);
24
+ }
25
+ }
26
+ if (isContentTypeError) {
27
+ schema.splice(i, 1);
28
+ --i;
29
+ if (schema.length < 1) {
30
+ schema.push({
31
+ data_type: 'text',
32
+ display_name: 'dummyTest',
33
+ uid: 'dummy_test',
34
+ field_metadata: {
35
+ description: '',
36
+ default_value: '',
37
+ version: 3,
38
+ },
28
39
  format: '',
29
- },
30
- multiple: false,
31
- mandatory: false,
32
- unique: false,
33
- non_localizable: false,
34
- });
40
+ error_messages: {
41
+ format: '',
42
+ },
43
+ multiple: false,
44
+ mandatory: false,
45
+ unique: false,
46
+ non_localizable: false,
47
+ });
48
+ }
35
49
  }
36
50
  } else if( // handling entry references in json rte
37
51
  schema[i].data_type === 'json'