@contentstack/cli-cm-bulk-publish 0.1.1-beta.5 → 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.
- package/LICENSE +21 -0
- package/README.md +525 -318
- package/oclif.manifest.json +1 -1
- package/package.json +26 -11
- package/src/commands/cm/assets/publish.js +233 -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 +587 -362
- package/src/producer/add-fields.js +204 -179
- package/src/producer/cross-publish.js +175 -98
- 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 +15 -16
- 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,82 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const { Command, flags } = require('@contentstack/cli-command');
|
|
3
|
+
const { cliux, printFlagDeprecation } = require('@contentstack/cli-utilities');
|
|
4
|
+
|
|
5
|
+
const { getLogsDirPath } = require('../../../util/logger.js');
|
|
6
|
+
|
|
7
|
+
class ClearCommand extends Command {
|
|
8
|
+
async run() {
|
|
9
|
+
const clearFlags = this.parse(ClearCommand).flags;
|
|
10
|
+
let dirPath = getLogsDirPath();
|
|
11
|
+
if (clearFlags['log-files-count'] || clearFlags.list) {
|
|
12
|
+
this.listFiles(dirPath);
|
|
13
|
+
} else if (clearFlags.yes) {
|
|
14
|
+
this.rmDir(dirPath, false);
|
|
15
|
+
} else {
|
|
16
|
+
const confirmation = await cliux.confirm('Proceed to delete all log files (y/n)?');
|
|
17
|
+
if (confirmation) {
|
|
18
|
+
this.rmDir(dirPath, false);
|
|
19
|
+
} else {
|
|
20
|
+
this.log('No action performed');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
rmDir(dirPath, removeSelf = true) {
|
|
26
|
+
try {
|
|
27
|
+
if (fs.existsSync(dirPath)) {
|
|
28
|
+
const files = fs.readdirSync(dirPath);
|
|
29
|
+
if (files.length > 0)
|
|
30
|
+
for (const element of files) {
|
|
31
|
+
const filePath = dirPath + '/' + element;
|
|
32
|
+
if (fs.statSync(filePath).isFile()) fs.unlinkSync(filePath);
|
|
33
|
+
else rmDir(filePath);
|
|
34
|
+
}
|
|
35
|
+
if (removeSelf) {
|
|
36
|
+
fs.rmdirSync(dirPath);
|
|
37
|
+
}
|
|
38
|
+
this.log('Log files have been cleared');
|
|
39
|
+
} else {
|
|
40
|
+
this.error(`The log directory doesn't exist.`);
|
|
41
|
+
}
|
|
42
|
+
} catch (e) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
listFiles(dirPath) {
|
|
48
|
+
if (fs.existsSync(dirPath)) {
|
|
49
|
+
fs.readdir(dirPath, (_err, files) => {
|
|
50
|
+
this.log('Total number of log files - ', files.length);
|
|
51
|
+
});
|
|
52
|
+
} else {
|
|
53
|
+
this.error(`The log directory doesn't exist.`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
ClearCommand.description = `Clear the log folder`;
|
|
59
|
+
|
|
60
|
+
ClearCommand.flags = {
|
|
61
|
+
'log-files-count': flags.boolean({ description: 'List number of log files' }),
|
|
62
|
+
yes: flags.boolean({ char: 'y', description: 'Delete all files without asking for confirmation' }),
|
|
63
|
+
|
|
64
|
+
//To be depreacted
|
|
65
|
+
list: flags.boolean({
|
|
66
|
+
description: 'List number of log files',
|
|
67
|
+
char: 'l',
|
|
68
|
+
hidden: true,
|
|
69
|
+
parse: printFlagDeprecation(['-l', '--list'], ['--log-files-count']),
|
|
70
|
+
}),
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
ClearCommand.examples = [
|
|
74
|
+
'csdx cm:stacks:publish-clear-logs',
|
|
75
|
+
'csdx cm:stacks:publish-clear-logs --log-files-count',
|
|
76
|
+
'csdx cm:stacks:publish-clear-logs --yes',
|
|
77
|
+
'csdx cm:stacks:publish-clear-logs -y',
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
ClearCommand.aliases = ['cm:bulk-publish:clear'];
|
|
81
|
+
|
|
82
|
+
module.exports = ClearCommand;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { Command, flags } = require('@contentstack/cli-command');
|
|
4
|
+
const { cliux } = require('@contentstack/cli-utilities');
|
|
5
|
+
|
|
6
|
+
let config = require('../../../config/index.js');
|
|
7
|
+
|
|
8
|
+
class ConfigureCommand extends Command {
|
|
9
|
+
async run() {
|
|
10
|
+
const configureFlags = this.parse(ConfigureCommand).flags;
|
|
11
|
+
|
|
12
|
+
if (!configureFlags.alias) {
|
|
13
|
+
configureFlags.alias = await cliux.prompt('Please enter the management token alias to be used');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
this.getToken(configureFlags.alias);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
this.error(`The configured management token alias ${configureFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${configureFlags.alias}'`, { exit: 2 })
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
this.setConfig(configureFlags);
|
|
23
|
+
this.log('The configuration has been saved successfully.');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
setConfig({ alias }) {
|
|
27
|
+
if (alias) config.alias = alias;
|
|
28
|
+
fs.writeFileSync(path.join(process.cwd(), 'config.js'), `module.exports = ${JSON.stringify(config, null, 2)}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
ConfigureCommand.description = `The configure command is used to generate a configuration file for publish scripts.`;
|
|
33
|
+
|
|
34
|
+
ConfigureCommand.flags = {
|
|
35
|
+
alias: flags.string({ char: 'a', description: 'Alias(name) for the management token' }),
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
ConfigureCommand.examples = [
|
|
39
|
+
'csdx cm:stacks:publish-configure',
|
|
40
|
+
'csdx cm:stacks:publish-configure -a <management_token_alias>',
|
|
41
|
+
'csdx cm:stacks:publish-configure --alias <management_token_alias>',
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
ConfigureCommand.aliases = ['cm:bulk-publish:configure'];
|
|
45
|
+
|
|
46
|
+
module.exports = ConfigureCommand;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const { Command, flags } = require('@contentstack/cli-command');
|
|
2
|
+
const { cliux, printFlagDeprecation } = require('@contentstack/cli-utilities');
|
|
3
|
+
|
|
4
|
+
const store = require('../../../util/store.js');
|
|
5
|
+
const { start } = require('../../../producer/revert');
|
|
6
|
+
const { prettyPrint, formatError } = require('../../../util');
|
|
7
|
+
|
|
8
|
+
let config;
|
|
9
|
+
const configKey = 'revert';
|
|
10
|
+
|
|
11
|
+
class RevertCommand extends Command {
|
|
12
|
+
async run() {
|
|
13
|
+
const revertFlags = this.parse(RevertCommand).flags;
|
|
14
|
+
revertFlags.retryFailed = revertFlags['retry-failed'] || revertFlags.retryFailed;
|
|
15
|
+
revertFlags.logFile = revertFlags['log-file'] || revertFlags.logFile;
|
|
16
|
+
delete revertFlags['retry-failed'];
|
|
17
|
+
delete revertFlags['log-file'];
|
|
18
|
+
|
|
19
|
+
let updatedFlags;
|
|
20
|
+
try {
|
|
21
|
+
updatedFlags = revertFlags.config ? store.updateMissing(configKey, revertFlags) : revertFlags;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
this.error(error.message, { exit: 2 });
|
|
24
|
+
}
|
|
25
|
+
if (this.validate(updatedFlags)) {
|
|
26
|
+
if (await this.confirmFlags(updatedFlags)) {
|
|
27
|
+
try {
|
|
28
|
+
await start(updatedFlags, config);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
const message = formatError(error);
|
|
31
|
+
this.error(message, { exit: 2 });
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
this.exit(0);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
validate({ retryFailed, logFile }) {
|
|
40
|
+
let missing = [];
|
|
41
|
+
if (retryFailed) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!logFile) {
|
|
46
|
+
missing.push('log-file');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (missing.length > 0) {
|
|
50
|
+
this.error(
|
|
51
|
+
`${missing.join(', ')} is required for processing this command. Please check --help for more details`,
|
|
52
|
+
{ exit: 2 },
|
|
53
|
+
);
|
|
54
|
+
} else {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async confirmFlags(data) {
|
|
60
|
+
prettyPrint(data);
|
|
61
|
+
if (data.yes) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
return cliux.confirm('Do you want to continue with this configuration ? [yes or no]');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
RevertCommand.description = `Revert publish operations by using a log file
|
|
69
|
+
The revert command is used to revert all publish operations performed using bulk-publish script.
|
|
70
|
+
A log file name is required to execute revert command
|
|
71
|
+
`;
|
|
72
|
+
|
|
73
|
+
RevertCommand.flags = {
|
|
74
|
+
'retry-failed': flags.string({ description: 'retry publishing failed entries from the logfile' }),
|
|
75
|
+
'log-file': flags.string({ description: 'logfile to be used to revert' }),
|
|
76
|
+
|
|
77
|
+
//To be deprecated
|
|
78
|
+
retryFailed: flags.string({
|
|
79
|
+
char: 'r',
|
|
80
|
+
description: 'retry publishing failed entries from the logfile',
|
|
81
|
+
hidden: true,
|
|
82
|
+
parse: printFlagDeprecation(['-r', '--retryFailed'], ['--retry-failed']),
|
|
83
|
+
}),
|
|
84
|
+
logFile: flags.string({
|
|
85
|
+
char: 'l',
|
|
86
|
+
description: 'logfile to be used to revert',
|
|
87
|
+
hidden: true,
|
|
88
|
+
parse: printFlagDeprecation(['-l', '--logFile'], ['--log-file']),
|
|
89
|
+
}),
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
RevertCommand.examples = [
|
|
93
|
+
'Using --log-file',
|
|
94
|
+
'cm:bulk-publish:revert --log-file [LOG FILE NAME]',
|
|
95
|
+
'',
|
|
96
|
+
'Using --retry-failed',
|
|
97
|
+
'cm:bulk-publish:revert --retry-failed [LOG FILE NAME]',
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
RevertCommand.aliases = ['cm:bulk-publish:revert'];
|
|
101
|
+
|
|
102
|
+
module.exports = RevertCommand;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { Command } = require('@contentstack/cli-command');
|
|
4
|
+
const { getSelectedCommand } = require('../../../util/command-helper');
|
|
5
|
+
const AssetsPublishReceiverCommand = require('../assets/publish');
|
|
6
|
+
const EntriesPublishReceiverCommand = require('../entries/publish');
|
|
7
|
+
|
|
8
|
+
class StackPublishCommand extends Command {
|
|
9
|
+
async run() {
|
|
10
|
+
try {
|
|
11
|
+
this.optionController = new OptionController();
|
|
12
|
+
|
|
13
|
+
this.entriesPublishReceiver = new EntriesPublishReceiverCommand(this.argv);
|
|
14
|
+
this.assetsPublishReceiver = new AssetsPublishReceiverCommand(this.argv);
|
|
15
|
+
this.entriesAndAssetsPublishReceiver = new PublishEntriesAndAssetsCommand();
|
|
16
|
+
|
|
17
|
+
this.publishEntriesCommand = new PublishEntriesCommand(this.entriesPublishReceiver);
|
|
18
|
+
this.publishAssetsCommand = new PublishAssetsCommand(this.assetsPublishReceiver);
|
|
19
|
+
this.publishEntriesAndAssetsCommand = new PublishEntriesAndAssetsCommand(this.entriesPublishReceiver, this.assetsPublishReceiver);
|
|
20
|
+
|
|
21
|
+
this.optionController.setCommand(0, this.publishEntriesCommand);
|
|
22
|
+
this.optionController.setCommand(1, this.publishAssetsCommand);
|
|
23
|
+
this.optionController.setCommand(2, this.publishEntriesAndAssetsCommand);
|
|
24
|
+
|
|
25
|
+
const selectedCommand = await getSelectedCommand();
|
|
26
|
+
await this.optionController.execute(selectedCommand);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
this.error(error.message, { exit: 2 });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
StackPublishCommand.description = `Publish entries and assets to multiple environments and locales
|
|
34
|
+
The publish command is used to publish entries and assets, to the specified environments and locales.
|
|
35
|
+
|
|
36
|
+
Note: Content types, Environments and Locales are required to execute the publish entries command successfully.
|
|
37
|
+
Note: Environments and Locales are required to execute the publish assets command successfully.
|
|
38
|
+
But, if retry-failed flag is set, then only a logfile is required`;
|
|
39
|
+
|
|
40
|
+
StackPublishCommand.examples = [
|
|
41
|
+
'General Usage',
|
|
42
|
+
'csdx cm:stacks:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS]',
|
|
43
|
+
'',
|
|
44
|
+
'Using --config or -c flag',
|
|
45
|
+
'Generate a config file in the current working directory using `csdx cm:stacks:publish-configure -a [ALIAS]`',
|
|
46
|
+
'csdx cm:stacks:publish --config [PATH TO CONFIG FILE]',
|
|
47
|
+
'csdx cm:stacks:publish -c [PATH TO CONFIG FILE]',
|
|
48
|
+
'',
|
|
49
|
+
'Using --retry-failed flag',
|
|
50
|
+
'csdx cm:stacks:publish --retry-failed [LOG FILE NAME]',
|
|
51
|
+
'',
|
|
52
|
+
'Using --branch flag',
|
|
53
|
+
'csdx cm:stacks:publish --environments [ENVIRONMENT 1] [ENVIRONMENT 2] --locales [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] --branch [BRANCH NAME]'
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
StackPublishCommand.flags = []; // Same as entries and assets.
|
|
57
|
+
|
|
58
|
+
module.exports = StackPublishCommand;
|
|
59
|
+
|
|
60
|
+
// Invoker
|
|
61
|
+
class OptionController {
|
|
62
|
+
constructor() {
|
|
63
|
+
this.runCommands = [];
|
|
64
|
+
const noCommand = new NoCommand();
|
|
65
|
+
for (let i = 0; i < 3; i++) {
|
|
66
|
+
this.runCommands[i] = noCommand;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
setCommand(slot, command) {
|
|
71
|
+
this.runCommands[slot] = command;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async execute(slot) {
|
|
75
|
+
await this.runCommands[slot].execute();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
class NoCommand {
|
|
80
|
+
execute() { }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
class PublishEntriesCommand {
|
|
84
|
+
constructor(publishEntryReceiver) {
|
|
85
|
+
this.publishEntry = publishEntryReceiver;
|
|
86
|
+
}
|
|
87
|
+
async execute() {
|
|
88
|
+
await this.publishEntry.run();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
class PublishAssetsCommand {
|
|
93
|
+
constructor(publishAssetReceiver) {
|
|
94
|
+
this.publishAsset = publishAssetReceiver;
|
|
95
|
+
}
|
|
96
|
+
async execute() {
|
|
97
|
+
await this.publishAsset.run();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
class PublishEntriesAndAssetsCommand {
|
|
102
|
+
constructor(publishEntryReceiver, publishAssetReceiver) {
|
|
103
|
+
this.publishEntry = publishEntryReceiver;
|
|
104
|
+
this.publishAsset = publishAssetReceiver;
|
|
105
|
+
}
|
|
106
|
+
async execute() {
|
|
107
|
+
await this.publishAsset.run();
|
|
108
|
+
await this.publishEntry.run();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
/* eslint-disable node/no-extraneous-require */
|
|
3
|
+
const { Command, flags } = require('@contentstack/cli-command');
|
|
4
|
+
const { start } = require('../../../producer/unpublish');
|
|
5
|
+
const store = require('../../../util/store.js');
|
|
6
|
+
const configKey = 'Unpublish';
|
|
7
|
+
const { prettyPrint, formatError } = require('../../../util');
|
|
8
|
+
const { getStack } = require('../../../util/client.js');
|
|
9
|
+
const { printFlagDeprecation, cliux } = require('@contentstack/cli-utilities');
|
|
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;
|
|
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 = unpublishFlags['only-assets'] || unpublishFlags.onlyAssets;
|
|
20
|
+
unpublishFlags.onlyEntries = unpublishFlags['only-entries'] || unpublishFlags.onlyEntries;
|
|
21
|
+
delete unpublishFlags['retry-failed'];
|
|
22
|
+
delete unpublishFlags['bulk-unpublish'];
|
|
23
|
+
delete unpublishFlags['content-type'];
|
|
24
|
+
delete unpublishFlags['delivery-token'];
|
|
25
|
+
delete unpublishFlags['only-assets'];
|
|
26
|
+
delete unpublishFlags['only-entries'];
|
|
27
|
+
|
|
28
|
+
let updatedFlags;
|
|
29
|
+
try {
|
|
30
|
+
updatedFlags = unpublishFlags.config ? store.updateMissing(configKey, unpublishFlags) : unpublishFlags;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
this.error(error.message, { exit: 2 });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (this.validate(updatedFlags)) {
|
|
36
|
+
let stack;
|
|
37
|
+
if (!updatedFlags.retryFailed) {
|
|
38
|
+
if (!updatedFlags.alias) {
|
|
39
|
+
updatedFlags.alias = await cliux.prompt('Please enter the management token alias to be used');
|
|
40
|
+
}
|
|
41
|
+
if (!updatedFlags.deliveryToken) {
|
|
42
|
+
updatedFlags.deliveryToken = await cliux.prompt('Enter delivery token of your source environment');
|
|
43
|
+
}
|
|
44
|
+
updatedFlags.bulkUnpublish = updatedFlags.bulkUnpublish === 'false' ? false : true;
|
|
45
|
+
// Validate management token alias.
|
|
46
|
+
try {
|
|
47
|
+
this.getToken(updatedFlags.alias);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
this.error(
|
|
50
|
+
`The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add --alias ${updatedFlags.alias}'`,
|
|
51
|
+
{ exit: 2 },
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
config = {
|
|
55
|
+
alias: updatedFlags.alias,
|
|
56
|
+
host: this.region.cma,
|
|
57
|
+
cda: this.region.cda,
|
|
58
|
+
branch: unpublishFlags.branch,
|
|
59
|
+
};
|
|
60
|
+
stack = getStack(config);
|
|
61
|
+
}
|
|
62
|
+
if (!updatedFlags.deliveryToken && updatedFlags.deliveryToken.length === 0) {
|
|
63
|
+
this.error('Delivery Token is required for executing this command', { exit: 2 });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (await this.confirmFlags(updatedFlags)) {
|
|
67
|
+
try {
|
|
68
|
+
if (!updatedFlags.retryFailed) {
|
|
69
|
+
await start(updatedFlags, stack, config);
|
|
70
|
+
} else {
|
|
71
|
+
await start(updatedFlags);
|
|
72
|
+
}
|
|
73
|
+
} catch (error) {
|
|
74
|
+
let message = formatError(error);
|
|
75
|
+
this.error(message, { exit: 2 });
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
this.exit(0);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
validate({ environment, retryFailed, locale, contentType, onlyAssets, onlyEntries }) {
|
|
84
|
+
let missing = [];
|
|
85
|
+
if (retryFailed) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (onlyAssets && onlyEntries) {
|
|
90
|
+
this.error(
|
|
91
|
+
`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`,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (onlyAssets && contentType) {
|
|
96
|
+
this.error(
|
|
97
|
+
`Specifying content-type and onlyAssets together will have unexpected results. Please do not use these 2 flags together. Thank you.`,
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!environment) {
|
|
102
|
+
missing.push('Environment');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Adding !onlyAssets because if, onlyAssets is set to true, that means only assets are going to be unpublished.
|
|
106
|
+
// Then locale won't be necessary (turns out that this is not the case)
|
|
107
|
+
// if (!locale && !onlyAssets) {
|
|
108
|
+
// missing.push('Locale')
|
|
109
|
+
// }
|
|
110
|
+
|
|
111
|
+
// Locales apply to assets as well
|
|
112
|
+
if (!locale) {
|
|
113
|
+
missing.push('Locale');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (missing.length > 0) {
|
|
117
|
+
this.error(
|
|
118
|
+
`${missing.join(', ')} is required for processing this command. Please check --help for more details`,
|
|
119
|
+
{ exit: 2 },
|
|
120
|
+
);
|
|
121
|
+
} else {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async confirmFlags(data) {
|
|
127
|
+
let confirmation;
|
|
128
|
+
prettyPrint(data);
|
|
129
|
+
if (data.yes) {
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (!data.contentType && !data.onlyAssets) {
|
|
134
|
+
confirmation = await cliux.confirm(
|
|
135
|
+
'Do you want to continue with this configuration. This will unpublish all the entries from all content types? [yes or no]',
|
|
136
|
+
);
|
|
137
|
+
} else {
|
|
138
|
+
confirmation = await cliux.confirm('Do you want to continue with this configuration ? [yes or no]');
|
|
139
|
+
}
|
|
140
|
+
return confirmation;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
UnpublishCommand.description = `Unpublish entries or assets of given content types from the specified environment
|
|
145
|
+
The unpublish command is used to unpublish entries or assets from given environment
|
|
146
|
+
|
|
147
|
+
Environment (Source Environment) and Locale are required to execute the command successfully
|
|
148
|
+
But, if retry-failed flag is set, then only a logfile is required
|
|
149
|
+
|
|
150
|
+
A content type can be specified for unpublishing entries, but if no content-type(s) is/are specified and --only-assets is not used,
|
|
151
|
+
then all entries from all content types will be unpublished from the source environment
|
|
152
|
+
|
|
153
|
+
Note: --only-assets can be used to unpublish only assets and --only-entries can be used to unpublish only entries.
|
|
154
|
+
(--only-assets and --only-entries cannot be used together at the same time)
|
|
155
|
+
`;
|
|
156
|
+
|
|
157
|
+
UnpublishCommand.flags = {
|
|
158
|
+
alias: flags.string({
|
|
159
|
+
char: 'a',
|
|
160
|
+
description: 'Alias(name) for the management token',
|
|
161
|
+
}),
|
|
162
|
+
environment: flags.string({
|
|
163
|
+
char: 'e',
|
|
164
|
+
description: 'Source Environment',
|
|
165
|
+
}),
|
|
166
|
+
config: flags.string({
|
|
167
|
+
char: 'c',
|
|
168
|
+
description: 'Path to the config file',
|
|
169
|
+
}),
|
|
170
|
+
yes: flags.boolean({
|
|
171
|
+
char: 'y',
|
|
172
|
+
description: 'Agree to process the command with the current configuration',
|
|
173
|
+
}),
|
|
174
|
+
locale: flags.string({
|
|
175
|
+
char: 'l',
|
|
176
|
+
description: 'Locale filter',
|
|
177
|
+
parse: printFlagDeprecation(['-l'], ['--locale']),
|
|
178
|
+
}),
|
|
179
|
+
branch: flags.string({
|
|
180
|
+
char: 'B',
|
|
181
|
+
default: 'main',
|
|
182
|
+
description: 'Specify the branch to fetch the content from (default is main branch)',
|
|
183
|
+
parse: printFlagDeprecation(['-B'], ['--branch']),
|
|
184
|
+
}),
|
|
185
|
+
'retry-failed': flags.string({
|
|
186
|
+
description: 'Retry publishing failed entries from the logfile (optional, overrides all other flags)',
|
|
187
|
+
}),
|
|
188
|
+
'bulk-unpublish': flags.string({
|
|
189
|
+
description:
|
|
190
|
+
"This flag is set to true by default. It indicates that contentstack's bulkpublish API will be used to unpublish the entries and assets",
|
|
191
|
+
default: 'true',
|
|
192
|
+
}),
|
|
193
|
+
'content-type': flags.string({
|
|
194
|
+
description: 'Content type filter',
|
|
195
|
+
}),
|
|
196
|
+
'delivery-token': flags.string({
|
|
197
|
+
description: 'Delivery token for source environment',
|
|
198
|
+
}),
|
|
199
|
+
'only-assets': flags.boolean({
|
|
200
|
+
description: 'Unpublish only assets',
|
|
201
|
+
default: false,
|
|
202
|
+
hidden: true,
|
|
203
|
+
}),
|
|
204
|
+
'only-entries': flags.boolean({
|
|
205
|
+
description: 'Unpublish only entries',
|
|
206
|
+
default: false,
|
|
207
|
+
hidden: true,
|
|
208
|
+
}),
|
|
209
|
+
|
|
210
|
+
// To be deprecated
|
|
211
|
+
retryFailed: flags.string({
|
|
212
|
+
char: 'r',
|
|
213
|
+
description: 'Retry publishing failed entries from the logfile',
|
|
214
|
+
hidden: true,
|
|
215
|
+
parse: printFlagDeprecation(['-r', '--retryFailed'], ['--retry-failed']),
|
|
216
|
+
}),
|
|
217
|
+
bulkUnpublish: flags.string({
|
|
218
|
+
char: 'b',
|
|
219
|
+
description:
|
|
220
|
+
"This flag is set to true by default. It indicates that contentstack's bulkpublish API will be used for publishing the entries",
|
|
221
|
+
default: 'true',
|
|
222
|
+
hidden: true,
|
|
223
|
+
parse: printFlagDeprecation(['-b', '--bulkUnpublish'], ['--bulk-unpublish']),
|
|
224
|
+
}),
|
|
225
|
+
contentType: flags.string({
|
|
226
|
+
char: 't',
|
|
227
|
+
description: 'Content Type filter',
|
|
228
|
+
hidden: true,
|
|
229
|
+
parse: printFlagDeprecation(['-t', '--contentType'], ['--content-type']),
|
|
230
|
+
}),
|
|
231
|
+
deliveryToken: flags.string({
|
|
232
|
+
char: 'x',
|
|
233
|
+
description: 'Delivery Token for source environment',
|
|
234
|
+
hidden: true,
|
|
235
|
+
parse: printFlagDeprecation(['-x', '--deliveryToken'], ['--delivery-token']),
|
|
236
|
+
}),
|
|
237
|
+
onlyAssets: flags.boolean({
|
|
238
|
+
description: 'Unpublish only assets',
|
|
239
|
+
default: false,
|
|
240
|
+
hidden: true,
|
|
241
|
+
parse: printFlagDeprecation(['--onlyAssets'], ['--only-assets']),
|
|
242
|
+
}),
|
|
243
|
+
onlyEntries: flags.boolean({
|
|
244
|
+
description: 'Unpublish only entries',
|
|
245
|
+
default: false,
|
|
246
|
+
hidden: true,
|
|
247
|
+
parse: printFlagDeprecation(['--onlyEntries'], ['--only-entries']),
|
|
248
|
+
}),
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
UnpublishCommand.examples = [
|
|
252
|
+
'General Usage',
|
|
253
|
+
'csdx cm:stacks:unpublish --bulk-unpublish --content-type [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --alias [MANAGEMENT TOKEN ALIAS] ----delivery-token [DELIVERY TOKEN]',
|
|
254
|
+
'',
|
|
255
|
+
'Using --config or -c flag',
|
|
256
|
+
'Generate a config file at the current working directory using `csdx cm:bulk-publish:configure --alias [ALIAS]`',
|
|
257
|
+
'csdx cm:stacks:unpublish --config [PATH TO CONFIG FILE]',
|
|
258
|
+
'csdx cm:stacks:unpublish -c [PATH TO CONFIG FILE]',
|
|
259
|
+
'',
|
|
260
|
+
'Using --retry-failed flag',
|
|
261
|
+
'csdx cm:stacks:unpublish --retry-failed [LOG FILE NAME]',
|
|
262
|
+
'',
|
|
263
|
+
'No content type',
|
|
264
|
+
'csdx cm:stacks:unpublish --environment [SOURCE ENV] --locale [LOCALE] (Will unpublish all entries from all content types and assets from the source environment)',
|
|
265
|
+
'',
|
|
266
|
+
'Using --only-assets',
|
|
267
|
+
'csdx cm:stacks:unpublish --environment [SOURCE ENV] --locale [LOCALE] --only-assets (Will unpublish only assets from the source environment)',
|
|
268
|
+
'',
|
|
269
|
+
'Using --only-entries',
|
|
270
|
+
'csdx cm:stacks:unpublish --environment [SOURCE ENV] --locale [LOCALE] --only-entries (Will unpublish only entries, all entries, from the source environment)',
|
|
271
|
+
'csdx cm:stacks:unpublish --contentType [CONTENT TYPE] --environment [SOURCE ENV] --locale [LOCALE] --only-entries (Will unpublish only entries, (from CONTENT TYPE) from the source environment)',
|
|
272
|
+
'',
|
|
273
|
+
'Using --branch flag',
|
|
274
|
+
'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]',
|
|
275
|
+
];
|
|
276
|
+
|
|
277
|
+
UnpublishCommand.aliases = ['cm:bulk-publish:unpublish'];
|
|
278
|
+
|
|
279
|
+
UnpublishCommand.usage =
|
|
280
|
+
'csdx cm:stacks:unpublish [-a <value>] [-e <value>] [-c <value>] [-y] [--locale <value>] [--branch <value>] [--retry-failed <value>] [--bulk-unpublish <value>] [--content-type <value>] [--delivery-token <value>] [--only-assets] [--only-entries]';
|
|
281
|
+
|
|
282
|
+
module.exports = UnpublishCommand;
|