@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.
- package/LICENSE +21 -0
- package/README.md +533 -281
- package/oclif.manifest.json +1 -1
- package/package.json +27 -12
- 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 +187 -68
- 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 +60 -99
- package/src/consumer/publish.js +600 -377
- package/src/producer/add-fields.js +209 -189
- package/src/producer/cross-publish.js +195 -136
- package/src/producer/nonlocalized-field-changes.js +235 -216
- package/src/producer/publish-assets.js +104 -98
- package/src/producer/publish-edits.js +126 -113
- package/src/producer/publish-entries.js +135 -112
- package/src/producer/publish-unpublished-env.js +126 -114
- package/src/producer/revert.js +261 -230
- package/src/producer/unpublish.js +175 -137
- package/src/services/publish-only-unpublished.js +130 -0
- package/src/util/client.js +21 -17
- 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 +44 -52
- package/src/commands/cm/bulk-publish/add-fields.js +0 -117
- package/src/commands/cm/bulk-publish/assets.js +0 -117
- package/src/commands/cm/bulk-publish/clear.js +0 -63
- package/src/commands/cm/bulk-publish/configure.js +0 -46
- package/src/commands/cm/bulk-publish/entries.js +0 -125
- package/src/commands/cm/bulk-publish/entry-edits.js +0 -123
- package/src/commands/cm/bulk-publish/nonlocalized-field-changes.js +0 -116
- package/src/commands/cm/bulk-publish/revert.js +0 -81
- package/src/commands/cm/bulk-publish/unpublish.js +0 -164
- package/src/commands/cm/bulk-publish/unpublished-entries.js +0 -122
- package/src/util/request.js +0 -57
|
@@ -3,80 +3,65 @@
|
|
|
3
3
|
/* eslint-disable complexity */
|
|
4
4
|
/* eslint-disable no-console */
|
|
5
5
|
/* eslint-disable camelcase */
|
|
6
|
-
const {getQueue} = require('../util/queue')
|
|
7
|
-
const defaults = require('../config/defaults.json')
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
let bulkUnPublishSet = []
|
|
23
|
-
let bulkUnPulishAssetSet = []
|
|
24
|
-
let logFileName
|
|
25
|
-
let filePath
|
|
6
|
+
const { getQueue } = require('../util/queue');
|
|
7
|
+
const defaults = require('../config/defaults.json');
|
|
8
|
+
const { performBulkUnPublish, UnpublishEntry, UnpublishAsset, initializeLogger } = require('../consumer/publish');
|
|
9
|
+
const retryFailedLogs = require('../util/retryfailed');
|
|
10
|
+
const { validateFile } = require('../util/fs');
|
|
11
|
+
const queue = getQueue();
|
|
12
|
+
const entryQueue = getQueue();
|
|
13
|
+
const assetQueue = getQueue();
|
|
14
|
+
const { Command } = require('@contentstack/cli-command');
|
|
15
|
+
const command = new Command();
|
|
16
|
+
const { isEmpty } = require('../util');
|
|
17
|
+
|
|
18
|
+
let bulkUnPublishSet = [];
|
|
19
|
+
let bulkUnPulishAssetSet = [];
|
|
20
|
+
let logFileName;
|
|
21
|
+
let filePath;
|
|
26
22
|
|
|
27
23
|
function setConfig(conf, bup) {
|
|
28
24
|
if (bup) {
|
|
29
|
-
logFileName = 'bulk-unpublish'
|
|
30
|
-
queue.consumer =
|
|
25
|
+
logFileName = 'bulk-unpublish';
|
|
26
|
+
queue.consumer = performBulkUnPublish;
|
|
31
27
|
} else {
|
|
32
|
-
logFileName = 'unpublish'
|
|
33
|
-
entryQueue.consumer = UnpublishEntry
|
|
34
|
-
assetQueue.consumer = UnpublishAsset
|
|
28
|
+
logFileName = 'unpublish';
|
|
29
|
+
entryQueue.consumer = UnpublishEntry;
|
|
30
|
+
assetQueue.consumer = UnpublishAsset;
|
|
35
31
|
}
|
|
36
|
-
config = conf
|
|
37
|
-
queue.config = conf
|
|
38
|
-
entryQueue.config = conf
|
|
39
|
-
assetQueue.config = conf
|
|
40
|
-
filePath = initializeLogger(logFileName)
|
|
32
|
+
config = conf;
|
|
33
|
+
queue.config = conf;
|
|
34
|
+
entryQueue.config = conf;
|
|
35
|
+
assetQueue.config = conf;
|
|
36
|
+
filePath = initializeLogger(logFileName);
|
|
41
37
|
}
|
|
42
38
|
|
|
43
|
-
let changedFlag = false
|
|
39
|
+
let changedFlag = false;
|
|
44
40
|
|
|
45
41
|
function getQueryParams(filter) {
|
|
46
|
-
let queryString = ''
|
|
47
|
-
Object.keys(filter).forEach(key => {
|
|
42
|
+
let queryString = '';
|
|
43
|
+
Object.keys(filter).forEach((key) => {
|
|
48
44
|
if (filter[key]) {
|
|
49
|
-
queryString = `${queryString}&${key}=${filter[key]}
|
|
45
|
+
queryString = `${queryString}&${key}=${filter[key]}`;
|
|
50
46
|
}
|
|
51
|
-
})
|
|
47
|
+
});
|
|
52
48
|
|
|
53
|
-
return queryString
|
|
49
|
+
return queryString;
|
|
54
50
|
}
|
|
55
51
|
|
|
56
52
|
function bulkAction(stack, items, bulkUnpublish, environment, locale) {
|
|
57
|
-
return new Promise(async resolve => {
|
|
53
|
+
return new Promise(async (resolve) => {
|
|
58
54
|
for (let index = 0; index < items.length; index++) {
|
|
59
|
-
changedFlag = true
|
|
60
|
-
|
|
61
|
-
if (!items[index].data.publish_details) {
|
|
62
|
-
// adding this condition because sometimes
|
|
63
|
-
// item.data.publish_details.locale failes because publish_details is undefined
|
|
64
|
-
items[index].data.publish_details = {}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (items[index].data.publish_details) {
|
|
68
|
-
items[index].data.publish_details.version = items[index].data._version
|
|
69
|
-
}
|
|
55
|
+
changedFlag = true;
|
|
70
56
|
|
|
71
57
|
if (bulkUnpublish) {
|
|
72
58
|
if (bulkUnPublishSet.length < 10 && items[index].type === 'entry_published') {
|
|
73
59
|
bulkUnPublishSet.push({
|
|
74
60
|
uid: items[index].data.uid,
|
|
75
61
|
content_type: items[index].content_type_uid,
|
|
76
|
-
locale: items[index].data.
|
|
77
|
-
version: items[index].data._version,
|
|
62
|
+
locale: items[index].data.locale || 'en-us',
|
|
78
63
|
publish_details: [items[index].data.publish_details] || [],
|
|
79
|
-
})
|
|
64
|
+
});
|
|
80
65
|
}
|
|
81
66
|
|
|
82
67
|
if (bulkUnPulishAssetSet.length < 10 && items[index].type === 'asset_published') {
|
|
@@ -84,138 +69,191 @@ function bulkAction(stack, items, bulkUnpublish, environment, locale) {
|
|
|
84
69
|
uid: items[index].data.uid,
|
|
85
70
|
version: items[index].data._version,
|
|
86
71
|
publish_details: [items[index].data.publish_details] || [],
|
|
87
|
-
})
|
|
72
|
+
});
|
|
88
73
|
}
|
|
89
74
|
|
|
90
75
|
if (bulkUnPulishAssetSet.length === 10) {
|
|
91
76
|
await queue.Enqueue({
|
|
92
|
-
assets: bulkUnPulishAssetSet,
|
|
93
|
-
|
|
94
|
-
|
|
77
|
+
assets: bulkUnPulishAssetSet,
|
|
78
|
+
Type: 'asset',
|
|
79
|
+
locale: locale,
|
|
80
|
+
environments: [environment],
|
|
81
|
+
stack: stack,
|
|
82
|
+
});
|
|
83
|
+
bulkUnPulishAssetSet = [];
|
|
95
84
|
}
|
|
96
85
|
|
|
97
86
|
if (bulkUnPublishSet.length === 10) {
|
|
98
87
|
await queue.Enqueue({
|
|
99
|
-
entries: bulkUnPublishSet,
|
|
100
|
-
|
|
101
|
-
|
|
88
|
+
entries: bulkUnPublishSet,
|
|
89
|
+
locale: locale,
|
|
90
|
+
Type: 'entry',
|
|
91
|
+
environments: [environment],
|
|
92
|
+
stack: stack,
|
|
93
|
+
});
|
|
94
|
+
bulkUnPublishSet = [];
|
|
102
95
|
}
|
|
103
96
|
if (index === items.length - 1 && bulkUnPulishAssetSet.length <= 10 && bulkUnPulishAssetSet.length > 0) {
|
|
104
97
|
await queue.Enqueue({
|
|
105
|
-
assets: bulkUnPulishAssetSet,
|
|
106
|
-
|
|
107
|
-
|
|
98
|
+
assets: bulkUnPulishAssetSet,
|
|
99
|
+
Type: 'asset',
|
|
100
|
+
locale: locale,
|
|
101
|
+
environments: [environment],
|
|
102
|
+
stack: stack,
|
|
103
|
+
});
|
|
104
|
+
bulkUnPulishAssetSet = [];
|
|
108
105
|
}
|
|
109
106
|
|
|
110
107
|
if (index === items.length - 1 && bulkUnPublishSet.length <= 10 && bulkUnPublishSet.length > 0) {
|
|
111
108
|
await queue.Enqueue({
|
|
112
|
-
entries: bulkUnPublishSet,
|
|
113
|
-
|
|
114
|
-
|
|
109
|
+
entries: bulkUnPublishSet,
|
|
110
|
+
locale: locale,
|
|
111
|
+
Type: 'entry',
|
|
112
|
+
environments: [environment],
|
|
113
|
+
stack: stack,
|
|
114
|
+
});
|
|
115
|
+
bulkUnPublishSet = [];
|
|
115
116
|
}
|
|
116
117
|
} else {
|
|
117
118
|
if (items[index].type === 'entry_published') {
|
|
118
119
|
await entryQueue.Enqueue({
|
|
119
|
-
content_type: items[index].content_type_uid,
|
|
120
|
-
|
|
120
|
+
content_type: items[index].content_type_uid,
|
|
121
|
+
publish_details: [items[index].data.publish_details],
|
|
122
|
+
environments: [environment],
|
|
123
|
+
entryUid: items[index].data.uid,
|
|
124
|
+
locale: items[index].data.locale || 'en-us',
|
|
125
|
+
Type: 'entry',
|
|
126
|
+
stack: stack,
|
|
127
|
+
});
|
|
121
128
|
}
|
|
122
129
|
if (items[index].type === 'asset_published') {
|
|
123
130
|
await assetQueue.Enqueue({
|
|
124
|
-
assetUid: items[index].data.uid,
|
|
125
|
-
|
|
131
|
+
assetUid: items[index].data.uid,
|
|
132
|
+
publish_details: [items[index].data.publish_details],
|
|
133
|
+
environments: [environment],
|
|
134
|
+
Type: 'entry',
|
|
135
|
+
stack: stack,
|
|
136
|
+
});
|
|
126
137
|
}
|
|
127
138
|
}
|
|
128
139
|
}
|
|
129
|
-
return resolve()
|
|
130
|
-
})
|
|
140
|
+
return resolve();
|
|
141
|
+
});
|
|
131
142
|
}
|
|
132
143
|
|
|
133
|
-
async function getSyncEntries(
|
|
144
|
+
async function getSyncEntries(
|
|
145
|
+
stack,
|
|
146
|
+
config,
|
|
147
|
+
locale,
|
|
148
|
+
queryParams,
|
|
149
|
+
bulkUnpublish,
|
|
150
|
+
environment,
|
|
151
|
+
deliveryToken,
|
|
152
|
+
paginationToken = null,
|
|
153
|
+
) {
|
|
134
154
|
return new Promise(async (resolve, reject) => {
|
|
135
155
|
try {
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
},
|
|
156
|
+
const tokenDetails = command.getToken(config.alias);
|
|
157
|
+
const queryParamsObj = {};
|
|
158
|
+
const pairs = queryParams.split('&');
|
|
159
|
+
for (let i in pairs) {
|
|
160
|
+
const split = pairs[i].split('=');
|
|
161
|
+
queryParamsObj[decodeURIComponent(split[0])] = decodeURIComponent(split[1]);
|
|
143
162
|
}
|
|
144
|
-
|
|
163
|
+
|
|
164
|
+
const Stack = new command.deliveryAPIClient.Stack({
|
|
165
|
+
api_key: tokenDetails.apiKey,
|
|
166
|
+
delivery_token: deliveryToken,
|
|
167
|
+
environment: queryParamsObj.environment,
|
|
168
|
+
branch: config.branch,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
const syncData = {};
|
|
172
|
+
|
|
173
|
+
if (paginationToken) {
|
|
174
|
+
syncData['pagination_token'] = paginationToken;
|
|
175
|
+
} else {
|
|
176
|
+
syncData['init'] = true;
|
|
177
|
+
}
|
|
178
|
+
if (queryParamsObj.locale) {
|
|
179
|
+
syncData['locale'] = queryParamsObj.locale;
|
|
180
|
+
}
|
|
181
|
+
if (queryParamsObj.type) {
|
|
182
|
+
syncData['type'] = queryParamsObj.type;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const entriesResponse = await Stack.sync(syncData);
|
|
186
|
+
|
|
145
187
|
if (entriesResponse.items.length > 0) {
|
|
146
|
-
await bulkAction(stack, entriesResponse.items, bulkUnpublish, environment, locale)
|
|
188
|
+
await bulkAction(stack, entriesResponse.items, bulkUnpublish, environment, locale);
|
|
147
189
|
}
|
|
148
190
|
if (entriesResponse.items.length === 0) {
|
|
149
|
-
if (!changedFlag) console.log('No Entries/Assets Found published on specified environment')
|
|
150
|
-
return resolve()
|
|
191
|
+
if (!changedFlag) console.log('No Entries/Assets Found published on specified environment');
|
|
192
|
+
return resolve();
|
|
151
193
|
}
|
|
152
194
|
setTimeout(async () => {
|
|
153
|
-
await getSyncEntries(stack, config, locale, queryParams, bulkUnpublish, environment, deliveryToken, null)
|
|
154
|
-
}, 3000)
|
|
195
|
+
await getSyncEntries(stack, config, locale, queryParams, bulkUnpublish, environment, deliveryToken, null);
|
|
196
|
+
}, 3000);
|
|
155
197
|
} catch (error) {
|
|
156
|
-
reject(error)
|
|
198
|
+
reject(error);
|
|
157
199
|
}
|
|
158
|
-
})
|
|
159
|
-
return resolve()
|
|
200
|
+
});
|
|
160
201
|
}
|
|
161
202
|
|
|
162
|
-
async function start(
|
|
203
|
+
async function start(
|
|
204
|
+
{ retryFailed, bulkUnpublish, contentType, locale, environment, deliveryToken, onlyAssets, onlyEntries, f_types },
|
|
205
|
+
stack,
|
|
206
|
+
config,
|
|
207
|
+
) {
|
|
163
208
|
process.on('beforeExit', async () => {
|
|
164
|
-
const isErrorLogEmpty = await isEmpty(`${filePath}.error`)
|
|
165
|
-
const isSuccessLogEmpty = await isEmpty(`${filePath}.success`)
|
|
209
|
+
const isErrorLogEmpty = await isEmpty(`${filePath}.error`);
|
|
210
|
+
const isSuccessLogEmpty = await isEmpty(`${filePath}.success`);
|
|
166
211
|
if (!isErrorLogEmpty) {
|
|
167
|
-
console.log(`The error log for this session is stored at ${filePath}.error`)
|
|
212
|
+
console.log(`The error log for this session is stored at ${filePath}.error`);
|
|
168
213
|
} else if (!isSuccessLogEmpty) {
|
|
169
|
-
console.log(`The success log for this session is stored at ${filePath}.success`)
|
|
214
|
+
console.log(`The success log for this session is stored at ${filePath}.success`);
|
|
170
215
|
}
|
|
171
|
-
process.exit(0)
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
try {
|
|
175
|
-
if (retryFailed) {
|
|
176
|
-
if (typeof retryFailed === 'string' && retryFailed.length > 0) {
|
|
177
|
-
if (!validateFile(retryFailed, ['unpublish', 'bulk-unpublish'])) {
|
|
178
|
-
return false
|
|
179
|
-
}
|
|
216
|
+
process.exit(0);
|
|
217
|
+
});
|
|
180
218
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
await retryFailedLogs(retryFailed, queue, 'bulk')
|
|
186
|
-
} else {
|
|
187
|
-
await retryFailedLogs(retryFailed, {entryQueue, assetQueue}, 'publish')
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
} else {
|
|
191
|
-
let filter = {
|
|
192
|
-
environment,
|
|
193
|
-
locale,
|
|
194
|
-
}
|
|
195
|
-
if (f_types)
|
|
196
|
-
filter.type = f_types
|
|
197
|
-
// filter.type = (f_types) ? f_types : types // types mentioned in the config file (f_types) are given preference
|
|
198
|
-
if (contentType) {
|
|
199
|
-
filter.content_type_uid = contentType
|
|
200
|
-
filter.type = 'entry_published'
|
|
219
|
+
if (retryFailed) {
|
|
220
|
+
if (typeof retryFailed === 'string' && retryFailed.length > 0) {
|
|
221
|
+
if (!validateFile(retryFailed, ['unpublish', 'bulk-unpublish'])) {
|
|
222
|
+
return false;
|
|
201
223
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const queryParams = getQueryParams(filter)
|
|
211
|
-
try {
|
|
212
|
-
await getSyncEntries(stack, config, locale, queryParams, bulkUnpublish, environment, deliveryToken)
|
|
213
|
-
} catch (error) {
|
|
214
|
-
throw error
|
|
224
|
+
|
|
225
|
+
bulkUnpublish = retryFailed.match(new RegExp('bulk')) ? true : false;
|
|
226
|
+
setConfig(config, bulkUnpublish);
|
|
227
|
+
|
|
228
|
+
if (bulkUnpublish) {
|
|
229
|
+
await retryFailedLogs(retryFailed, queue, 'bulk');
|
|
230
|
+
} else {
|
|
231
|
+
await retryFailedLogs(retryFailed, { entryQueue, assetQueue }, 'publish');
|
|
215
232
|
}
|
|
216
233
|
}
|
|
217
|
-
}
|
|
218
|
-
|
|
234
|
+
} else {
|
|
235
|
+
let filter = {
|
|
236
|
+
environment,
|
|
237
|
+
locale,
|
|
238
|
+
};
|
|
239
|
+
if (f_types) {
|
|
240
|
+
filter.type = f_types;
|
|
241
|
+
}
|
|
242
|
+
// filter.type = (f_types) ? f_types : types // types mentioned in the config file (f_types) are given preference
|
|
243
|
+
if (contentType) {
|
|
244
|
+
filter.content_type_uid = contentType;
|
|
245
|
+
filter.type = 'entry_published';
|
|
246
|
+
}
|
|
247
|
+
if (onlyAssets) {
|
|
248
|
+
filter.type = 'asset_published';
|
|
249
|
+
delete filter.content_type_uid;
|
|
250
|
+
}
|
|
251
|
+
if (onlyEntries) {
|
|
252
|
+
filter.type = 'entry_published';
|
|
253
|
+
}
|
|
254
|
+
setConfig(config, bulkUnpublish);
|
|
255
|
+
const queryParams = getQueryParams(filter);
|
|
256
|
+
await getSyncEntries(stack, config, locale, queryParams, bulkUnpublish, environment, deliveryToken);
|
|
219
257
|
}
|
|
220
258
|
}
|
|
221
259
|
|
|
@@ -226,4 +264,4 @@ module.exports = {
|
|
|
226
264
|
setConfig,
|
|
227
265
|
getQueryParams,
|
|
228
266
|
start,
|
|
229
|
-
}
|
|
267
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { cliux } = require('@contentstack/cli-utilities');
|
|
4
|
+
|
|
5
|
+
const { start } = require('../producer/publish-unpublished-env');
|
|
6
|
+
const { prettyPrint, formatError } = require('../util');
|
|
7
|
+
const { getStack } = require('../util/client');
|
|
8
|
+
const store = require('../util/store');
|
|
9
|
+
|
|
10
|
+
const configKey = 'publish_unpublished_env';
|
|
11
|
+
|
|
12
|
+
async function publishOnlyUnpublishedService(UnpublishedEntriesCommand) {
|
|
13
|
+
let config;
|
|
14
|
+
const unpublishedEntriesFlags = flagsAdapter(this.parse(UnpublishedEntriesCommand).flags);
|
|
15
|
+
let updatedFlags;
|
|
16
|
+
try {
|
|
17
|
+
updatedFlags = unpublishedEntriesFlags.config
|
|
18
|
+
? store.updateMissing(configKey, unpublishedEntriesFlags)
|
|
19
|
+
: unpublishedEntriesFlags;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
this.error(error.message, { exit: 2 });
|
|
22
|
+
}
|
|
23
|
+
if (validate.apply(this, [updatedFlags])) {
|
|
24
|
+
let stack;
|
|
25
|
+
if (!updatedFlags.retryFailed) {
|
|
26
|
+
if (!updatedFlags.alias) {
|
|
27
|
+
updatedFlags.alias = await cliux.prompt('Please enter the management token alias to be used');
|
|
28
|
+
}
|
|
29
|
+
updatedFlags.bulkPublish = updatedFlags.bulkPublish === 'false' ? false : true;
|
|
30
|
+
// Validate management token alias.
|
|
31
|
+
try {
|
|
32
|
+
this.getToken(updatedFlags.alias);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
this.error(
|
|
35
|
+
`The configured management token alias ${updatedFlags.alias} has not been added yet. Add it using 'csdx auth:tokens:add -a ${updatedFlags.alias}'`,
|
|
36
|
+
{ exit: 2 },
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
config = {
|
|
40
|
+
alias: updatedFlags.alias,
|
|
41
|
+
host: this.region.cma,
|
|
42
|
+
branch: unpublishedEntriesFlags.branch,
|
|
43
|
+
};
|
|
44
|
+
stack = getStack(config);
|
|
45
|
+
}
|
|
46
|
+
if (await confirmFlags(updatedFlags)) {
|
|
47
|
+
try {
|
|
48
|
+
if (!updatedFlags.retryFailed) {
|
|
49
|
+
await start(updatedFlags, stack, config);
|
|
50
|
+
} else {
|
|
51
|
+
await start(updatedFlags);
|
|
52
|
+
}
|
|
53
|
+
} catch (error) {
|
|
54
|
+
let message = formatError(error);
|
|
55
|
+
this.error(message, { exit: 2 });
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
this.exit(0);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function validate({ contentTypes, environments, sourceEnv, locale, retryFailed }) {
|
|
64
|
+
let missing = [];
|
|
65
|
+
if (retryFailed) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!contentTypes || contentTypes.length === 0) {
|
|
70
|
+
missing.push('Content Types');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!sourceEnv) {
|
|
74
|
+
missing.push('SourceEnv');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (!environments || environments.length === 0) {
|
|
78
|
+
missing.push('Environments');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (!locale) {
|
|
82
|
+
missing.push('Source Locale');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (missing.length > 0) {
|
|
86
|
+
this.error(`${missing.join(', ')} are required for processing this command. Please check --help for more details`, {
|
|
87
|
+
exit: 2,
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function confirmFlags(data) {
|
|
95
|
+
prettyPrint(data);
|
|
96
|
+
if (data.yes) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
return cliux.confirm('Do you want to continue with this configuration ? [yes or no]');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function flagsAdapter(flags) {
|
|
103
|
+
if ('content-types' in flags) {
|
|
104
|
+
flags.contentTypes = flags['content-types'];
|
|
105
|
+
delete flags['content-types'];
|
|
106
|
+
}
|
|
107
|
+
if ('locales' in flags) {
|
|
108
|
+
flags.locale = flags.locales;
|
|
109
|
+
delete flags['locales'];
|
|
110
|
+
}
|
|
111
|
+
if ('source-env' in flags) {
|
|
112
|
+
flags.sourceEnv = flags['source-env'];
|
|
113
|
+
delete flags['source-env'];
|
|
114
|
+
}
|
|
115
|
+
if ('retry-failed' in flags) {
|
|
116
|
+
flags.retryFailed = flags['retry-failed'];
|
|
117
|
+
delete flags['retry-failed'];
|
|
118
|
+
}
|
|
119
|
+
if ('bulk-publish' in flags) {
|
|
120
|
+
flags.bulkPublish = flags['bulk-publish'];
|
|
121
|
+
delete flags['bulk-publish'];
|
|
122
|
+
}
|
|
123
|
+
return flags;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
module.exports = {
|
|
127
|
+
publishOnlyUnpublishedService,
|
|
128
|
+
validate,
|
|
129
|
+
confirmFlags,
|
|
130
|
+
};
|
package/src/util/client.js
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
|
-
const contentstackSdk = require('@contentstack/management')
|
|
2
|
-
const {Command} = require('@contentstack/cli-command')
|
|
3
|
-
const command = new Command()
|
|
1
|
+
const contentstackSdk = require('@contentstack/management');
|
|
2
|
+
const { Command } = require('@contentstack/cli-command');
|
|
3
|
+
const command = new Command();
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const config = new Configstore('contentstack_cli')
|
|
7
|
-
const { formatHostname } = require('../util')
|
|
5
|
+
const { formatHostname } = require('../util');
|
|
8
6
|
|
|
9
7
|
function getStack(data) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
const tokenDetails = command.getToken(data.alias);
|
|
9
|
+
const client = contentstackSdk.client({
|
|
10
|
+
headers: {
|
|
11
|
+
branch: data.branch,
|
|
12
|
+
},
|
|
13
|
+
host: formatHostname(data.host),
|
|
14
|
+
// eslint-disable-next-line no-unused-vars
|
|
15
|
+
logHandler: (_level) => {
|
|
16
|
+
// empty block
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
const stack = client.stack({ api_key: tokenDetails.apiKey, management_token: tokenDetails.token });
|
|
20
|
+
stack.alias = data.alias;
|
|
21
|
+
stack.host = data.host;
|
|
22
|
+
return stack;
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
module.exports = {
|
|
22
|
-
getStack
|
|
23
|
-
}
|
|
26
|
+
getStack,
|
|
27
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const inquirer = require('inquirer');
|
|
4
|
+
|
|
5
|
+
const COMMAND_CODE_MAP = {
|
|
6
|
+
'Publish Entries': 0,
|
|
7
|
+
'Publish Assets': 1,
|
|
8
|
+
'Publish Entries and Assets': 2,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const getSelectedCommand = async () => {
|
|
12
|
+
const inquirerOptions = [{
|
|
13
|
+
type: 'list',
|
|
14
|
+
message: 'Choose one of the following task to execute.',
|
|
15
|
+
choices: Object.keys(COMMAND_CODE_MAP),
|
|
16
|
+
name: 'selectedOption',
|
|
17
|
+
loop: false,
|
|
18
|
+
}];
|
|
19
|
+
const { selectedOption } = await inquirer.prompt(inquirerOptions);
|
|
20
|
+
return COMMAND_CODE_MAP[selectedOption];
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
getSelectedCommand,
|
|
25
|
+
};
|
package/src/util/fs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const chalk = require('chalk');
|
|
3
3
|
const path = require('path');
|
|
4
|
-
const {getLogsDirPath} = require('../util/logger.js')
|
|
4
|
+
const { getLogsDirPath } = require('../util/logger.js');
|
|
5
5
|
|
|
6
6
|
const logsDir = getLogsDirPath();
|
|
7
7
|
|
|
@@ -12,7 +12,7 @@ function doesFileExistInLogsDirectory(filename) {
|
|
|
12
12
|
if (files.indexOf(filename) !== -1) {
|
|
13
13
|
return true;
|
|
14
14
|
}
|
|
15
|
-
throw new Error(`${filename} doesn't exist in logs directory at ${logsDir}`)
|
|
15
|
+
throw new Error(`${filename} doesn't exist in logs directory at ${logsDir}`);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
function validateFile(filename, types) {
|
|
@@ -20,11 +20,11 @@ function validateFile(filename, types) {
|
|
|
20
20
|
const [timestamp, logType, status] = filename.split('.');
|
|
21
21
|
|
|
22
22
|
if (!timestamp || !logType || !status) {
|
|
23
|
-
throw new Error(`${filename} is not a valid log file or the log name has been changed`)
|
|
23
|
+
throw new Error(`${filename} is not a valid log file or the log name has been changed`);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
if (status !== 'success' && status !== 'error') {
|
|
27
|
-
throw new Error(`${filename} is not a valid log file or the log name has been changed`)
|
|
27
|
+
throw new Error(`${filename} is not a valid log file or the log name has been changed`);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
if (logType) {
|
|
@@ -48,19 +48,18 @@ function validateFile(filename, types) {
|
|
|
48
48
|
case 'unpublish':
|
|
49
49
|
case 'revert':
|
|
50
50
|
if (types && types.length > 0) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
throw new Error('Error: The given log file is not an error log file.')
|
|
51
|
+
if (status !== 'error') {
|
|
52
|
+
throw new Error('Error: The given log file is not an error log file.');
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
if(types.indexOf(logType) === -1) {
|
|
57
|
-
let validTypes = '' + types.join(', ')
|
|
58
|
-
throw new Error(`For this operation, the log file should be of the following types: ${validTypes}`)
|
|
55
|
+
if (types.indexOf(logType) === -1) {
|
|
56
|
+
let validTypes = '' + types.join(', ');
|
|
57
|
+
throw new Error(`For this operation, the log file should be of the following types: ${validTypes}`);
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
60
|
return true;
|
|
62
61
|
default:
|
|
63
|
-
throw new Error(`${filename} is not a valid log file or the log name has been changed`)
|
|
62
|
+
throw new Error(`${filename} is not a valid log file or the log name has been changed`);
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
}
|