@contentstack/cli-cm-bulk-publish 0.1.1-beta.3 → 1.0.0

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.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +533 -281
  3. package/oclif.manifest.json +1 -1
  4. package/package.json +27 -12
  5. package/src/commands/cm/assets/publish.js +233 -0
  6. package/src/commands/cm/assets/unpublish.js +179 -0
  7. package/src/commands/cm/bulk-publish/cross-publish.js +187 -68
  8. package/src/commands/cm/bulk-publish/index.js +5 -6
  9. package/src/commands/cm/entries/publish-modified.js +197 -0
  10. package/src/commands/cm/entries/publish-non-localized-fields.js +208 -0
  11. package/src/commands/cm/entries/publish-only-unpublished.js +109 -0
  12. package/src/commands/cm/entries/publish.js +254 -0
  13. package/src/commands/cm/entries/unpublish.js +184 -0
  14. package/src/commands/cm/entries/update-and-publish.js +191 -0
  15. package/src/commands/cm/stacks/publish-clear-logs.js +82 -0
  16. package/src/commands/cm/stacks/publish-configure.js +46 -0
  17. package/src/commands/cm/stacks/publish-revert.js +102 -0
  18. package/src/commands/cm/stacks/publish.js +110 -0
  19. package/src/commands/cm/stacks/unpublish.js +282 -0
  20. package/src/config/index.js +60 -99
  21. package/src/consumer/publish.js +600 -377
  22. package/src/producer/add-fields.js +209 -189
  23. package/src/producer/cross-publish.js +195 -136
  24. package/src/producer/nonlocalized-field-changes.js +235 -216
  25. package/src/producer/publish-assets.js +104 -98
  26. package/src/producer/publish-edits.js +126 -113
  27. package/src/producer/publish-entries.js +135 -112
  28. package/src/producer/publish-unpublished-env.js +126 -114
  29. package/src/producer/revert.js +261 -230
  30. package/src/producer/unpublish.js +175 -137
  31. package/src/services/publish-only-unpublished.js +130 -0
  32. package/src/util/client.js +21 -17
  33. package/src/util/command-helper.js +25 -0
  34. package/src/util/fs.js +10 -11
  35. package/src/util/index.js +15 -16
  36. package/src/util/logger.js +21 -25
  37. package/src/util/queue.js +13 -13
  38. package/src/util/retryfailed.js +8 -4
  39. package/src/util/store.js +44 -52
  40. package/src/commands/cm/bulk-publish/add-fields.js +0 -117
  41. package/src/commands/cm/bulk-publish/assets.js +0 -117
  42. package/src/commands/cm/bulk-publish/clear.js +0 -63
  43. package/src/commands/cm/bulk-publish/configure.js +0 -46
  44. package/src/commands/cm/bulk-publish/entries.js +0 -125
  45. package/src/commands/cm/bulk-publish/entry-edits.js +0 -123
  46. package/src/commands/cm/bulk-publish/nonlocalized-field-changes.js +0 -116
  47. package/src/commands/cm/bulk-publish/revert.js +0 -81
  48. package/src/commands/cm/bulk-publish/unpublish.js +0 -164
  49. package/src/commands/cm/bulk-publish/unpublished-entries.js +0 -122
  50. package/src/util/request.js +0 -57
package/src/util/index.js CHANGED
@@ -2,11 +2,11 @@ const chalk = require('chalk')
2
2
  const fs = require('fs')
3
3
 
4
4
  function prettyPrint(data) {
5
- console.log(chalk.yellow('Configuration to be used for executing this command:'))
6
- Object.keys(data).forEach((key, index) => {
7
- console.log(chalk.grey(`${key}: ${data[key]}`))
8
- })
9
- console.log('\n')
5
+ console.log(chalk.yellow('Configuration to be used for executing this command:'))
6
+ Object.keys(data).forEach((key, _index) => {
7
+ console.log(chalk.grey(`${key}: ${data[key]}`))
8
+ })
9
+ console.log('\n')
10
10
  }
11
11
 
12
12
  function formatError(error) {
@@ -14,13 +14,11 @@ function formatError(error) {
14
14
  if (typeof error === 'string') {
15
15
  error = JSON.parse(error)
16
16
  } else {
17
- error = JSON.parse(error.message)
17
+ error = JSON.parse(error.message)
18
18
  }
19
- } catch(e) {
20
- error = error.message
21
- }
22
- let message = (error.errorMessage) ? error.errorMessage : (error.error_message) ? error.error_message : error
23
- if (error.errors && Object.keys(error.errors).length > 0){
19
+ } catch (e) {}
20
+ let message = error.errorMessage || error.error_message || error
21
+ if (error.errors && Object.keys(error.errors).length > 0) {
24
22
  Object.keys(error.errors).forEach((e) => {
25
23
  let entity = e
26
24
  if (e === 'authorization')
@@ -41,7 +39,8 @@ function formatHostname(hostname) {
41
39
  return hostname.split('//').pop()
42
40
  }
43
41
 
44
- function setDelayForBulkPublish(queue) {
42
+ function setDelayForBulkPublish(_queue) {
43
+ // empty block
45
44
  // queue.requestBatchSize = 1
46
45
  // queue.delay = 1
47
46
  }
@@ -50,13 +49,13 @@ function getNumberOfBulkPublishRequests(count) {
50
49
  // for example, if the total count of elements is 738
51
50
  // then the number of requets that'll be required are (if there are 10 elements per request)
52
51
  // (738 - 8)/10 + 1 = 74 requests
53
- return (count - (count % 10))/10 + 1
52
+ return (count - (count % 10)) / 10 + 1
54
53
  }
55
54
 
56
55
  function isEmpty(file) {
57
56
  return new Promise((resolve) => {
58
- fs.readFile(file, (err, data) => {
59
- if (data.length === 0){
57
+ fs.readFile(file, (_err, data) => {
58
+ if (data.length === 0) {
60
59
  return resolve(true)
61
60
  }
62
61
  return resolve(false)
@@ -64,4 +63,4 @@ function isEmpty(file) {
64
63
  })
65
64
  }
66
65
 
67
- module.exports = { prettyPrint, formatError, formatHostname, setDelayForBulkPublish, getNumberOfBulkPublishRequests, isEmpty}
66
+ module.exports = { prettyPrint, formatError, formatHostname, setDelayForBulkPublish, getNumberOfBulkPublishRequests, isEmpty }
@@ -1,45 +1,41 @@
1
1
  const path = require('path');
2
2
  const winston = require('winston');
3
- const homedir = require('os').homedir()
4
- const logsDir = path.join(homedir, 'contentstack-cli-logs', 'bulk-publish')
3
+ const cwd = process.cwd();
4
+ const logsDir = path.join(cwd, 'contentstack-cli-logs', 'bulk-publish');
5
5
 
6
6
  let filename;
7
7
 
8
8
  module.exports.getLoggerInstance = (fileName) => {
9
9
  filename = path.join(logsDir, fileName);
10
- const logger = winston.createLogger({
10
+ return winston.createLogger({
11
11
  transports: [
12
12
  new winston.transports.File({ filename: `${filename}.error`, level: 'error' }),
13
13
  new winston.transports.File({ filename: `${filename}.success`, level: 'info' }),
14
14
  ],
15
15
  });
16
- return logger;
17
16
  };
18
17
 
19
18
  /* eslint-disable no-multi-assign */
20
- const getFileLoggerInstance = module.exports.getFileLoggerInstance = (fileName) => {
19
+ const getFileLoggerInstance = (module.exports.getFileLoggerInstance = (fileName) => {
21
20
  filename = path.join(logsDir, fileName);
22
- const logger = winston.createLogger({
23
- transports: [
24
- new winston.transports.File({ filename }),
25
- ],
21
+ return winston.createLogger({
22
+ transports: [new winston.transports.File({ filename })],
26
23
  });
27
- return logger;
28
- };
29
-
24
+ });
30
25
 
31
- module.exports.getAllLogs = (fname) => new Promise((resolve, reject) => {
32
- const options = {
33
- limit: 1000000000000,
34
- start: 0,
35
- order: 'desc',
36
- };
37
- const logger = getFileLoggerInstance(fname);
38
- logger.query(options, async (err, result) => {
39
- if (err) return reject(err);
40
- return resolve(result);
26
+ module.exports.getAllLogs = (fname) =>
27
+ new Promise((resolve, reject) => {
28
+ const options = {
29
+ limit: 1000000000000,
30
+ start: 0,
31
+ order: 'desc',
32
+ };
33
+ const logger = getFileLoggerInstance(fname);
34
+ logger.query(options, async (err, result) => {
35
+ if (err) return reject(err);
36
+ return resolve(result);
37
+ });
41
38
  });
42
- });
43
39
 
44
40
  module.exports.addLogs = (logger, data, Type) => {
45
41
  switch (Type) {
@@ -55,5 +51,5 @@ module.exports.addLogs = (logger, data, Type) => {
55
51
  };
56
52
 
57
53
  module.exports.getLogsDirPath = () => {
58
- return logsDir
59
- }
54
+ return logsDir;
55
+ };
package/src/util/queue.js CHANGED
@@ -7,8 +7,8 @@ class Queue extends EventEmitter {
7
7
  this.count = 0;
8
8
  this.store = [];
9
9
  this.config = {};
10
- this.delay = 1
11
- this.requestBatchSize = 1
10
+ this.delay = 1;
11
+ this.requestBatchSize = 1;
12
12
  this.on('dequeue', this.check);
13
13
  }
14
14
 
@@ -20,16 +20,16 @@ class Queue extends EventEmitter {
20
20
 
21
21
  Enqueue(obj) {
22
22
  if (!obj.retry) {
23
- obj = {obj, retry: 0}
23
+ obj = { obj, retry: 0 };
24
24
  }
25
25
  if (this.count === this.requestBatchSize) {
26
26
  return this.sleep(this.delay).then(() => {
27
- this.count = 1 // reset the count to 1. Because the current object will be processed too, and that counts as one request
27
+ this.count = 1; // reset the count to 1. Because the current object will be processed too, and that counts as one request
28
28
  this.store.push(obj);
29
29
  this.check();
30
- })
30
+ });
31
31
  } else {
32
- this.count++
32
+ this.count++;
33
33
  this.store.push(obj);
34
34
  this.check();
35
35
  }
@@ -44,14 +44,14 @@ class Queue extends EventEmitter {
44
44
  }
45
45
 
46
46
  sleep(seconds) {
47
- return new Promise(resolve => {
48
- setTimeout(resolve, seconds * 1000)
49
- })
47
+ return new Promise((resolve) => {
48
+ setTimeout(resolve, seconds * 1000);
49
+ });
50
50
  }
51
51
  }
52
52
 
53
53
  module.exports = {
54
- getQueue: function() {
55
- return new Queue()
56
- }
57
- }
54
+ getQueue: function () {
55
+ return new Queue();
56
+ },
57
+ };
@@ -1,12 +1,12 @@
1
1
  const { getAllLogs } = require('./logger');
2
- const {getStack} = require('./client.js')
2
+ const { getStack } = require('./client.js');
3
3
 
4
4
  module.exports = async (filename, queue, Type) => {
5
5
  const logs = await getAllLogs(filename);
6
6
  if (logs.file.length > 0) {
7
7
  logs.file.forEach((log) => {
8
8
  if (Type === 'bulk') {
9
- log.message.options.stack = getStack({alias: log.message.alias, host: log.message.host})
9
+ log.message.options.stack = getStack({ alias: log.message.alias, host: log.message.host });
10
10
  queue.Enqueue(log.message.options);
11
11
  }
12
12
  if (Type === 'publish') {
@@ -18,11 +18,15 @@ module.exports = async (filename, queue, Type) => {
18
18
  entryUid: log.message.options.entryUid,
19
19
  locale: log.message.options.locale,
20
20
  Type: 'entry',
21
- stack: getStack({alias: log.message.alias, host: log.message.host})
21
+ stack: getStack({ alias: log.message.alias, host: log.message.host }),
22
22
  });
23
23
  } else {
24
24
  queue.assetQueue.Enqueue({
25
- assetUid: log.message.options.assetUid, publish_details: log.message.options.publish_assets, environments: log.message.options.environments, Type: 'asset', stack: getStack({alias: log.message.alias, host: log.message.host})
25
+ assetUid: log.message.options.assetUid,
26
+ publish_details: log.message.options.publish_assets,
27
+ environments: log.message.options.environments,
28
+ Type: 'asset',
29
+ stack: getStack({ alias: log.message.alias, host: log.message.host }),
26
30
  });
27
31
  }
28
32
  }
package/src/util/store.js CHANGED
@@ -1,72 +1,64 @@
1
- const fs = require('fs')
2
- const path = require('path')
3
- const config = require('../config/index.js')
4
- const chalk = require('chalk')
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const config = require('../config/index.js');
4
+ const chalk = require('chalk');
5
5
 
6
6
  function save(key, data) {
7
- let bulkPublish = (config) ? config : {}
8
- let filePath = path.join(process.cwd(), config.json)
9
- bulkPublish[key] = data
7
+ let bulkPublish = config ? config : {};
8
+ let filePath = path.join(process.cwd(), config.json);
9
+ bulkPublish[key] = data;
10
10
  fs.writeFile(filePath, JSON.stringify(bulkPublish), (error) => {
11
- if(error) {
12
- console.log(chalk.red(error))
11
+ if (error) {
12
+ console.log(chalk.red(error));
13
13
  return;
14
14
  }
15
- console.log(chalk.green(`Configuration file has been successfully created at ${filePath}`))
16
- })
15
+ console.log(chalk.green(`Configuration file has been successfully created at ${filePath}`));
16
+ });
17
17
  }
18
18
 
19
19
  function get(key, filePath) {
20
20
  try {
21
- const missing = []
22
- const bulkPublish = require(filePath)
23
- // const bulkPublish = JSON.parse(fs.readFileSync(filePath, 'utf-8'))
21
+ const missing = [];
22
+ const bulkPublish = require(filePath);
24
23
  if (!bulkPublish) {
25
- throw new Error('Unable to read config file')
24
+ throw new Error('Unable to read config file');
26
25
  }
27
- if (!bulkPublish.alias){
28
- missing.push('alias')
26
+ if (!bulkPublish.alias) {
27
+ missing.push('alias');
29
28
  }
30
- if (missing.length > 0){
31
- throw new Error(`Please update the following values in the config file: ${missing.join(', ')}`)
29
+ if (missing.length > 0) {
30
+ throw new Error(`Please update the following values in the config file: ${missing.join(', ')}`);
32
31
  }
33
- if (key === 'revert')
34
- bulkPublish[key] = {}
35
- if (key === 'Unpublish' || key === 'cross_env_publish')
36
- bulkPublish[key] = handleFilterObj(bulkPublish[key])
32
+ if (key === 'revert') bulkPublish[key] = {};
33
+ if (key === 'Unpublish' || key === 'cross_env_publish') bulkPublish[key] = handleFilterObj(bulkPublish[key]);
37
34
  if (!bulkPublish[key] || Object.keys(bulkPublish[key]).length === 0) {
38
35
  if (key !== 'revert') {
39
- throw new Error(`Config is empty for ${key} case`)
36
+ throw new Error(`Config is empty for ${key} case`);
40
37
  }
41
38
  }
42
39
  return {
43
40
  alias: bulkPublish.alias,
44
- ...bulkPublish[key]
45
- }
46
- } catch(error) {
47
- if(error.code === 'ENOENT' || error.code === 'MODULE_NOT_FOUND')
48
- throw new Error('The given config file was not found')
49
- throw error
41
+ ...bulkPublish[key],
42
+ };
43
+ } catch (error) {
44
+ if (error.code === 'ENOENT' || error.code === 'MODULE_NOT_FOUND')
45
+ throw new Error('The given config file was not found');
46
+ throw error;
50
47
  }
51
48
  }
52
49
 
53
50
  function updateMissing(key, flags) {
54
- let savedConfig
55
- try {
56
- savedConfig = get(key, path.resolve(flags.config))
57
- } catch(error) {
58
- throw error
59
- }
60
- Object.keys(savedConfig).forEach(element => {
51
+ let savedConfig;
52
+ savedConfig = get(key, path.resolve(flags.config));
53
+ Object.keys(savedConfig).forEach((element) => {
61
54
  if (flags[element] === undefined) {
62
- console.log(`Using ${element} from config file`)
63
- flags[element] = savedConfig[element]
55
+ console.log(`Using ${element} from config file`);
56
+ flags[element] = savedConfig[element];
64
57
  }
65
- })
66
- if (flags.publishAllContentTypes)
67
- delete savedConfig.contentTypes
68
- console.log('\n')
69
- return flags
58
+ });
59
+ if (flags.publishAllContentTypes) delete savedConfig.contentTypes;
60
+ console.log('\n');
61
+ return flags;
70
62
  }
71
63
 
72
64
  // a fix for handling filter object in Unpublish and cross publish cases
@@ -74,17 +66,17 @@ function updateMissing(key, flags) {
74
66
  // because both unpublish and cross-publish commands build the filter object
75
67
  // internally, and in the original bulk-publish script the filter object was
76
68
  // mentioned in the config file itself
77
- function handleFilterObj(config) {
78
- config.environment = config.filter.environment
79
- config.contentType = config.filter.content_type_uid
80
- config.locale = config.filter.locale
81
- config.f_types = config.filter.type // adding f_types to differentiate the types specified in the config.js, and the types defined internally in Unpublish and Cross Publish
82
- delete config.filter
83
- return config
69
+ function handleFilterObj(config1) {
70
+ config1.environment = config1.filter.environment;
71
+ config1.contentType = config1.filter.content_type_uid;
72
+ config1.locale = config1.filter.locale;
73
+ config1.f_types = config1.filter.type; // adding f_types to differentiate the types specified in the config.js, and the types defined internally in Unpublish and Cross Publish
74
+ delete config1.filter;
75
+ return config1;
84
76
  }
85
77
 
86
78
  module.exports = {
87
79
  save: save,
88
80
  get: get,
89
81
  updateMissing: updateMissing,
90
- }
82
+ };
@@ -1,117 +0,0 @@
1
- const {Command, flags} = require('@oclif/command')
2
- const {start} = require('../../../producer/add-fields')
3
- const store = require('../../../util/store.js')
4
- const {cli} = require('cli-ux')
5
- const configKey = 'addFields'
6
- const { prettyPrint, formatError } = require('../../../util')
7
- const { getStack } = require('../../../util/client.js')
8
- let config
9
-
10
- class AddFieldsCommand extends Command {
11
- async run() {
12
- const {flags} = this.parse(AddFieldsCommand)
13
- let updatedFlags
14
- try {
15
- updatedFlags = (flags.config) ? store.updateMissing(configKey, flags) : flags
16
- } catch(error) {
17
- this.error(error.message, {exit: 2})
18
- }
19
- if (this.validate(updatedFlags)) {
20
- let stack
21
- if (!updatedFlags.retryFailed) {
22
- if(!updatedFlags.alias) {
23
- updatedFlags.alias = await cli.prompt('Please enter the management token alias to be used')
24
- }
25
- updatedFlags.bulkPublish = (updatedFlags.bulkPublish === 'false') ? false : true
26
- await this.config.runHook('validateManagementTokenAlias', {alias: updatedFlags.alias})
27
- config = {
28
- alias: updatedFlags.alias,
29
- host: this.config.userConfig.getRegion().cma
30
- }
31
- stack = getStack(config)
32
- }
33
- if (await this.confirmFlags(updatedFlags)) {
34
- try {
35
- if (!updatedFlags.retryFailed) {
36
- await start(updatedFlags, stack, config)
37
- } else {
38
- await start(updatedFlags)
39
- }
40
- } catch(error) {
41
- let message = formatError(error)
42
- this.error(message, {exit: 2})
43
- }
44
- } else {
45
- this.exit(0)
46
- }
47
- }
48
- }
49
-
50
- validate({contentTypes, locales, environments, retryFailed}) {
51
- let missing = []
52
- if (retryFailed) {
53
- return true
54
- }
55
-
56
- if (!contentTypes || contentTypes.length === 0) {
57
- missing.push('Content Types')
58
- }
59
-
60
- if (!locales || locales.length === 0) {
61
- missing.push('Locales')
62
- }
63
-
64
- if (!environments || environments.length === 0) {
65
- missing.push('Environments')
66
- }
67
-
68
- if (missing.length > 0) {
69
- this.error(`${missing.join(', ')} are required for processing this command. Please check --help for more details`, {exit: 2})
70
- } else {
71
- return true
72
- }
73
- }
74
-
75
- async confirmFlags(flags) {
76
- prettyPrint(flags)
77
- if(flags.yes) {
78
- return true
79
- }
80
- const confirmation = await cli.confirm('Do you want to continue with this configuration ? [yes or no]')
81
- return confirmation
82
- }
83
- }
84
-
85
- AddFieldsCommand.description = `Add fields from updated content types to their respective entries
86
- The add-fields command is used for updating already existing entries with the updated schema of their respective Content Type
87
-
88
- Content Types, Environments and Locales are required for executing the command successfully
89
- But, if retryFailed flag is set, then only a logfile is required
90
- `
91
-
92
- AddFieldsCommand.flags = {
93
- alias: flags.string({char: 'a', description: 'Alias for the management token to be used'}),
94
- retryFailed: flags.string({char: 'r', description: 'Retry publishing failed entries from the logfile (optional, overrides all other flags)'}),
95
- bulkPublish: flags.string({char: 'b', description: 'This flag is set to true by default. It indicates that contentstack\'s bulkpublish API will be used for publishing the entries', default: 'true'}),
96
- contentTypes: flags.string({char: 't', description: 'The Content-Types from which entries need to be published', multiple: true}),
97
- locales: flags.string({char: 'l', description: 'Locales to which entries need to be published', multiple: true}),
98
- environments: flags.string({char: 'e', description: 'Environments to which entries need to be published', multiple: true}),
99
- config: flags.string({char: 'c', description: 'Path to config file to be used'}),
100
- yes: flags.boolean({char: 'y', description: 'Agree to process the command with the current configuration' }),
101
- }
102
-
103
- AddFieldsCommand.examples = [
104
- 'General Usage',
105
- 'csdx cm:bulk-publish:add-fields -t [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] -l [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS]',
106
- '',
107
- 'Using --config or -c flag',
108
- 'Generate a config file at the current working directory using `csdx cm:bulk-publish:configure -a [ALIAS]`',
109
- 'csdx cm:bulk-publish:add-fields --config [PATH TO CONFIG FILE]',
110
- 'csdx cm:bulk-publish:add-fields -c [PATH TO CONFIG FILE]',
111
- '',
112
- 'Using --retryFailed or -r flag',
113
- 'csdx cm:bulk-publish:add-fields --retryFailed [LOG FILE NAME]',
114
- 'csdx cm:bulk-publish:add-fields -r [LOG FILE NAME]'
115
- ]
116
-
117
- module.exports = AddFieldsCommand
@@ -1,117 +0,0 @@
1
- const {Command, flags} = require('@oclif/command')
2
- const {start} = require('../../../producer/publish-assets')
3
- const store = require('../../../util/store.js')
4
- const {cli} = require('cli-ux')
5
- const configKey = 'publish_assets'
6
- const { prettyPrint, formatError } = require('../../../util')
7
- const { getStack } = require('../../../util/client.js')
8
- let config
9
-
10
- class AssetsCommand extends Command {
11
- async run() {
12
- const {flags} = this.parse(AssetsCommand)
13
- let updatedFlags
14
- try {
15
- updatedFlags = (flags.config) ? store.updateMissing(configKey, flags) : flags
16
- } catch(error) {
17
- this.error(error.message, {exit: 2})
18
- }
19
- if (this.validate(updatedFlags)) {
20
- let stack
21
- if (!updatedFlags.retryFailed) {
22
- if(!updatedFlags.alias) {
23
- updatedFlags.alias = await cli.prompt('Please enter the management token alias to be used')
24
- }
25
- updatedFlags.bulkPublish = (updatedFlags.bulkPublish === 'false') ? false : true
26
- if (updatedFlags.folderUid === undefined) {
27
- // set default value for folderUid
28
- updatedFlags.folderUid = 'cs_root'
29
- }
30
- await this.config.runHook('validateManagementTokenAlias', {alias: updatedFlags.alias})
31
- config = {
32
- alias: updatedFlags.alias,
33
- host: this.config.userConfig.getRegion().cma
34
- }
35
- stack = getStack(config)
36
- }
37
- if (await this.confirmFlags(updatedFlags)) {
38
- try {
39
- if (!updatedFlags.retryFailed) {
40
- await start(updatedFlags, stack, config)
41
- } else {
42
- await start(updatedFlags)
43
- }
44
- } catch(error) {
45
- let message = formatError(error)
46
- this.error(message, {exit: 2})
47
- }
48
- } else {
49
- this.exit(0)
50
- }
51
- }
52
- }
53
-
54
- validate({environments, retryFailed, locales}) {
55
- let missing = []
56
- if (retryFailed) {
57
- return true
58
- }
59
-
60
- if (!environments || environments.length === 0) {
61
- missing.push('Environments')
62
- }
63
-
64
- if (!locales || locales.length === 0) {
65
- missing.push('Locales')
66
- }
67
-
68
- if (missing.length > 0) {
69
- this.error(`${missing.join(', ')} are required for processing this command. Please check --help for more details`, {exit: 2})
70
- } else {
71
- return true
72
- }
73
- }
74
-
75
- async confirmFlags(flags) {
76
- prettyPrint(flags)
77
- if(flags.yes) {
78
- return true
79
- }
80
- const confirmation = await cli.confirm('Do you want to continue with this configuration ? [yes or no]')
81
- return confirmation
82
- }
83
- }
84
-
85
- AssetsCommand.description = `Publish assets to specified environments
86
- The assets command is used for publishing assets from the specified stack, to the specified environments
87
-
88
- Environment(s) and Locale(s) are required for executing the command successfully
89
- But, if retryFailed flag is set, then only a logfile is required
90
- `
91
-
92
- AssetsCommand.flags = {
93
- alias: flags.string({char: 'a', description: 'Alias for the management token to be used'}),
94
- retryFailed: flags.string({char: 'r', description: 'Retry publishing failed assets from the logfile (optional, will override all other flags)'}),
95
- environments: flags.string({char: 'e', description: 'Environments to which assets need to be published', multiple: true}),
96
- folderUid: flags.string({char: 'u', description: '[default: cs_root] Folder-uid from which the assets need to be published'}),
97
- bulkPublish: flags.string({char: 'b', description: 'This flag is set to true by default. It indicates that contentstack\'s bulkpublish API will be used for publishing the entries', default: 'true'}),
98
- config: flags.string({char: 'c', description: 'Path to config file to be used'}),
99
- yes: flags.boolean({char: 'y', description: 'Agree to process the command with the current configuration' }),
100
- locales: flags.string({char: 'l', description: 'Locales to which assets need to be published', multiple: true }),
101
- }
102
-
103
- AssetsCommand.examples = [
104
- 'General Usage',
105
- 'csdx cm:bulk-publish:assets -e [ENVIRONMENT 1] [ENVIRONMENT 2] -l [LOCALE] -a [MANAGEMENT TOKEN ALIAS]',
106
- '',
107
- 'Using --config or -c flag',
108
- 'Generate a config file at the current working directory using `csdx cm:bulk-publish:configure -a [ALIAS]`',
109
- 'csdx cm:bulk-publish:assets --config [PATH TO CONFIG FILE]',
110
- 'csdx cm:bulk-publish:assets -c [PATH TO CONFIG FILE]',
111
- '',
112
- 'Using --retryFailed or -r flag',
113
- 'csdx cm:bulk-publish:assets --retryFailed [LOG FILE NAME]',
114
- 'csdx cm:bulk-publish:assets -r [LOG FILE NAME]'
115
- ]
116
-
117
- module.exports = AssetsCommand
@@ -1,63 +0,0 @@
1
- const fs = require('fs')
2
- const {cli} = require('cli-ux')
3
- const {Command, flags} = require('@oclif/command')
4
- const {getLogsDirPath} = require('../../../util/logger.js')
5
-
6
- class ClearCommand extends Command {
7
- async run() {
8
- const {flags} = this.parse(ClearCommand)
9
- let dirPath = getLogsDirPath()
10
- if (flags.list) {
11
- this.listFiles(dirPath)
12
- } else if (flags.yes) {
13
- this.rmDir(dirPath, false)
14
- } else {
15
- const confirmation = await cli.prompt('Proceed to delete all log files (y/n)?')
16
- if (confirmation) {
17
- this.rmDir(dirPath, false)
18
- }
19
- }
20
- }
21
-
22
- rmDir(dirPath, removeSelf) {
23
- if (fs.existsSync(dirPath)) {
24
- if (removeSelf === undefined)
25
- removeSelf = true;
26
- try { var files = fs.readdirSync(dirPath); }
27
- catch(e) { return; }
28
- if (files.length > 0)
29
- for (var i = 0; i < files.length; i++) {
30
- var filePath = dirPath + '/' + files[i];
31
- if (fs.statSync(filePath).isFile())
32
- fs.unlinkSync(filePath);
33
- else
34
- rmDir(filePath);
35
- }
36
- if (removeSelf)
37
- fs.rmdirSync(dirPath);
38
- this.log('Log files have been cleared')
39
- } else {
40
- this.error(`The log directory doesn't exist.`)
41
- }
42
- };
43
-
44
- listFiles(dirPath) {
45
- if (fs.existsSync(dirPath)) {
46
- fs.readdir(dirPath, (err, files) => {
47
- this.log(files.length)
48
- })
49
- } else {
50
- this.error(`The log directory doesn't exist.`)
51
- }
52
- }
53
- }
54
-
55
- ClearCommand.description = `Clear the log folder
56
- `
57
-
58
- ClearCommand.flags = {
59
- list: flags.boolean({char: 'l', description: 'List number of log files'}),
60
- yes: flags.boolean({char: 'y', description: 'Delete all files without asking for confirmation'})
61
- }
62
-
63
- module.exports = ClearCommand