@contentstack/cli-cm-bulk-publish 0.1.1-beta.1 → 0.1.1-beta.4

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.
@@ -5,11 +5,11 @@ const {getLogsDirPath} = require('../../../util/logger.js')
5
5
 
6
6
  class ClearCommand extends Command {
7
7
  async run() {
8
- const {flags} = this.parse(ClearCommand)
8
+ const clearFlags = this.parse(ClearCommand).flags
9
9
  let dirPath = getLogsDirPath()
10
- if (flags.list) {
10
+ if (clearFlags.list) {
11
11
  this.listFiles(dirPath)
12
- } else if (flags.yes) {
12
+ } else if (clearFlags.yes) {
13
13
  this.rmDir(dirPath, false)
14
14
  } else {
15
15
  const confirmation = await cli.prompt('Proceed to delete all log files (y/n)?')
@@ -21,8 +21,9 @@ class ClearCommand extends Command {
21
21
 
22
22
  rmDir(dirPath, removeSelf) {
23
23
  if (fs.existsSync(dirPath)) {
24
- if (removeSelf === undefined)
24
+ if (removeSelf === undefined) {
25
25
  removeSelf = true;
26
+ }
26
27
  try { var files = fs.readdirSync(dirPath); }
27
28
  catch(e) { return; }
28
29
  if (files.length > 0)
@@ -33,13 +34,14 @@ class ClearCommand extends Command {
33
34
  else
34
35
  rmDir(filePath);
35
36
  }
36
- if (removeSelf)
37
+ if (removeSelf) {
37
38
  fs.rmdirSync(dirPath);
39
+ }
38
40
  this.log('Log files have been cleared')
39
41
  } else {
40
42
  this.error(`The log directory doesn't exist.`)
41
43
  }
42
- };
44
+ }
43
45
 
44
46
  listFiles(dirPath) {
45
47
  if (fs.existsSync(dirPath)) {
@@ -2,21 +2,19 @@ const {Command, flags} = require('@oclif/command')
2
2
  const {cli} = require('cli-ux')
3
3
  const fs = require('fs')
4
4
  const path = require('path')
5
- const defaults = require('../../../config/defaults.json')
6
- const store = require('../../../util/store.js')
7
5
  let config = require('../../../config/index.js')
8
6
 
9
7
  class ConfigureCommand extends Command {
10
8
 
11
9
  async run() {
12
- const {flags} = this.parse(ConfigureCommand)
10
+ const configureFlags = this.parse(ConfigureCommand).flags
13
11
 
14
- if (!flags.alias) {
15
- flags.alias = await cli.prompt('Please enter the management token alias to be used')
12
+ if (!configureFlags.alias) {
13
+ configureFlags.alias = await cli.prompt('Please enter the management token alias to be used')
16
14
  }
17
15
 
18
- await this.config.runHook('validateManagementTokenAlias', {alias: flags.alias})
19
- this.setConfig(flags)
16
+ await this.config.runHook('validateManagementTokenAlias', {alias: configureFlags.alias})
17
+ this.setConfig(configureFlags)
20
18
  this.log('The configuration has been saved successfully.')
21
19
  }
22
20
 
@@ -10,10 +10,10 @@ let config
10
10
 
11
11
  class CrossPublishCommand extends Command {
12
12
  async run() {
13
- const {flags} = this.parse(CrossPublishCommand)
13
+ const crossPublishFlags = this.parse(CrossPublishCommand).flags
14
14
  let updatedFlags
15
15
  try {
16
- updatedFlags = (flags.config) ? store.updateMissing(configKey, flags) : flags
16
+ updatedFlags = (crossPublishFlags.config) ? store.updateMissing(configKey, crossPublishFlags) : crossPublishFlags
17
17
  } catch(error) {
18
18
  this.error(error.message, {exit: 2})
19
19
  }
@@ -29,10 +29,11 @@ class CrossPublishCommand extends Command {
29
29
  }
30
30
  updatedFlags.bulkPublish = (updatedFlags.bulkPublish === 'false') ? false : true
31
31
  await this.config.runHook('validateManagementTokenAlias', {alias: updatedFlags.alias})
32
- config = {
32
+ config = {
33
33
  alias: updatedFlags.alias,
34
34
  host: this.config.userConfig.getRegion().cma,
35
35
  cda: this.config.userConfig.getRegion().cda,
36
+ branch: crossPublishFlags.branch,
36
37
  }
37
38
  stack = getStack(config)
38
39
  }
@@ -42,19 +43,6 @@ class CrossPublishCommand extends Command {
42
43
  }
43
44
 
44
45
  if (await this.confirmFlags(updatedFlags)) {
45
- updatedFlags.filter = {}
46
- updatedFlags.filter.locale = updatedFlags.locale
47
- delete updatedFlags.locale
48
-
49
- if (updatedFlags.contentType && updatedFlags.contentType.length > 0) {
50
- updatedFlags.filter.content_type_uid = updatedFlags.contentType
51
- delete updatedFlags.contentType
52
- }
53
-
54
- if (updatedFlags.environment && updatedFlags.environment.length > 0) {
55
- updatedFlags.filter.environment = updatedFlags.environment
56
- delete updatedFlags.environment
57
- }
58
46
  try {
59
47
  if (!updatedFlags.retryFailed) {
60
48
  await start(updatedFlags, stack, config)
@@ -71,12 +59,20 @@ class CrossPublishCommand extends Command {
71
59
  }
72
60
  }
73
61
 
74
- validate({environment, retryFailed, contentType, destEnv, locale}) {
62
+ validate({environment, retryFailed, destEnv, onlyAssets, contentType, onlyEntries, locale}) {
75
63
  let missing = []
76
64
  if (retryFailed) {
77
65
  return true
78
66
  }
79
67
 
68
+ if (onlyAssets && onlyEntries) {
69
+ this.error(`The flags onlyAssets and onlyEntries need not be used at the same time. Unpublish command unpublishes entries and assts at the same time by default`)
70
+ }
71
+
72
+ if (onlyAssets && contentType) {
73
+ this.error(`Specifying content-type and onlyAssets together will have unexpected results. Please do not use these 2 flags together. Thank you.`)
74
+ }
75
+
80
76
  if (!environment) {
81
77
  missing.push('Environment')
82
78
  }
@@ -85,10 +81,6 @@ class CrossPublishCommand extends Command {
85
81
  missing.push('Destination Environment')
86
82
  }
87
83
 
88
- if (!contentType) {
89
- missing.push('ContentType')
90
- }
91
-
92
84
  if (!locale) {
93
85
  missing.push('Locale')
94
86
  }
@@ -100,9 +92,9 @@ class CrossPublishCommand extends Command {
100
92
  }
101
93
  }
102
94
 
103
- async confirmFlags(flags) {
104
- prettyPrint(flags)
105
- if(flags.yes) {
95
+ async confirmFlags(data) {
96
+ prettyPrint(data)
97
+ if (data.yes) {
106
98
  return true
107
99
  }
108
100
  const confirmation = await cli.confirm('Do you want to continue with this configuration ? [yes or no]')
@@ -127,7 +119,10 @@ CrossPublishCommand.flags = {
127
119
  deliveryToken: flags.string({char: 'x', description: 'Delivery Token for source environment'}),
128
120
  destEnv: flags.string({char: 'd', description: 'Destination Environments', multiple: true}),
129
121
  config: flags.string({char: 'c', description: 'Path to config file to be used'}),
130
- yes: flags.boolean({char: 'y', description: 'Agree to process the command with the current configuration' }),
122
+ yes: flags.boolean({char: 'y', description: 'Agree to process the command with the current configuration'}),
123
+ branch: flags.string({char: 'B', default: 'main', description: 'Specify the branch to fetch the content from (default is main branch)'}),
124
+ onlyAssets: flags.boolean({description: 'Unpublish only assets', default: false}),
125
+ onlyEntries: flags.boolean({description: 'Unpublish only entries', default: false}),
131
126
  }
132
127
 
133
128
  CrossPublishCommand.examples = [
@@ -141,7 +136,10 @@ CrossPublishCommand.examples = [
141
136
  '',
142
137
  'Using --retryFailed or -r flag',
143
138
  'csdx cm:bulk-publish:cross-publish --retryFailed [LOG FILE NAME]',
144
- 'csdx cm:bulk-publish:cross-publish -r [LOG FILE NAME]'
139
+ 'csdx cm:bulk-publish:cross-publish -r [LOG FILE NAME]',
140
+ '',
141
+ 'Using --branch or -B flag',
142
+ 'csdx cm:bulk-publish:cross-publish -t [CONTENT TYPE] -e [SOURCE ENV] -d [DESTINATION ENVIRONMENT] -l [LOCALE] -a [MANAGEMENT TOKEN ALIAS] -x [DELIVERY TOKEN] -B [BRANCH NAME]',
145
143
  ]
146
144
 
147
145
  module.exports = CrossPublishCommand
@@ -5,41 +5,43 @@ const {start} = require('../../../producer/publish-entries')
5
5
  const store = require('../../../util/store.js')
6
6
  const {cli} = require('cli-ux')
7
7
  const configKey = 'publish_entries'
8
- const { prettyPrint, formatError } = require('../../../util')
9
- const { getStack } = require('../../../util/client.js')
8
+ const {prettyPrint, formatError} = require('../../../util')
9
+ const {getStack} = require('../../../util/client.js')
10
10
  let config
11
11
 
12
12
  class EntriesCommand extends Command {
13
13
  async run() {
14
- const {flags} = this.parse(EntriesCommand)
14
+ const entriesFlags = this.parse(EntriesCommand).flags
15
15
  let updatedFlags
16
16
  try {
17
- updatedFlags = (flags.config) ? store.updateMissing(configKey, flags) : flags
18
- } catch(error) {
17
+ updatedFlags = (entriesFlags.config) ? store.updateMissing(configKey, entriesFlags) : entriesFlags
18
+ } catch (error) {
19
19
  this.error(error.message, {exit: 2})
20
20
  }
21
21
  if (this.validate(updatedFlags)) {
22
22
  let stack
23
23
  if (!updatedFlags.retryFailed) {
24
- if(!updatedFlags.alias) {
24
+ if (!updatedFlags.alias) {
25
25
  updatedFlags.alias = await cli.prompt('Provide the alias of the management token to use')
26
26
  }
27
- updatedFlags.bulkPublish = (updatedFlags.bulkPublish === 'false') ? false : true
27
+ updatedFlags.bulkPublish = updatedFlags.bulkPublish !== 'false'
28
28
  await this.config.runHook('validateManagementTokenAlias', {alias: updatedFlags.alias})
29
29
  config = {
30
30
  alias: updatedFlags.alias,
31
- host: this.config.userConfig.getRegion().cma
31
+ host: this.config.userConfig.getRegion().cma,
32
+ branch: entriesFlags.branch,
32
33
  }
33
34
  stack = getStack(config)
34
35
  }
35
36
  if (await this.confirmFlags(updatedFlags)) {
36
37
  try {
38
+ // eslint-disable-next-line no-negated-condition
37
39
  if (!updatedFlags.retryFailed) {
38
40
  await start(updatedFlags, stack, config)
39
41
  } else {
40
42
  await start(updatedFlags)
41
43
  }
42
- } catch(error) {
44
+ } catch (error) {
43
45
  let message = formatError(error)
44
46
  this.error(message, {exit: 2})
45
47
  }
@@ -49,7 +51,7 @@ class EntriesCommand extends Command {
49
51
  }
50
52
  }
51
53
 
52
- validate({contentTypes, locales, environments, retryFailed, publishAllContentTypes }) {
54
+ validate({contentTypes, locales, environments, retryFailed, publishAllContentTypes}) {
53
55
  let missing = []
54
56
  if (retryFailed) {
55
57
  return true
@@ -78,13 +80,13 @@ class EntriesCommand extends Command {
78
80
  }
79
81
  }
80
82
 
81
- async confirmFlags(flags) {
82
- prettyPrint(flags)
83
- if(flags.yes) {
84
- return true
85
- }
86
- const confirmation = await cli.confirm('Do you want to continue with this configuration ? [yes or no]')
87
- return confirmation
83
+ async confirmFlags(data) {
84
+ prettyPrint(data)
85
+ if (data.yes) {
86
+ return true
87
+ }
88
+ const confirmation = await cli.confirm('Do you want to continue with this configuration ? [yes or no]')
89
+ return confirmation
88
90
  }
89
91
  }
90
92
 
@@ -102,10 +104,11 @@ EntriesCommand.flags = {
102
104
  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'}),
103
105
  publishAllContentTypes: flags.boolean({char: 'o', description: 'Publish all content-types (optional, cannot be set when contentTypes flag is set)'}),
104
106
  contentTypes: flags.string({char: 't', description: 'The Content-types from which entries need to be published', multiple: true}),
105
- locales: flags.string({char: 'l', description: 'Locales to which entries need to be published', multiple: true }),
107
+ locales: flags.string({char: 'l', description: 'Locales to which entries need to be published', multiple: true}),
106
108
  environments: flags.string({char: 'e', description: 'Environments to which entries need to be published', multiple: true}),
107
109
  config: flags.string({char: 'c', description: 'Path for the external config file to be used (A new config file can be generated at the current working directory using `csdx cm:bulk-publish:configure -a [ALIAS]`)'}),
108
110
  yes: flags.boolean({char: 'y', description: 'Agree to process the command with the current configuration'}),
111
+ branch: flags.string({char: 'B', default: 'main', description: 'Specify the branch to fetch the content from (default is main branch)'}),
109
112
  }
110
113
 
111
114
  EntriesCommand.examples = [
@@ -119,7 +122,10 @@ EntriesCommand.examples = [
119
122
  '',
120
123
  'Using --retryFailed or -r flag',
121
124
  'csdx cm:bulk-publish:entries --retryFailed [LOG FILE NAME]',
122
- 'csdx cm:bulk-publish:entries -r [LOG FILE NAME]'
125
+ 'csdx cm:bulk-publish:entries -r [LOG FILE NAME]',
126
+ '',
127
+ 'Using --branch or -B flag',
128
+ 'csdx cm:bulk-publish:entries -t [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] -l [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] -B [BRANCH NAME]',
123
129
  ]
124
130
 
125
- module.exports = EntriesCommand
131
+ module.exports = EntriesCommand
@@ -1,43 +1,45 @@
1
1
  const {Command, flags} = require('@oclif/command')
2
2
  const {start} = require('../../../producer/publish-edits')
3
3
  const store = require('../../../util/store.js')
4
+ // eslint-disable-next-line node/no-extraneous-require
4
5
  const {cli} = require('cli-ux')
5
6
  const configKey = 'publish_edits_on_env'
6
- const { prettyPrint, formatError } = require('../../../util')
7
- const { getStack } = require('../../../util/client.js')
7
+ const {prettyPrint, formatError} = require('../../../util')
8
+ const {getStack} = require('../../../util/client.js')
8
9
  let config
9
10
 
10
11
  class EntryEditsCommand extends Command {
11
12
  async run() {
12
- const {flags} = this.parse(EntryEditsCommand)
13
+ const entryEditsFlags = this.parse(EntryEditsCommand).flags
13
14
  let updatedFlags
14
15
  try {
15
- updatedFlags = (flags.config) ? store.updateMissing(configKey, flags) : flags
16
- } catch(error) {
16
+ updatedFlags = (entryEditsFlags.config) ? store.updateMissing(configKey, entryEditsFlags) : entryEditsFlags
17
+ } catch (error) {
17
18
  this.error(error.message, {exit: 2})
18
19
  }
19
20
  if (this.validate(updatedFlags)) {
20
21
  let stack
21
- if (!updatedFlags.retryFailed) {
22
- if(!updatedFlags.alias) {
22
+ if (!updatedFlags.retryFailed) {
23
+ if (!updatedFlags.alias) {
23
24
  updatedFlags.alias = await cli.prompt('Please enter the management token alias to be used')
24
25
  }
25
- updatedFlags.bulkPublish = (updatedFlags.bulkPublish === 'false') ? false : true
26
+ updatedFlags.bulkPublish = updatedFlags.bulkPublish !== 'false'
26
27
  await this.config.runHook('validateManagementTokenAlias', {alias: updatedFlags.alias})
27
- config = {
28
+ config = {
28
29
  alias: updatedFlags.alias,
29
- host: this.config.userConfig.getRegion().cma
30
+ host: this.config.userConfig.getRegion().cma,
31
+ branch: entryEditsFlags.branch,
30
32
  }
31
33
  stack = getStack(config)
32
34
  }
33
- if(await this.confirmFlags(updatedFlags)) {
35
+ if (await this.confirmFlags(updatedFlags)) {
34
36
  try {
35
37
  if (!updatedFlags.retryFailed) {
36
38
  await start(updatedFlags, stack, config)
37
39
  } else {
38
40
  await start(updatedFlags)
39
41
  }
40
- } catch(error) {
42
+ } catch (error) {
41
43
  let message = formatError(error)
42
44
  this.error(message, {exit: 2})
43
45
  }
@@ -76,9 +78,9 @@ class EntryEditsCommand extends Command {
76
78
  }
77
79
  }
78
80
 
79
- async confirmFlags(flags) {
80
- prettyPrint(flags)
81
- if(flags.yes) {
81
+ async confirmFlags(data) {
82
+ prettyPrint(data)
83
+ if (data.yes) {
82
84
  return true
83
85
  }
84
86
  const confirmation = await cli.confirm('Do you want to continue with this configuration ? [yes or no]')
@@ -103,7 +105,8 @@ EntryEditsCommand.flags = {
103
105
  locales: flags.string({char: 'l', description: 'Locales to which edited entries need to be published', multiple: true}),
104
106
  environments: flags.string({char: 'e', description: 'Destination environments', multiple: true}),
105
107
  config: flags.string({char: 'c', description: 'Path to config file to be used'}),
106
- yes: flags.boolean({char: 'y', description: 'Agree to process the command with the current configuration' }),
108
+ yes: flags.boolean({char: 'y', description: 'Agree to process the command with the current configuration'}),
109
+ branch: flags.string({char: 'B', default: 'main', description: 'Specify the branch to fetch the content from (default is main branch)'}),
107
110
  }
108
111
 
109
112
  EntryEditsCommand.examples = [
@@ -117,7 +120,10 @@ EntryEditsCommand.examples = [
117
120
  '',
118
121
  'Using --retryFailed or -r flag',
119
122
  'csdx cm:bulk-publish:entry-edits --retryFailed [LOG FILE NAME]',
120
- 'csdx cm:bulk-publish:entry-edits -r [LOG FILE NAME]'
123
+ 'csdx cm:bulk-publish:entry-edits -r [LOG FILE NAME]',
124
+ '',
125
+ 'Using --branch or -B flag',
126
+ 'csdx cm:bulk-publish:entry-edits -t [CONTENT TYPE 1] [CONTENT TYPE 2] -s [SOURCE_ENV] -e [ENVIRONMENT 1] [ENVIRONMENT 2] -l [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] -B [BRANCH NAME]',
121
127
  ]
122
128
 
123
129
  module.exports = EntryEditsCommand
@@ -9,10 +9,10 @@ let config
9
9
 
10
10
  class NonlocalizedFieldChangesCommand extends Command {
11
11
  async run() {
12
- const {flags} = this.parse(NonlocalizedFieldChangesCommand)
12
+ const nonlocalizedFieldChangesFlags = this.parse(NonlocalizedFieldChangesCommand).flags
13
13
  let updatedFlags
14
14
  try {
15
- updatedFlags = (flags.config) ? store.updateMissing(configKey, flags) : flags
15
+ updatedFlags = (nonlocalizedFieldChangesFlags.config) ? store.updateMissing(configKey, nonlocalizedFieldChangesFlags) : nonlocalizedFieldChangesFlags
16
16
  } catch(error) {
17
17
  this.error(error.message, {exit: 2})
18
18
  }
@@ -24,7 +24,8 @@ class NonlocalizedFieldChangesCommand extends Command {
24
24
  await this.config.runHook('validateManagementTokenAlias', {alias: updatedFlags.alias})
25
25
  config = {
26
26
  alias: updatedFlags.alias,
27
- host: this.config.userConfig.getRegion().cma
27
+ host: this.config.userConfig.getRegion().cma,
28
+ branch: nonlocalizedFieldChangesFlags.branch,
28
29
  }
29
30
  stack = getStack(config)
30
31
  }
@@ -70,9 +71,9 @@ class NonlocalizedFieldChangesCommand extends Command {
70
71
  }
71
72
  }
72
73
 
73
- async confirmFlags(flags) {
74
- prettyPrint(flags)
75
- if(flags.yes) {
74
+ async confirmFlags(data) {
75
+ prettyPrint(data)
76
+ if(data.yes) {
76
77
  return true
77
78
  }
78
79
  const confirmation = await cli.confirm('Do you want to continue with this configuration ? [yes or no]')
@@ -96,12 +97,13 @@ NonlocalizedFieldChangesCommand.flags = {
96
97
  contentTypes: flags.string({char: 't', description: 'The Content-Types from which entries need to be published', multiple: true}),
97
98
  environments: flags.string({char: 'e', description: 'Destination environments', multiple: true}),
98
99
  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
+ yes: flags.boolean({char: 'y', description: 'Agree to process the command with the current configuration'}),
101
+ branch: flags.string({char: 'B', default: 'main', description: 'Specify the branch to fetch the content from (default is main branch)'}),
100
102
  }
101
103
 
102
104
  NonlocalizedFieldChangesCommand.examples = [
103
105
  'General Usage',
104
- 'csdx cm:bulk-publish:nonlocalized-field-changes -t [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] -l [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS]',
106
+ 'csdx cm:bulk-publish:nonlocalized-field-changes -t [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] -l [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] -s [SOURCE ENV]',
105
107
  '',
106
108
  'Using --config or -c flag',
107
109
  'Generate a config file at the current working directory using `csdx cm:bulk-publish:configure -a [ALIAS]`',
@@ -110,7 +112,10 @@ NonlocalizedFieldChangesCommand.examples = [
110
112
  '',
111
113
  'Using --retryFailed or -r flag',
112
114
  'csdx cm:bulk-publish:nonlocalized-field-changes --retryFailed [LOG FILE NAME]',
113
- 'csdx cm:bulk-publish:nonlocalized-field-changes -r [LOG FILE NAME]'
115
+ 'csdx cm:bulk-publish:nonlocalized-field-changes -r [LOG FILE NAME]',
116
+ '',
117
+ 'Using --branch or -B flag',
118
+ 'csdx cm:bulk-publish:nonlocalized-field-changes -t [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] -l [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] -B [BRANCH NAME] -s [SOURCE ENV]',
114
119
  ]
115
120
 
116
121
  module.exports = NonlocalizedFieldChangesCommand
@@ -10,10 +10,10 @@ let config
10
10
 
11
11
  class RevertCommand extends Command {
12
12
  async run() {
13
- const {flags} = this.parse(RevertCommand)
13
+ const revertFlags = this.parse(RevertCommand).flags
14
14
  let updatedFlags
15
15
  try {
16
- updatedFlags = (flags.config) ? store.updateMissing(configKey, flags) : flags
16
+ updatedFlags = (revertFlags.config) ? store.updateMissing(configKey, revertFlags) : revertFlags
17
17
  } catch(error) {
18
18
  this.error(error.message, {exit: 2})
19
19
  }
@@ -48,9 +48,9 @@ class RevertCommand extends Command {
48
48
  }
49
49
  }
50
50
 
51
- async confirmFlags(flags) {
52
- prettyPrint(flags)
53
- if(flags.yes) {
51
+ async confirmFlags(data) {
52
+ prettyPrint(data)
53
+ if(data.yes) {
54
54
  return true
55
55
  }
56
56
  const confirmation = await cli.confirm('Do you want to continue with this configuration ? [yes or no]')
@@ -11,11 +11,11 @@ let config
11
11
 
12
12
  class UnpublishCommand extends Command {
13
13
  async run() {
14
- const {flags} = this.parse(UnpublishCommand)
14
+ const unpublishFlags = this.parse(UnpublishCommand).flags
15
15
  let updatedFlags
16
16
  try {
17
- updatedFlags = (flags.config) ? store.updateMissing(configKey, flags) : flags
18
- } catch(error) {
17
+ updatedFlags = (unpublishFlags.config) ? store.updateMissing(configKey, unpublishFlags) : unpublishFlags
18
+ } catch (error) {
19
19
  this.error(error.message, {exit: 2})
20
20
  }
21
21
 
@@ -30,10 +30,11 @@ class UnpublishCommand extends Command {
30
30
  }
31
31
  updatedFlags.bulkUnpublish = (updatedFlags.bulkUnpublish === 'false') ? false : true
32
32
  await this.config.runHook('validateManagementTokenAlias', {alias: updatedFlags.alias})
33
- config = {
33
+ config = {
34
34
  alias: updatedFlags.alias,
35
35
  host: this.config.userConfig.getRegion().cma,
36
36
  cda: this.config.userConfig.getRegion().cda,
37
+ branch: unpublishFlags.branch,
37
38
  }
38
39
  stack = getStack(config)
39
40
  }
@@ -48,7 +49,7 @@ class UnpublishCommand extends Command {
48
49
  } else {
49
50
  await start(updatedFlags)
50
51
  }
51
- } catch(error) {
52
+ } catch (error) {
52
53
  let message = formatError(error)
53
54
  this.error(message, {exit: 2})
54
55
  }
@@ -58,7 +59,7 @@ class UnpublishCommand extends Command {
58
59
  }
59
60
  }
60
61
 
61
- validate({environment, retryFailed, locale, onlyAssets, onlyEntries}) {
62
+ validate({environment, retryFailed, locale, contentType, onlyAssets, onlyEntries}) {
62
63
  let missing = []
63
64
  if (retryFailed) {
64
65
  return true
@@ -68,6 +69,10 @@ class UnpublishCommand extends Command {
68
69
  this.error(`The flags onlyAssets and onlyEntries need not be used at the same time. Unpublish command unpublishes entries and assts at the same time by default`)
69
70
  }
70
71
 
72
+ if (onlyAssets && contentType) {
73
+ this.error(`Specifying content-type and onlyAssets together will have unexpected results. Please do not use these 2 flags together. Thank you.`)
74
+ }
75
+
71
76
  if (!environment) {
72
77
  missing.push('Environment')
73
78
  }
@@ -90,19 +95,19 @@ class UnpublishCommand extends Command {
90
95
  }
91
96
  }
92
97
 
93
- async confirmFlags(flags) {
98
+ async confirmFlags(data) {
94
99
  let confirmation
95
- prettyPrint(flags)
96
- if(flags.yes) {
97
- return true
98
- }
100
+ prettyPrint(data)
101
+ if (data.yes) {
102
+ return true
103
+ }
99
104
 
100
- if(!flags.contentType && !flags.onlyAssets) {
105
+ if (!data.contentType && !data.onlyAssets) {
101
106
  confirmation = await cli.confirm('Do you want to continue with this configuration. This will unpublish all the entries from all content types? [yes or no]')
102
107
  } else {
103
- confirmation = await cli.confirm('Do you want to continue with this configuration ? [yes or no]')
108
+ confirmation = await cli.confirm('Do you want to continue with this configuration ? [yes or no]')
104
109
  }
105
- return confirmation
110
+ return confirmation
106
111
  }
107
112
  }
108
113
 
@@ -131,6 +136,7 @@ UnpublishCommand.flags = {
131
136
  yes: flags.boolean({char: 'y', description: 'Agree to process the command with the current configuration'}),
132
137
  onlyAssets: flags.boolean({description: 'Unpublish only assets', default: false}),
133
138
  onlyEntries: flags.boolean({description: 'Unpublish only entries', default: false}),
139
+ branch: flags.string({char: 'B', default: 'main', description: 'Specify the branch to fetch the content from (default is main branch)'}),
134
140
  }
135
141
 
136
142
  UnpublishCommand.examples = [
@@ -155,6 +161,9 @@ UnpublishCommand.examples = [
155
161
  'Using --onlyEntries',
156
162
  'csdx cm:bulk-publish:unpublish --environment [SOURCE ENV] --locale [LOCALE] --onlyEntries (Will unpublish only entries, all entries, from the source environment)',
157
163
  'csdx cm:bulk-publish:unpublish --contentType [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --onlyEntries (Will unpublish only entries, (from CONTENT TYPE) from the source environment)',
164
+ '',
165
+ 'Using --branch or -B flag',
166
+ 'csdx cm:bulk-publish:unpublish -b -t [CONTENT TYPE] -e [SOURCE ENV] -l [LOCALE] -a [MANAGEMENT TOKEN ALIAS] -x [DELIVERY TOKEN] -B [BRANCH NAME]',
158
167
  ]
159
168
 
160
- module.exports = UnpublishCommand
169
+ module.exports = UnpublishCommand
@@ -9,24 +9,25 @@ let config
9
9
 
10
10
  class UnpublishedEntriesCommand extends Command {
11
11
  async run() {
12
- const {flags} = this.parse(UnpublishedEntriesCommand)
12
+ const unpublishedEntriesFlags = this.parse(UnpublishedEntriesCommand).flags
13
13
  let updatedFlags
14
14
  try {
15
- updatedFlags = (flags.config) ? store.updateMissing(configKey, flags) : flags
16
- } catch(error) {
15
+ updatedFlags = (unpublishedEntriesFlags.config) ? store.updateMissing(configKey, unpublishedEntriesFlags) : unpublishedEntriesFlags
16
+ } catch (error) {
17
17
  this.error(error.message, {exit: 2})
18
18
  }
19
19
  if (this.validate(updatedFlags)) {
20
20
  let stack
21
21
  if (!updatedFlags.retryFailed) {
22
- if(!updatedFlags.alias) {
22
+ if (!updatedFlags.alias) {
23
23
  updatedFlags.alias = await cli.prompt('Please enter the management token alias to be used')
24
24
  }
25
25
  updatedFlags.bulkPublish = (updatedFlags.bulkPublish === 'false') ? false : true
26
26
  await this.config.runHook('validateManagementTokenAlias', {alias: updatedFlags.alias})
27
- config = {
27
+ config = {
28
28
  alias: updatedFlags.alias,
29
- host: this.config.userConfig.getRegion().cma
29
+ host: this.config.userConfig.getRegion().cma,
30
+ branch: unpublishedEntriesFlags.branch,
30
31
  }
31
32
  stack = getStack(config)
32
33
  }
@@ -76,9 +77,9 @@ class UnpublishedEntriesCommand extends Command {
76
77
  }
77
78
  }
78
79
 
79
- async confirmFlags(flags) {
80
- prettyPrint(flags)
81
- if(flags.yes) {
80
+ async confirmFlags(data) {
81
+ prettyPrint(data)
82
+ if(data.yes) {
82
83
  return true
83
84
  }
84
85
  const confirmation = await cli.confirm('Do you want to continue with this configuration ? [yes or no]')
@@ -102,12 +103,13 @@ UnpublishedEntriesCommand.flags = {
102
103
  locale: flags.string({char: 'l', description: 'Source locale'}),
103
104
  environments: flags.string({char: 'e', description: 'Destination environments', multiple: true}),
104
105
  config: flags.string({char: 'c', description: 'Path to config file to be used'}),
105
- yes: flags.boolean({char: 'y', description: 'Agree to process the command with the current configuration' }),
106
+ yes: flags.boolean({char: 'y', description: 'Agree to process the command with the current configuration'}),
107
+ branch: flags.string({char: 'B', default: 'main', description: 'Specify the branch to fetch the content from (default is main branch)'}),
106
108
  }
107
109
 
108
110
  UnpublishedEntriesCommand.examples = [
109
111
  'General Usage',
110
- 'csdx cm:bulk-publish:unpublished-entries -b -t [CONTENT TYPES] -e [ENVIRONMENTS] -l LOCALE -a [MANAGEMENT TOKEN ALIAS]',
112
+ 'csdx cm:bulk-publish:unpublished-entries -b -t [CONTENT TYPES] -e [ENVIRONMENTS] -l LOCALE -a [MANAGEMENT TOKEN ALIAS] -s [SOURCE ENV]',
111
113
  '',
112
114
  'Using --config or -c flag',
113
115
  'Generate a config file at the current working directory using `csdx cm:bulk-publish:configure -a [ALIAS]`',
@@ -116,7 +118,10 @@ UnpublishedEntriesCommand.examples = [
116
118
  '',
117
119
  'Using --retryFailed or -r flag',
118
120
  'csdx cm:bulk-publish:unpublished-entries --retryFailed [LOG FILE NAME]',
119
- 'csdx cm:bulk-publish:unpublished-entries -r [LOG FILE NAME]'
121
+ 'csdx cm:bulk-publish:unpublished-entries -r [LOG FILE NAME]',
122
+ '',
123
+ 'Using --branch or -B flag',
124
+ 'csdx cm:bulk-publish:unpublished-entries -b -t [CONTENT TYPES] -e [ENVIRONMENTS] -l LOCALE -a [MANAGEMENT TOKEN ALIAS] -B [BRANCH NAME] -s [SOURCE ENV]',
120
125
  ]
121
126
 
122
127
  module.exports = UnpublishedEntriesCommand