@contentstack/cli-cm-bulk-publish 0.1.1-beta.5 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +522 -318
- package/oclif.manifest.json +1 -1
- package/package.json +26 -11
- package/src/commands/cm/assets/publish.js +243 -0
- package/src/commands/cm/assets/unpublish.js +179 -0
- package/src/commands/cm/bulk-publish/cross-publish.js +181 -67
- package/src/commands/cm/bulk-publish/index.js +5 -6
- package/src/commands/cm/entries/publish-modified.js +197 -0
- package/src/commands/cm/entries/publish-non-localized-fields.js +208 -0
- package/src/commands/cm/entries/publish-only-unpublished.js +109 -0
- package/src/commands/cm/entries/publish.js +254 -0
- package/src/commands/cm/entries/unpublish.js +184 -0
- package/src/commands/cm/entries/update-and-publish.js +191 -0
- package/src/commands/cm/stacks/publish-clear-logs.js +82 -0
- package/src/commands/cm/stacks/publish-configure.js +46 -0
- package/src/commands/cm/stacks/publish-revert.js +102 -0
- package/src/commands/cm/stacks/publish.js +110 -0
- package/src/commands/cm/stacks/unpublish.js +282 -0
- package/src/config/index.js +18 -57
- package/src/consumer/publish.js +589 -362
- package/src/producer/add-fields.js +204 -179
- package/src/producer/cross-publish.js +177 -99
- package/src/producer/nonlocalized-field-changes.js +225 -194
- package/src/producer/publish-assets.js +97 -83
- package/src/producer/publish-edits.js +113 -88
- package/src/producer/publish-entries.js +121 -90
- package/src/producer/publish-unpublished-env.js +114 -90
- package/src/producer/revert.js +261 -230
- package/src/producer/unpublish.js +154 -97
- package/src/services/publish-only-unpublished.js +130 -0
- package/src/util/client.js +14 -15
- package/src/util/command-helper.js +25 -0
- package/src/util/fs.js +10 -11
- package/src/util/index.js +38 -36
- package/src/util/logger.js +21 -25
- package/src/util/queue.js +13 -13
- package/src/util/retryfailed.js +8 -4
- package/src/util/store.js +43 -47
- package/src/commands/cm/bulk-publish/add-fields.js +0 -122
- package/src/commands/cm/bulk-publish/assets.js +0 -122
- package/src/commands/cm/bulk-publish/clear.js +0 -65
- package/src/commands/cm/bulk-publish/configure.js +0 -44
- package/src/commands/cm/bulk-publish/entries.js +0 -131
- package/src/commands/cm/bulk-publish/entry-edits.js +0 -129
- package/src/commands/cm/bulk-publish/nonlocalized-field-changes.js +0 -121
- package/src/commands/cm/bulk-publish/revert.js +0 -81
- package/src/commands/cm/bulk-publish/unpublish.js +0 -169
- package/src/commands/cm/bulk-publish/unpublished-entries.js +0 -127
- package/src/util/request.js +0 -59
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
/* eslint-disable node/no-extraneous-require */
|
|
3
|
+
const { Command, flags } = require('@contentstack/cli-command');
|
|
4
|
+
const { start: startPublish } = require('../../../producer/publish-entries');
|
|
5
|
+
const { start: startCrossPublish } = require('../../../producer/cross-publish');
|
|
6
|
+
const store = require('../../../util/store.js');
|
|
7
|
+
const { cliux } = require('@contentstack/cli-utilities');
|
|
8
|
+
const configKey = 'publish_entries';
|
|
9
|
+
const configKeyCrossEnv = 'cross_env_publish';
|
|
10
|
+
const { prettyPrint, formatError } = require('../../../util');
|
|
11
|
+
const { getStack } = require('../../../util/client.js');
|
|
12
|
+
const { printFlagDeprecation } = require('@contentstack/cli-utilities');
|
|
13
|
+
let config;
|
|
14
|
+
|
|
15
|
+
class PublishEntriesCommand extends Command {
|
|
16
|
+
async run() {
|
|
17
|
+
const entriesFlags = this.parse(PublishEntriesCommand).flags;
|
|
18
|
+
entriesFlags.retryFailed = entriesFlags['retry-failed'] || entriesFlags.retryFailed || false;
|
|
19
|
+
entriesFlags.contentTypes = entriesFlags['content-types'] || entriesFlags.contentTypes;
|
|
20
|
+
entriesFlags.bulkPublish = entriesFlags['bulk-publish'] || entriesFlags.bulkPublish;
|
|
21
|
+
entriesFlags.publishAllContentTypes = entriesFlags['publish-all-content-types'] || entriesFlags.publishAllContentTypes || false;
|
|
22
|
+
delete entriesFlags['retry-failed'];
|
|
23
|
+
delete entriesFlags['content-types'];
|
|
24
|
+
delete entriesFlags['bulk-publish'];
|
|
25
|
+
delete entriesFlags['publish-all-content-types'];
|
|
26
|
+
|
|
27
|
+
let updatedFlags;
|
|
28
|
+
try {
|
|
29
|
+
const storeConfigKey = entriesFlags['source-env'] ? configKeyCrossEnv : configKey
|
|
30
|
+
updatedFlags = entriesFlags.config ? store.updateMissing(storeConfigKey, entriesFlags) : entriesFlags;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
this.error(error.message, { exit: 2 });
|
|
33
|
+
}
|
|
34
|
+
if (this.validate(updatedFlags)) {
|
|
35
|
+
let stack;
|
|
36
|
+
if (!updatedFlags.retryFailed) {
|
|
37
|
+
if (!updatedFlags.alias) {
|
|
38
|
+
updatedFlags.alias = await cliux.prompt('Provide the alias of the management token to use');
|
|
39
|
+
}
|
|
40
|
+
updatedFlags.bulkPublish = updatedFlags.bulkPublish !== 'false';
|
|
41
|
+
// Validate management token alias.
|
|
42
|
+
try {
|
|
43
|
+
this.getToken(updatedFlags.alias);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
this.error(`The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`, { exit: 2 })
|
|
46
|
+
}
|
|
47
|
+
config = {
|
|
48
|
+
alias: updatedFlags.alias,
|
|
49
|
+
host: this.region.cma,
|
|
50
|
+
cda: this.region.cda,
|
|
51
|
+
branch: entriesFlags.branch,
|
|
52
|
+
};
|
|
53
|
+
stack = getStack(config);
|
|
54
|
+
}
|
|
55
|
+
if (await this.confirmFlags(updatedFlags)) {
|
|
56
|
+
try {
|
|
57
|
+
|
|
58
|
+
const publishFunction = async (func) => {
|
|
59
|
+
// eslint-disable-next-line no-negated-condition
|
|
60
|
+
if (!updatedFlags.retryFailed) {
|
|
61
|
+
await func(updatedFlags, stack, config);
|
|
62
|
+
} else {
|
|
63
|
+
await func(updatedFlags);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (updatedFlags['source-env']) {
|
|
68
|
+
updatedFlags.deliveryToken = updatedFlags['delivery-token']
|
|
69
|
+
updatedFlags.destEnv = updatedFlags.environments
|
|
70
|
+
updatedFlags.environment = updatedFlags['source-env']
|
|
71
|
+
updatedFlags.onlyEntries = true
|
|
72
|
+
if (updatedFlags.locales instanceof Array) {
|
|
73
|
+
updatedFlags.locales.forEach(locale => {
|
|
74
|
+
updatedFlags.locale = locale
|
|
75
|
+
publishFunction(startCrossPublish)
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
updatedFlags.locale = locales
|
|
79
|
+
publishFunction(startCrossPublish)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
publishFunction(startPublish)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
} catch (error) {
|
|
88
|
+
let message = formatError(error);
|
|
89
|
+
this.error(message, { exit: 2 });
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
this.exit(0);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
validate({ contentTypes, locales, environments, retryFailed, publishAllContentTypes, 'source-env': sourceEnv, 'delivery-token': deliveryToken }) {
|
|
98
|
+
let missing = [];
|
|
99
|
+
if (retryFailed) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (sourceEnv && !deliveryToken) {
|
|
104
|
+
this.error(
|
|
105
|
+
'Specify source environment delivery token. Please check --help for more details',
|
|
106
|
+
{ exit: 2 },
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (publishAllContentTypes && contentTypes && contentTypes.length > 0) {
|
|
111
|
+
this.error(
|
|
112
|
+
'Do not specify contentTypes when publishAllContentTypes flag is set. Please check --help for more details',
|
|
113
|
+
{ exit: 2 },
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if ((!contentTypes || contentTypes.length === 0) && !publishAllContentTypes) {
|
|
118
|
+
missing.push('Content Types');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (!locales || locales.length === 0) {
|
|
122
|
+
missing.push('Locales');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (!environments || environments.length === 0) {
|
|
126
|
+
missing.push('Environments');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (missing.length > 0) {
|
|
130
|
+
this.error(
|
|
131
|
+
`${missing.join(', ')} are required for processing this command. Please check --help for more details`,
|
|
132
|
+
{ exit: 2 },
|
|
133
|
+
);
|
|
134
|
+
} else {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async confirmFlags(data) {
|
|
140
|
+
prettyPrint(data);
|
|
141
|
+
|
|
142
|
+
if (data.yes) {
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return cliux.confirm('Do you want to continue with this configuration ? [yes or no]');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
PublishEntriesCommand.description = `Publish entries from multiple contenttypes to multiple environments and locales
|
|
151
|
+
The publish command is used to publish entries from the specified content types, to the
|
|
152
|
+
specified environments and locales
|
|
153
|
+
|
|
154
|
+
Note: Content Types, Environments and Locales are required to execute the command successfully
|
|
155
|
+
But, if retry-failed flag is set, then only a logfile is required
|
|
156
|
+
`;
|
|
157
|
+
|
|
158
|
+
PublishEntriesCommand.flags = {
|
|
159
|
+
alias: flags.string({ char: 'a', description: 'Alias(name) for the management token' }),
|
|
160
|
+
retryFailed: flags.string({
|
|
161
|
+
char: 'r',
|
|
162
|
+
description:
|
|
163
|
+
'Retry failed entries from the logfile (optional, overrides all other flags) This flag is used to retry publishing entries that failed to publish in a previous attempt. A log file for the previous session will be required for processing the failed entries',
|
|
164
|
+
hidden: true,
|
|
165
|
+
parse: printFlagDeprecation(['-r', '--retryFailed'], ['--retry-failed']),
|
|
166
|
+
}),
|
|
167
|
+
'retry-failed': flags.string({
|
|
168
|
+
description:
|
|
169
|
+
'(optional) Retry failed entries from the logfile (overrides all other flags) This flag is used to retry publishing entries that failed to publish in a previous attempt. A log file for the previous session will be required for processing the failed entries',
|
|
170
|
+
}),
|
|
171
|
+
bulkPublish: flags.string({
|
|
172
|
+
char: 'b',
|
|
173
|
+
description:
|
|
174
|
+
"This flag is set to true by default. It indicates that contentstack's bulkpublish API will be used to publish the entries",
|
|
175
|
+
hidden: true,
|
|
176
|
+
parse: printFlagDeprecation(['-b', '--bulkPublish'], ['--bulk-publish']),
|
|
177
|
+
}),
|
|
178
|
+
'bulk-publish': flags.string({
|
|
179
|
+
description:
|
|
180
|
+
"This flag is set to true by default. It indicates that contentstack's bulkpublish API will be used to publish the entries",
|
|
181
|
+
default: 'true',
|
|
182
|
+
}),
|
|
183
|
+
'publish-all-content-types': flags.boolean({
|
|
184
|
+
description: '(optional) Publish all contenttypes (cannot be set when contentTypes flag is set)',
|
|
185
|
+
}),
|
|
186
|
+
publishAllContentTypes: flags.boolean({
|
|
187
|
+
char: 'o',
|
|
188
|
+
description: 'Publish all content-types (optional, cannot be set when contentTypes flag is set)',
|
|
189
|
+
hidden: true,
|
|
190
|
+
parse: printFlagDeprecation(['-o', '--publishAllContentTypes'], ['--publish-all-content-types']),
|
|
191
|
+
}),
|
|
192
|
+
'content-types': flags.string({
|
|
193
|
+
description: 'The Contenttypes from which entries need to be published',
|
|
194
|
+
multiple: true,
|
|
195
|
+
}),
|
|
196
|
+
contentTypes: flags.string({
|
|
197
|
+
char: 't',
|
|
198
|
+
description: 'The Contenttypes from which entries will be published',
|
|
199
|
+
multiple: true,
|
|
200
|
+
parse: printFlagDeprecation(['-t', '--contentTypes'], ['--content-types']),
|
|
201
|
+
hidden: true,
|
|
202
|
+
}),
|
|
203
|
+
locales: flags.string({
|
|
204
|
+
char: 'l',
|
|
205
|
+
description: 'Locales where entries will be published',
|
|
206
|
+
multiple: true,
|
|
207
|
+
parse: printFlagDeprecation(['-l'], ['--locales']),
|
|
208
|
+
}),
|
|
209
|
+
environments: flags.string({
|
|
210
|
+
char: 'e',
|
|
211
|
+
description: 'Environments where entries will be published',
|
|
212
|
+
multiple: true,
|
|
213
|
+
}),
|
|
214
|
+
config: flags.string({
|
|
215
|
+
char: 'c',
|
|
216
|
+
description:
|
|
217
|
+
'Path for the external config file (A new config file can be generated at the current working directory using `csdx cm:bulk-publish:configure -a [ALIAS]`)',
|
|
218
|
+
}),
|
|
219
|
+
yes: flags.boolean({ char: 'y', description: 'Agree to process the command with the current configuration' }),
|
|
220
|
+
branch: flags.string({
|
|
221
|
+
char: 'B',
|
|
222
|
+
default: 'main',
|
|
223
|
+
description: 'Specify the branch to fetch the content (by default the main branch is selected)',
|
|
224
|
+
parse: printFlagDeprecation(['-B'], ['--branch']),
|
|
225
|
+
}),
|
|
226
|
+
'delivery-token': flags.string({ description: 'Delivery token for source environment' }),
|
|
227
|
+
'source-env': flags.string({ description: 'Source environment'}),
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
PublishEntriesCommand.examples = [
|
|
231
|
+
'General Usage',
|
|
232
|
+
'csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS]',
|
|
233
|
+
'',
|
|
234
|
+
'Using --config or -c flag',
|
|
235
|
+
'Generate a config file at the current working directory using `csdx cm:stacks:publish-configure -a [ALIAS]`',
|
|
236
|
+
'csdx cm:entries:publish --config [PATH TO CONFIG FILE]',
|
|
237
|
+
'csdx cm:entries:publish -c [PATH TO CONFIG FILE]',
|
|
238
|
+
'',
|
|
239
|
+
'Using --retry-failed',
|
|
240
|
+
'csdx cm:entries:publish --retry-failed [LOG FILE NAME]',
|
|
241
|
+
'csdx cm:entries:publish -r [LOG FILE NAME]',
|
|
242
|
+
'',
|
|
243
|
+
'Using --branch',
|
|
244
|
+
'csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME]',
|
|
245
|
+
'',
|
|
246
|
+
'Using --source-env',
|
|
247
|
+
'csdx cm:entries:publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --source-env [SOURCE ENVIRONMENT] --delivery-token [DELIVERY TOKEN]',
|
|
248
|
+
];
|
|
249
|
+
|
|
250
|
+
PublishEntriesCommand.aliases = ['cm:bulk-publish:entries']
|
|
251
|
+
|
|
252
|
+
PublishEntriesCommand.usage = 'cm:entries:publish [-a <value>] [--retry-failed <value>] [--bulk-publish <value>] [--publish-all-content-types] [--content-types <value>] [--locales <value>] [-e <value>] [-c <value>] [-y] [--branch <value>] [--delivery-token <value>] [--source-env <value>]'
|
|
253
|
+
|
|
254
|
+
module.exports = PublishEntriesCommand;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
/* eslint-disable node/no-extraneous-require */
|
|
3
|
+
const { Command, flags } = require('@contentstack/cli-command');
|
|
4
|
+
const { cliux } = require('@contentstack/cli-utilities');
|
|
5
|
+
const { start } = require('../../../producer/unpublish');
|
|
6
|
+
const store = require('../../../util/store.js');
|
|
7
|
+
const configKey = 'Unpublish';
|
|
8
|
+
const { prettyPrint, formatError } = require('../../../util');
|
|
9
|
+
const { getStack } = require('../../../util/client.js');
|
|
10
|
+
let config;
|
|
11
|
+
|
|
12
|
+
class UnpublishCommand extends Command {
|
|
13
|
+
async run() {
|
|
14
|
+
const unpublishFlags = this.parse(UnpublishCommand).flags;
|
|
15
|
+
unpublishFlags.retryFailed = unpublishFlags['retry-failed'] || unpublishFlags.retryFailed || false;
|
|
16
|
+
unpublishFlags.bulkUnpublish = unpublishFlags['bulk-unpublish'] || unpublishFlags.bulkUnpublish;
|
|
17
|
+
unpublishFlags.contentType = unpublishFlags['content-type'] || unpublishFlags.contentType || '';
|
|
18
|
+
unpublishFlags.deliveryToken = unpublishFlags['delivery-token'] || unpublishFlags.deliveryToken;
|
|
19
|
+
unpublishFlags.onlyAssets = false;
|
|
20
|
+
unpublishFlags.onlyEntries = true;
|
|
21
|
+
delete unpublishFlags['retry-failed'];
|
|
22
|
+
delete unpublishFlags['bulk-unpublish'];
|
|
23
|
+
delete unpublishFlags['content-type'];
|
|
24
|
+
delete unpublishFlags['delivery-token'];
|
|
25
|
+
|
|
26
|
+
let updatedFlags;
|
|
27
|
+
try {
|
|
28
|
+
updatedFlags = unpublishFlags.config ? store.updateMissing(configKey, unpublishFlags) : unpublishFlags;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
this.error(error.message, { exit: 2 });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (this.validate(updatedFlags)) {
|
|
34
|
+
let stack;
|
|
35
|
+
if (!updatedFlags.retryFailed) {
|
|
36
|
+
if (!updatedFlags.alias) {
|
|
37
|
+
updatedFlags.alias = await cliux.prompt('Please enter the management token alias to be used');
|
|
38
|
+
}
|
|
39
|
+
if (!updatedFlags.deliveryToken) {
|
|
40
|
+
updatedFlags.deliveryToken = await cliux.prompt('Enter delivery token of your source environment');
|
|
41
|
+
}
|
|
42
|
+
updatedFlags.bulkUnpublish = updatedFlags.bulkUnpublish === 'false' ? false : true;
|
|
43
|
+
// Validate management token alias.
|
|
44
|
+
try {
|
|
45
|
+
this.getToken(updatedFlags.alias);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
this.error(
|
|
48
|
+
`The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add --alias ${updatedFlags.alias}'`,
|
|
49
|
+
{ exit: 2 },
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
config = {
|
|
53
|
+
alias: updatedFlags.alias,
|
|
54
|
+
host: this.region.cma,
|
|
55
|
+
cda: this.region.cda,
|
|
56
|
+
branch: unpublishFlags.branch,
|
|
57
|
+
};
|
|
58
|
+
stack = getStack(config);
|
|
59
|
+
}
|
|
60
|
+
if (!updatedFlags.deliveryToken && updatedFlags.deliveryToken.length === 0) {
|
|
61
|
+
this.error('Delivery Token is required for executing this command', { exit: 2 });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (await this.confirmFlags(updatedFlags)) {
|
|
65
|
+
try {
|
|
66
|
+
if (!updatedFlags.retryFailed) {
|
|
67
|
+
await start(updatedFlags, stack, config);
|
|
68
|
+
} else {
|
|
69
|
+
await start(updatedFlags);
|
|
70
|
+
}
|
|
71
|
+
} catch (error) {
|
|
72
|
+
let message = formatError(error);
|
|
73
|
+
this.error(message, { exit: 2 });
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
this.exit(0);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
validate({ environment, retryFailed, locale }) {
|
|
82
|
+
let missing = [];
|
|
83
|
+
if (retryFailed) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!environment) {
|
|
88
|
+
missing.push('Environment');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Locales apply to assets as well
|
|
92
|
+
if (!locale) {
|
|
93
|
+
missing.push('Locale');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (missing.length > 0) {
|
|
97
|
+
this.error(
|
|
98
|
+
`${missing.join(', ')} is required for processing this command. Please check --help for more details`,
|
|
99
|
+
{ exit: 2 },
|
|
100
|
+
);
|
|
101
|
+
} else {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async confirmFlags(data) {
|
|
107
|
+
prettyPrint(data);
|
|
108
|
+
if (data.yes) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
if (!data.contentType) {
|
|
112
|
+
return cliux.confirm(
|
|
113
|
+
'Do you want to continue with this configuration. This will unpublish all the entries from all content types? [yes or no]',
|
|
114
|
+
);
|
|
115
|
+
} else {
|
|
116
|
+
return cliux.confirm('Do you want to continue with this configuration ? [yes or no]');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
UnpublishCommand.description = `Unpublish entries from the given environment
|
|
122
|
+
The unpublish command is used to unpublish entries from the given environment
|
|
123
|
+
|
|
124
|
+
Note: Environment (Source Environment) and Locale are required to execute the command successfully
|
|
125
|
+
But, if retry-failed flag is set, then only a logfile is required`;
|
|
126
|
+
|
|
127
|
+
UnpublishCommand.flags = {
|
|
128
|
+
alias: flags.string({
|
|
129
|
+
char: 'a',
|
|
130
|
+
description: 'Alias(name) for the management token',
|
|
131
|
+
}),
|
|
132
|
+
environment: flags.string({
|
|
133
|
+
char: 'e',
|
|
134
|
+
description: 'Source Environment',
|
|
135
|
+
}),
|
|
136
|
+
config: flags.string({
|
|
137
|
+
char: 'c',
|
|
138
|
+
description: 'Path to the config file',
|
|
139
|
+
}),
|
|
140
|
+
yes: flags.boolean({
|
|
141
|
+
char: 'y',
|
|
142
|
+
description: 'Agree to process the command with the current configuration',
|
|
143
|
+
}),
|
|
144
|
+
locale: flags.string({
|
|
145
|
+
description: 'Locale filter',
|
|
146
|
+
}),
|
|
147
|
+
branch: flags.string({
|
|
148
|
+
default: 'main',
|
|
149
|
+
description: 'Specify the branch to fetch the content (by default the main branch is selected)',
|
|
150
|
+
}),
|
|
151
|
+
'retry-failed': flags.string({
|
|
152
|
+
description: 'Retry publishing failed entries from the logfile',
|
|
153
|
+
}),
|
|
154
|
+
'bulk-unpublish': flags.string({
|
|
155
|
+
description:
|
|
156
|
+
"This flag is set to true by default. It indicates that contentstack's bulkpublish API will be used to unpublish the entries",
|
|
157
|
+
default: 'true',
|
|
158
|
+
}),
|
|
159
|
+
'content-type': flags.string({
|
|
160
|
+
description: 'Content type filter',
|
|
161
|
+
}),
|
|
162
|
+
'delivery-token': flags.string({
|
|
163
|
+
description: 'Delivery token for source environment',
|
|
164
|
+
}),
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
UnpublishCommand.examples = [
|
|
168
|
+
'General Usage',
|
|
169
|
+
'csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN]',
|
|
170
|
+
'',
|
|
171
|
+
'Using --config or -c flag',
|
|
172
|
+
'Generate a config file at the current working directory using `csdx cm:bulk-publish:configure --alias [ALIAS]`',
|
|
173
|
+
'csdx cm:stacks:unpublish --config [PATH TO CONFIG FILE]',
|
|
174
|
+
'csdx cm:stacks:unpublish -c [PATH TO CONFIG FILE]',
|
|
175
|
+
'',
|
|
176
|
+
'Using --retry-failed flag',
|
|
177
|
+
'csdx cm:stacks:unpublish --retry-failed [LOG FILE NAME]',
|
|
178
|
+
'',
|
|
179
|
+
'',
|
|
180
|
+
'Using --branch flag',
|
|
181
|
+
'csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --delivery-token [DELIVERY TOKEN] --branch [BRANCH NAME]',
|
|
182
|
+
];
|
|
183
|
+
|
|
184
|
+
module.exports = UnpublishCommand;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
const { Command, flags } = require('@contentstack/cli-command');
|
|
2
|
+
const { printFlagDeprecation, cliux } = require('@contentstack/cli-utilities');
|
|
3
|
+
|
|
4
|
+
const store = require('../../../util/store.js');
|
|
5
|
+
const { getStack } = require('../../../util/client.js');
|
|
6
|
+
const { start } = require('../../../producer/add-fields');
|
|
7
|
+
const { prettyPrint, formatError } = require('../../../util');
|
|
8
|
+
|
|
9
|
+
let config;
|
|
10
|
+
const configKey = 'addFields';
|
|
11
|
+
|
|
12
|
+
class UpdateAndPublishCommand extends Command {
|
|
13
|
+
async run() {
|
|
14
|
+
const addFieldsFlags = this.parse(UpdateAndPublishCommand).flags;
|
|
15
|
+
addFieldsFlags.retryFailed = addFieldsFlags['retry-failed'] || addFieldsFlags.retryFailed || false;
|
|
16
|
+
addFieldsFlags.contentTypes = addFieldsFlags['content-types'] || addFieldsFlags.contentTypes;
|
|
17
|
+
addFieldsFlags.bulkPublish = addFieldsFlags['bulk-publish'] || addFieldsFlags.bulkPublish;
|
|
18
|
+
delete addFieldsFlags['retry-failed'];
|
|
19
|
+
delete addFieldsFlags['content-types'];
|
|
20
|
+
delete addFieldsFlags['bulk-publish'];
|
|
21
|
+
|
|
22
|
+
let updatedFlags;
|
|
23
|
+
try {
|
|
24
|
+
updatedFlags = addFieldsFlags.config ? store.updateMissing(configKey, addFieldsFlags) : addFieldsFlags;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
this.error(error.message, { exit: 2 });
|
|
27
|
+
}
|
|
28
|
+
if (this.validate(updatedFlags)) {
|
|
29
|
+
let stack;
|
|
30
|
+
if (!updatedFlags.retryFailed) {
|
|
31
|
+
if (!updatedFlags.alias) {
|
|
32
|
+
updatedFlags.alias = await cliux.prompt('Please enter the management token alias to be used');
|
|
33
|
+
}
|
|
34
|
+
updatedFlags.bulkPublish = updatedFlags.bulkPublish === 'false' ? false : true;
|
|
35
|
+
// Validate management token alias.
|
|
36
|
+
try {
|
|
37
|
+
this.getToken(updatedFlags.alias);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
this.error(
|
|
40
|
+
`The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`,
|
|
41
|
+
{ exit: 2 },
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
config = {
|
|
45
|
+
alias: updatedFlags.alias,
|
|
46
|
+
host: this.region.cma,
|
|
47
|
+
branch: addFieldsFlags.branch,
|
|
48
|
+
};
|
|
49
|
+
stack = getStack(config);
|
|
50
|
+
}
|
|
51
|
+
if (await this.confirmFlags(updatedFlags)) {
|
|
52
|
+
try {
|
|
53
|
+
if (!updatedFlags.retryFailed) {
|
|
54
|
+
await start(updatedFlags, stack, config);
|
|
55
|
+
} else {
|
|
56
|
+
await start(updatedFlags);
|
|
57
|
+
}
|
|
58
|
+
} catch (error) {
|
|
59
|
+
let message = formatError(error);
|
|
60
|
+
this.error(message, { exit: 2 });
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
this.exit(0);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
validate({ contentTypes, locales, environments, retryFailed }) {
|
|
69
|
+
let missing = [];
|
|
70
|
+
if (retryFailed) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!contentTypes || contentTypes.length === 0) {
|
|
75
|
+
missing.push('Content Types');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!locales || locales.length === 0) {
|
|
79
|
+
missing.push('Locales');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!environments || environments.length === 0) {
|
|
83
|
+
missing.push('Environments');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (missing.length > 0) {
|
|
87
|
+
this.error(
|
|
88
|
+
`${missing.join(', ')} are required for processing this command. Please check --help for more details`,
|
|
89
|
+
{ exit: 2 },
|
|
90
|
+
);
|
|
91
|
+
} else {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async confirmFlags(data) {
|
|
97
|
+
prettyPrint(data);
|
|
98
|
+
if (data.yes) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
return cliux.confirm('Do you want to continue with this configuration ? [yes or no]');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
UpdateAndPublishCommand.description = `Add fields from updated content types to their respective entries
|
|
106
|
+
The update-and-publish command is used to update existing entries with the updated schema of the respective content type
|
|
107
|
+
|
|
108
|
+
Note: Content types, Environments and Locales are required to execute the command successfully
|
|
109
|
+
But, if retry-failed flag is set, then only a logfile is required
|
|
110
|
+
`;
|
|
111
|
+
|
|
112
|
+
UpdateAndPublishCommand.flags = {
|
|
113
|
+
alias: flags.string({ char: 'a', description: 'Alias(name) for the management token' }),
|
|
114
|
+
'retry-failed': flags.string({
|
|
115
|
+
description: 'Retry publishing failed entries from the logfile (optional, overrides all other flags)',
|
|
116
|
+
}),
|
|
117
|
+
retryFailed: flags.string({
|
|
118
|
+
char: 'r',
|
|
119
|
+
description: 'Retry publishing failed entries from the logfile (optional, overrides all other flags)',
|
|
120
|
+
hidden: true,
|
|
121
|
+
parse: printFlagDeprecation(['-r', '--retryFailed'], ['--retry-failed']),
|
|
122
|
+
}),
|
|
123
|
+
'bulk-publish': flags.string({
|
|
124
|
+
description:
|
|
125
|
+
"This flag is set to true by default. It indicates that contentstack's bulkpublish API will be used to publish the entries",
|
|
126
|
+
default: 'true',
|
|
127
|
+
}),
|
|
128
|
+
bulkPublish: flags.string({
|
|
129
|
+
char: 'b',
|
|
130
|
+
description:
|
|
131
|
+
"This flag is set to true by default. It indicates that contentstack's bulkpublish API will be used to publish the entries",
|
|
132
|
+
hidden: true,
|
|
133
|
+
parse: printFlagDeprecation(['-b', '--bulkPublish'], ['--bulk-publish']),
|
|
134
|
+
}),
|
|
135
|
+
'content-types': flags.string({
|
|
136
|
+
description: 'The Contenttypes from which entries will be published',
|
|
137
|
+
multiple: true,
|
|
138
|
+
}),
|
|
139
|
+
contentTypes: flags.string({
|
|
140
|
+
char: 't',
|
|
141
|
+
description: 'The Contenttypes from which entries will be published',
|
|
142
|
+
multiple: true,
|
|
143
|
+
parse: printFlagDeprecation(['-t', '--contentTypes'], ['--content-types']),
|
|
144
|
+
}),
|
|
145
|
+
environments: flags.string({
|
|
146
|
+
char: 'e',
|
|
147
|
+
description: 'Environments where entries will be published',
|
|
148
|
+
multiple: true,
|
|
149
|
+
}),
|
|
150
|
+
config: flags.string({ char: 'c', description: 'Path to the config file' }),
|
|
151
|
+
yes: flags.boolean({ char: 'y', description: 'Agree to process the command with the current configuration' }),
|
|
152
|
+
locales: flags.string({
|
|
153
|
+
char: 'l',
|
|
154
|
+
description: 'Locales where entries will be published',
|
|
155
|
+
multiple: true,
|
|
156
|
+
parse: printFlagDeprecation(['-l'], ['--locales']),
|
|
157
|
+
}),
|
|
158
|
+
branch: flags.string({
|
|
159
|
+
char: 'B',
|
|
160
|
+
default: 'main',
|
|
161
|
+
description: 'Specify the branch to fetch the content (by default the main branch is selected)',
|
|
162
|
+
parse: printFlagDeprecation(['-B'], ['--branch']),
|
|
163
|
+
}),
|
|
164
|
+
force: flags.boolean({
|
|
165
|
+
default: false,
|
|
166
|
+
description: 'Update and publish all entries even if no fields have been added',
|
|
167
|
+
}),
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
UpdateAndPublishCommand.examples = [
|
|
171
|
+
'General Usage',
|
|
172
|
+
'csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locale [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS]',
|
|
173
|
+
'',
|
|
174
|
+
'Using --config or -c flag',
|
|
175
|
+
'Generate a config file at the current working directory using `csdx cm:stacks:publish-configure -a [ALIAS]`',
|
|
176
|
+
'csdx cm:entries:update-and-publish --config [PATH TO CONFIG FILE]',
|
|
177
|
+
'csdx cm:entries:update-and-publish -c [PATH TO CONFIG FILE]',
|
|
178
|
+
'',
|
|
179
|
+
'Using --retry-failed',
|
|
180
|
+
'csdx cm:entries:update-and-publish --retry-failed [LOG FILE NAME]',
|
|
181
|
+
'',
|
|
182
|
+
'Using --branch',
|
|
183
|
+
'csdx cm:entries:update-and-publish --content-types [CONTENT TYPE 1] [CONTENT TYPE 2] -e [ENVIRONMENT 1] [ENVIRONMENT 2] --locale [LOCALE 1] [LOCALE 2] -a [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME]',
|
|
184
|
+
];
|
|
185
|
+
|
|
186
|
+
UpdateAndPublishCommand.aliases = ['cm:bulk-publish:add-fields'];
|
|
187
|
+
|
|
188
|
+
UpdateAndPublishCommand.usage =
|
|
189
|
+
'cm:entries:update-and-publish [-a <value>] [--retry-failed <value>] [--bulk-publish <value>] [--content-types <value>] [-t <value>] [-e <value>] [-c <value>] [-y] [--locales <value>] [--branch <value>]';
|
|
190
|
+
|
|
191
|
+
module.exports = UpdateAndPublishCommand;
|