mcdev 3.0.3 → 3.1.3
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/.eslintrc.json +1 -1
- package/.github/ISSUE_TEMPLATE/bug.yml +75 -0
- package/.github/ISSUE_TEMPLATE/task.md +1 -1
- package/.issuetracker +11 -3
- package/.vscode/settings.json +3 -3
- package/CHANGELOG.md +66 -0
- package/README.md +245 -141
- package/boilerplate/config.json +3 -2
- package/docs/dist/documentation.md +799 -338
- package/lib/Deployer.js +4 -1
- package/lib/MetadataTypeDefinitions.js +1 -0
- package/lib/MetadataTypeInfo.js +1 -0
- package/lib/Retriever.js +30 -14
- package/lib/cli.js +298 -0
- package/lib/index.js +773 -1019
- package/lib/metadataTypes/AccountUser.js +389 -0
- package/lib/metadataTypes/Asset.js +8 -7
- package/lib/metadataTypes/Automation.js +121 -56
- package/lib/metadataTypes/DataExtension.js +133 -97
- package/lib/metadataTypes/DataExtensionField.js +134 -4
- package/lib/metadataTypes/DataExtract.js +9 -5
- package/lib/metadataTypes/EventDefinition.js +9 -5
- package/lib/metadataTypes/FileTransfer.js +9 -5
- package/lib/metadataTypes/ImportFile.js +13 -12
- package/lib/metadataTypes/MetadataType.js +41 -33
- package/lib/metadataTypes/Query.js +2 -3
- package/lib/metadataTypes/Role.js +13 -8
- package/lib/metadataTypes/Script.js +2 -2
- package/lib/metadataTypes/definitions/AccountUser.definition.js +227 -0
- package/lib/metadataTypes/definitions/Asset.definition.js +1 -0
- package/lib/metadataTypes/definitions/DataExtension.definition.js +1 -1
- package/lib/metadataTypes/definitions/ImportFile.definition.js +2 -1
- package/lib/metadataTypes/definitions/Script.definition.js +5 -5
- package/lib/retrieveChangelog.js +96 -0
- package/lib/util/cli.js +4 -6
- package/lib/util/init.git.js +2 -1
- package/lib/util/util.js +17 -0
- package/package.json +18 -22
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -30
- package/img/README.md/troubleshoot-nodejs-postinstall.jpg +0 -0
- package/postinstall.js +0 -41
package/lib/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
'use strict';
|
|
3
2
|
|
|
4
3
|
const Util = require('./util/util');
|
|
@@ -13,1121 +12,876 @@ const Deployer = require('./Deployer');
|
|
|
13
12
|
const MetadataTypeInfo = require('./MetadataTypeInfo');
|
|
14
13
|
const MetadataTypeDefinitions = require('./MetadataTypeDefinitions');
|
|
15
14
|
const Retriever = require('./Retriever');
|
|
16
|
-
const yargs = require('yargs');
|
|
17
15
|
const inquirer = require('inquirer');
|
|
18
16
|
let properties;
|
|
19
17
|
|
|
20
|
-
// CLI framework
|
|
21
|
-
yargs
|
|
22
|
-
.scriptName('mcdev')
|
|
23
|
-
.usage('$0 <command> [options]')
|
|
24
|
-
.command({
|
|
25
|
-
command: 'retrieve [BU] [TYPE]',
|
|
26
|
-
aliases: ['r'],
|
|
27
|
-
desc: 'retrieves metadata of a business unit',
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
builder: (yargs) => {
|
|
30
|
-
yargs
|
|
31
|
-
.positional('BU', {
|
|
32
|
-
type: 'string',
|
|
33
|
-
describe:
|
|
34
|
-
'the business unit to retrieve from (in format "credential name/BU name")',
|
|
35
|
-
})
|
|
36
|
-
.positional('TYPE', {
|
|
37
|
-
type: 'string',
|
|
38
|
-
describe: 'metadata type that shall be exclusively downloaded',
|
|
39
|
-
});
|
|
40
|
-
},
|
|
41
|
-
handler: (argv) => {
|
|
42
|
-
_setLoggingLevel(argv);
|
|
43
|
-
retrieve(argv.BU, argv.TYPE);
|
|
44
|
-
},
|
|
45
|
-
})
|
|
46
|
-
.command({
|
|
47
|
-
command: 'deploy [BU] [TYPE]',
|
|
48
|
-
aliases: ['d'],
|
|
49
|
-
desc: 'deploys local metadata to a business unit',
|
|
50
|
-
builder: (yargs) => {
|
|
51
|
-
yargs
|
|
52
|
-
.positional('BU', {
|
|
53
|
-
type: 'string',
|
|
54
|
-
describe:
|
|
55
|
-
'the business unit to deploy to (in format "credential name/BU name")',
|
|
56
|
-
})
|
|
57
|
-
.positional('TYPE', {
|
|
58
|
-
type: 'string',
|
|
59
|
-
describe: 'metadata type that shall be exclusively uploaded',
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
handler: (argv) => {
|
|
63
|
-
_setLoggingLevel(argv);
|
|
64
|
-
deploy(argv.BU, argv.TYPE);
|
|
65
|
-
},
|
|
66
|
-
})
|
|
67
|
-
.command({
|
|
68
|
-
command: 'init [credentialsName]',
|
|
69
|
-
desc: `creates '${Util.configFileName}' in your root or adds additional credentials to the existing one`,
|
|
70
|
-
builder: (yargs) => {
|
|
71
|
-
yargs.positional('credentialsName', {
|
|
72
|
-
type: 'string',
|
|
73
|
-
describe: 'name of your installed package',
|
|
74
|
-
});
|
|
75
|
-
},
|
|
76
|
-
handler: (argv) => {
|
|
77
|
-
_setLoggingLevel(argv);
|
|
78
|
-
initProject(argv.credentialsName, argv.skipInteraction);
|
|
79
|
-
},
|
|
80
|
-
})
|
|
81
|
-
.command({
|
|
82
|
-
command: 'reloadBUs [credentialsName]',
|
|
83
|
-
aliases: ['rb'],
|
|
84
|
-
desc: 'loads the list of available BUs from the server and saves it to your config',
|
|
85
|
-
builder: (yargs) => {
|
|
86
|
-
yargs.positional('credentialsName', {
|
|
87
|
-
type: 'string',
|
|
88
|
-
describe: 'name of your installed package',
|
|
89
|
-
});
|
|
90
|
-
},
|
|
91
|
-
handler: (argv) => {
|
|
92
|
-
_setLoggingLevel(argv);
|
|
93
|
-
findBUs(argv.credentialsName);
|
|
94
|
-
},
|
|
95
|
-
})
|
|
96
|
-
.command({
|
|
97
|
-
command: 'badKeys [BU]',
|
|
98
|
-
desc: 'lists metadata with random API names in specified Business Unit directory',
|
|
99
|
-
builder: (yargs) => {
|
|
100
|
-
yargs.positional('BU', {
|
|
101
|
-
type: 'string',
|
|
102
|
-
describe: 'the business unit to deploy to',
|
|
103
|
-
});
|
|
104
|
-
},
|
|
105
|
-
handler: (argv) => {
|
|
106
|
-
_setLoggingLevel(argv);
|
|
107
|
-
badKeys(argv.BU);
|
|
108
|
-
},
|
|
109
|
-
})
|
|
110
|
-
.command({
|
|
111
|
-
command: 'document <TYPE> [BU]',
|
|
112
|
-
aliases: ['doc'],
|
|
113
|
-
desc: 'Creates Markdown or HTML documentation for the selected type',
|
|
114
|
-
builder: (yargs) => {
|
|
115
|
-
yargs
|
|
116
|
-
.positional('TYPE', {
|
|
117
|
-
type: 'string',
|
|
118
|
-
describe:
|
|
119
|
-
'metadata type to generate docs for; currently supported: dataExtension, role',
|
|
120
|
-
})
|
|
121
|
-
.positional('BU', {
|
|
122
|
-
type: 'string',
|
|
123
|
-
describe:
|
|
124
|
-
'the business unit to generate docs for (in format "credential name/BU name")',
|
|
125
|
-
});
|
|
126
|
-
},
|
|
127
|
-
handler: (argv) => {
|
|
128
|
-
_setLoggingLevel(argv);
|
|
129
|
-
document(argv.BU, argv.TYPE);
|
|
130
|
-
},
|
|
131
|
-
})
|
|
132
|
-
.command({
|
|
133
|
-
command: 'delete <BU> <TYPE> <EXTERNALKEY>',
|
|
134
|
-
aliases: ['del'],
|
|
135
|
-
desc: 'deletes metadata of selected type and external key',
|
|
136
|
-
builder: (yargs) => {
|
|
137
|
-
yargs
|
|
138
|
-
.positional('BU', {
|
|
139
|
-
type: 'string',
|
|
140
|
-
describe:
|
|
141
|
-
'the business unit to delete from (in format "credential name/BU name")',
|
|
142
|
-
})
|
|
143
|
-
.positional('TYPE', {
|
|
144
|
-
type: 'string',
|
|
145
|
-
describe: 'metadata type to delete from; currently supported: dataExtension',
|
|
146
|
-
})
|
|
147
|
-
.positional('EXTERNALKEY', {
|
|
148
|
-
type: 'string',
|
|
149
|
-
describe: 'the key to delete',
|
|
150
|
-
});
|
|
151
|
-
},
|
|
152
|
-
handler: (argv) => {
|
|
153
|
-
_setLoggingLevel(argv);
|
|
154
|
-
deleteByKey(argv.BU, argv.TYPE, argv.EXTERNALKEY);
|
|
155
|
-
},
|
|
156
|
-
})
|
|
157
|
-
.command({
|
|
158
|
-
command: 'retrieveAsTemplate <BU> <TYPE> <NAME> <MARKET>',
|
|
159
|
-
aliases: ['rt'],
|
|
160
|
-
desc: 'Retrieves a specific metadata file by name for templating',
|
|
161
|
-
builder: (yargs) => {
|
|
162
|
-
yargs
|
|
163
|
-
.positional('BU', {
|
|
164
|
-
type: 'string',
|
|
165
|
-
describe:
|
|
166
|
-
'the business unit to deploy to (in format "credential name/BU name")',
|
|
167
|
-
})
|
|
168
|
-
.positional('TYPE', {
|
|
169
|
-
type: 'string',
|
|
170
|
-
describe: 'metadata type',
|
|
171
|
-
})
|
|
172
|
-
.positional('NAME', {
|
|
173
|
-
type: 'string',
|
|
174
|
-
describe: 'name of the metadata component',
|
|
175
|
-
})
|
|
176
|
-
.positional('MARKET', {
|
|
177
|
-
type: 'string',
|
|
178
|
-
describe: 'market used for reverse building template',
|
|
179
|
-
});
|
|
180
|
-
},
|
|
181
|
-
handler: (argv) => {
|
|
182
|
-
_setLoggingLevel(argv);
|
|
183
|
-
retrieveAsTemplate(argv.BU, argv.TYPE, argv.NAME, argv.MARKET);
|
|
184
|
-
},
|
|
185
|
-
})
|
|
186
|
-
.command({
|
|
187
|
-
command: 'buildDefinition <BU> <TYPE> <NAME> <MARKET>',
|
|
188
|
-
aliases: ['bd'],
|
|
189
|
-
desc: 'builds metadata definition based on template',
|
|
190
|
-
builder: (yargs) => {
|
|
191
|
-
yargs
|
|
192
|
-
.positional('BU', {
|
|
193
|
-
type: 'string',
|
|
194
|
-
describe: 'the business unit to deploy to',
|
|
195
|
-
})
|
|
196
|
-
.positional('TYPE', {
|
|
197
|
-
type: 'string',
|
|
198
|
-
describe: 'metadata type',
|
|
199
|
-
})
|
|
200
|
-
.positional('NAME', {
|
|
201
|
-
type: 'string',
|
|
202
|
-
describe: 'name of the metadata component',
|
|
203
|
-
})
|
|
204
|
-
.positional('MARKET', {
|
|
205
|
-
type: 'string',
|
|
206
|
-
describe: 'the business unit to deploy to',
|
|
207
|
-
});
|
|
208
|
-
},
|
|
209
|
-
handler: (argv) => {
|
|
210
|
-
_setLoggingLevel(argv);
|
|
211
|
-
buildDefinition(argv.BU, argv.TYPE, argv.NAME, argv.MARKET);
|
|
212
|
-
},
|
|
213
|
-
})
|
|
214
|
-
.command({
|
|
215
|
-
command: 'buildDefinitionBulk <LISTNAME> <TYPE> <NAME>',
|
|
216
|
-
aliases: ['bdb'],
|
|
217
|
-
desc: 'builds metadata definition based on template en bulk',
|
|
218
|
-
builder: (yargs) => {
|
|
219
|
-
yargs
|
|
220
|
-
.positional('LISTNAME', {
|
|
221
|
-
type: 'string',
|
|
222
|
-
describe: 'name of list of BU-market combos',
|
|
223
|
-
})
|
|
224
|
-
.positional('TYPE', {
|
|
225
|
-
type: 'string',
|
|
226
|
-
describe: 'metadata type',
|
|
227
|
-
})
|
|
228
|
-
.positional('NAME', {
|
|
229
|
-
type: 'string',
|
|
230
|
-
describe: 'name of the metadata component',
|
|
231
|
-
});
|
|
232
|
-
},
|
|
233
|
-
handler: (argv) => {
|
|
234
|
-
_setLoggingLevel(argv);
|
|
235
|
-
buildDefinitionBulk(argv.LISTNAME, argv.TYPE, argv.NAME);
|
|
236
|
-
},
|
|
237
|
-
})
|
|
238
|
-
.command({
|
|
239
|
-
command: 'selectTypes',
|
|
240
|
-
aliases: ['st'],
|
|
241
|
-
desc: 'lets you choose what metadata types to retrieve',
|
|
242
|
-
handler: (argv) => {
|
|
243
|
-
_setLoggingLevel(argv);
|
|
244
|
-
selectTypes();
|
|
245
|
-
},
|
|
246
|
-
})
|
|
247
|
-
.command({
|
|
248
|
-
command: 'explainTypes',
|
|
249
|
-
aliases: ['et'],
|
|
250
|
-
desc: 'explains metadata types that can be retrieved',
|
|
251
|
-
handler: (argv) => {
|
|
252
|
-
_setLoggingLevel(argv);
|
|
253
|
-
explainTypes();
|
|
254
|
-
},
|
|
255
|
-
})
|
|
256
|
-
.command({
|
|
257
|
-
command: 'createDeltaPkg [range] [filter]',
|
|
258
|
-
aliases: ['cdp'],
|
|
259
|
-
desc: 'Copies commit-based file delta into deploy folder',
|
|
260
|
-
builder: (yargs) => {
|
|
261
|
-
yargs
|
|
262
|
-
.positional('range', {
|
|
263
|
-
type: 'string',
|
|
264
|
-
describe: 'Pull Request target branch or git commit range',
|
|
265
|
-
})
|
|
266
|
-
.positional('filter', {
|
|
267
|
-
type: 'string',
|
|
268
|
-
describe:
|
|
269
|
-
'Disable templating & instead filter by the specified file path (comma separated)',
|
|
270
|
-
});
|
|
271
|
-
},
|
|
272
|
-
handler: createDeltaPkg,
|
|
273
|
-
})
|
|
274
|
-
.command({
|
|
275
|
-
command: 'upgrade',
|
|
276
|
-
aliases: ['up'],
|
|
277
|
-
desc: 'Add NPM dependencies and IDE configuration files to your project',
|
|
278
|
-
handler: (argv) => {
|
|
279
|
-
_setLoggingLevel(argv);
|
|
280
|
-
upgrade(argv.skipInteraction);
|
|
281
|
-
},
|
|
282
|
-
})
|
|
283
|
-
.option('verbose', {
|
|
284
|
-
type: 'boolean',
|
|
285
|
-
description: 'Run with verbose CLI output',
|
|
286
|
-
})
|
|
287
|
-
.option('debug', {
|
|
288
|
-
type: 'boolean',
|
|
289
|
-
description: 'Enable developer & edge-case features',
|
|
290
|
-
})
|
|
291
|
-
.option('silent', {
|
|
292
|
-
type: 'boolean',
|
|
293
|
-
description: 'Only output errors to CLI',
|
|
294
|
-
})
|
|
295
|
-
.option('skipInteraction', {
|
|
296
|
-
alias: ['yes', 'y'],
|
|
297
|
-
description: 'Interactive questions where possible and go with defaults instead',
|
|
298
|
-
})
|
|
299
|
-
.demandCommand(1, 'Please enter a valid command')
|
|
300
|
-
.strict()
|
|
301
|
-
.recommendCommands()
|
|
302
|
-
.wrap(yargs.terminalWidth())
|
|
303
|
-
.epilog('Copyright 2021. Accenture.')
|
|
304
|
-
.help().argv;
|
|
305
|
-
|
|
306
18
|
/**
|
|
307
|
-
*
|
|
308
|
-
* @param {Object} argv yargs parameters
|
|
309
|
-
* @param {String} [argv.range] git commit range
|
|
310
|
-
into deploy directory
|
|
311
|
-
* @param {String} [argv.filter] filter file paths that start with any
|
|
312
|
-
* @param {Boolean} [argv.skipInteraction] allows to skip interactive wizard
|
|
313
|
-
* @returns {void}
|
|
19
|
+
* main class
|
|
314
20
|
*/
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
!properties.options.deployment.sourceTargetMapping ||
|
|
330
|
-
!Object.keys(properties.options.deployment.sourceTargetMapping).length
|
|
331
|
-
) {
|
|
332
|
-
Util.logger.error('Bad configuration of options.deployment.sourceTargetMapping');
|
|
333
|
-
return;
|
|
21
|
+
class Mcdev {
|
|
22
|
+
/**
|
|
23
|
+
* handler for 'mcdev createDeltaPkg
|
|
24
|
+
* @param {Object} argv yargs parameters
|
|
25
|
+
* @param {String} [argv.range] git commit range
|
|
26
|
+
into deploy directory
|
|
27
|
+
* @param {String} [argv.filter] filter file paths that start with any
|
|
28
|
+
* @param {Boolean} [argv.skipInteraction] allows to skip interactive wizard
|
|
29
|
+
* @returns {void}
|
|
30
|
+
*/
|
|
31
|
+
static async createDeltaPkg(argv) {
|
|
32
|
+
properties = properties || File.loadConfigFile();
|
|
33
|
+
if (!Util.checkProperties(properties)) {
|
|
34
|
+
return null;
|
|
334
35
|
}
|
|
335
|
-
|
|
36
|
+
// get source market and source BU from config
|
|
37
|
+
if (argv.filter) {
|
|
38
|
+
return DevOps.createDeltaPkg(properties, argv.range, true, argv.filter);
|
|
39
|
+
} else {
|
|
40
|
+
// If no custom filter was provided, use deployment marketLists & templating
|
|
336
41
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
42
|
+
// check if sourceTargetMapping is valid
|
|
43
|
+
if (
|
|
44
|
+
!properties.options.deployment.sourceTargetMapping ||
|
|
45
|
+
!Object.keys(properties.options.deployment.sourceTargetMapping).length
|
|
46
|
+
) {
|
|
47
|
+
Util.logger.error('Bad configuration of options.deployment.sourceTargetMapping');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const sourceMarketListArr = Object.keys(
|
|
51
|
+
properties.options.deployment.sourceTargetMapping
|
|
52
|
+
);
|
|
344
53
|
|
|
345
|
-
|
|
346
|
-
if
|
|
347
|
-
|
|
54
|
+
for (const sourceML of sourceMarketListArr) {
|
|
55
|
+
// check if sourceTargetMapping has valid values
|
|
56
|
+
// #1 check source marketlist
|
|
57
|
+
try {
|
|
58
|
+
Builder.verifyMarketList(sourceML, properties);
|
|
59
|
+
// remove potentially existing "description"-entry
|
|
60
|
+
delete properties.marketList[sourceML].description;
|
|
61
|
+
|
|
62
|
+
const sourceMarketBuArr = Object.keys(properties.marketList[sourceML]);
|
|
63
|
+
if (sourceMarketBuArr.length !== 1) {
|
|
64
|
+
throw new Error('Only 1 BU is allowed per source marketList');
|
|
65
|
+
}
|
|
66
|
+
if ('string' !== typeof properties.marketList[sourceML][sourceMarketBuArr[0]]) {
|
|
67
|
+
throw new Error('Only 1 market per BU is allowed per source marketList');
|
|
68
|
+
}
|
|
69
|
+
} catch (ex) {
|
|
70
|
+
Util.logger.error('Deployment Source: ' + ex.message);
|
|
71
|
+
return;
|
|
348
72
|
}
|
|
349
|
-
|
|
350
|
-
|
|
73
|
+
// #2 check corresponding target marketList
|
|
74
|
+
let targetML;
|
|
75
|
+
try {
|
|
76
|
+
targetML = properties.options.deployment.sourceTargetMapping[sourceML];
|
|
77
|
+
if ('string' !== typeof targetML) {
|
|
78
|
+
throw new Error(
|
|
79
|
+
'Please define one target marketList per source in deployment.sourceTargetMapping (No arrays allowed)'
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
Builder.verifyMarketList(targetML, properties);
|
|
83
|
+
// remove potentially existing "description"-entry
|
|
84
|
+
delete properties.marketList[targetML].description;
|
|
85
|
+
} catch (ex) {
|
|
86
|
+
Util.logger.error('Deployment Target: ' + ex.message);
|
|
351
87
|
}
|
|
352
|
-
} catch (ex) {
|
|
353
|
-
Util.logger.error('Deployment Source: ' + ex.message);
|
|
354
|
-
return;
|
|
355
88
|
}
|
|
356
|
-
//
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
89
|
+
// all good let's loop a second time for actual execution
|
|
90
|
+
for (const sourceMlName of sourceMarketListArr) {
|
|
91
|
+
const targetMlName =
|
|
92
|
+
properties.options.deployment.sourceTargetMapping[sourceMlName];
|
|
93
|
+
const sourceBU = Object.keys(properties.marketList[sourceMlName])[0];
|
|
94
|
+
const sourceMarket = Object.values(properties.marketList[sourceMlName])[0];
|
|
95
|
+
|
|
96
|
+
const delta = await DevOps.createDeltaPkg(properties, argv.range, false, sourceBU);
|
|
97
|
+
// If only chaing templating and buildDefinition if required
|
|
98
|
+
if (!delta || delta.length === 0) {
|
|
99
|
+
// info/error messages was printed by DevOps.createDeltaPkg() already
|
|
100
|
+
return;
|
|
364
101
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
102
|
+
Util.logger.info('=============');
|
|
103
|
+
|
|
104
|
+
// Put files into maps. One map with BU -> type -> file (for retrieveAsTemplate)
|
|
105
|
+
// Other map only with type -> file (for buildDefinitionBulk)
|
|
106
|
+
const buTypeDelta = {};
|
|
107
|
+
const typeDelta = {};
|
|
108
|
+
delta
|
|
109
|
+
// Only template/build files that were added/updated/moved. no deletions
|
|
110
|
+
// ! doesn't work for folder, because their name parsing doesnt work at the moment
|
|
111
|
+
.filter((file) => file.gitAction !== 'delete' && file.name)
|
|
112
|
+
.forEach((file) => {
|
|
113
|
+
const buPath = `${file._credential}/${file._businessUnit}`;
|
|
114
|
+
if (!buTypeDelta[buPath]) {
|
|
115
|
+
buTypeDelta[buPath] = {};
|
|
116
|
+
}
|
|
117
|
+
if (!buTypeDelta[buPath][file.type]) {
|
|
118
|
+
buTypeDelta[buPath][file.type] = [];
|
|
119
|
+
}
|
|
120
|
+
buTypeDelta[buPath][file.type].push(file.name);
|
|
121
|
+
|
|
122
|
+
if (!typeDelta[file.type]) {
|
|
123
|
+
typeDelta[file.type] = [];
|
|
124
|
+
}
|
|
125
|
+
typeDelta[file.type].push(file.name);
|
|
126
|
+
});
|
|
385
127
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
128
|
+
// Run retrieve as template for each business unit for each type
|
|
129
|
+
Util.logger.info('Retrieve template from Git delta');
|
|
130
|
+
// ! needs to be for (.. in ..) loop so that it gets executed in series
|
|
131
|
+
for (const bu in buTypeDelta) {
|
|
132
|
+
for (const type in buTypeDelta[bu]) {
|
|
133
|
+
Util.logger.info(
|
|
134
|
+
`⚡ mcdev rt ${bu} ${type} "${buTypeDelta[bu][type].join(
|
|
135
|
+
','
|
|
136
|
+
)}" ${sourceMarket}`
|
|
137
|
+
);
|
|
138
|
+
await this.retrieveAsTemplate(
|
|
139
|
+
bu,
|
|
140
|
+
type,
|
|
141
|
+
buTypeDelta[bu][type].join(','),
|
|
142
|
+
sourceMarket
|
|
143
|
+
);
|
|
398
144
|
}
|
|
399
|
-
|
|
400
|
-
buTypeDelta[buPath][file.type] = [];
|
|
401
|
-
}
|
|
402
|
-
buTypeDelta[buPath][file.type].push(file.name);
|
|
145
|
+
}
|
|
403
146
|
|
|
404
|
-
|
|
405
|
-
|
|
147
|
+
// Run build definitions bulk for each type
|
|
148
|
+
Util.logger.info(`- ✔️ Templates created`);
|
|
149
|
+
Util.logger.info('=============');
|
|
150
|
+
Util.logger.info('Build definitions from delta templates');
|
|
151
|
+
if (
|
|
152
|
+
properties.directories.templateBuilds == properties.directories.deploy ||
|
|
153
|
+
(Array.isArray(properties.directories.templateBuilds) &&
|
|
154
|
+
properties.directories.templateBuilds.includes(
|
|
155
|
+
properties.directories.deploy
|
|
156
|
+
))
|
|
157
|
+
) {
|
|
158
|
+
let responses;
|
|
159
|
+
if (!argv.skipInteraction) {
|
|
160
|
+
// deploy folder is in targets for definition creation
|
|
161
|
+
// recommend to purge their content first
|
|
162
|
+
const questions = [
|
|
163
|
+
{
|
|
164
|
+
type: 'confirm',
|
|
165
|
+
name: 'isPurgeDeployFolder',
|
|
166
|
+
message:
|
|
167
|
+
'Do you want to empty the deploy folder (ensures no files from previous deployments remain)?',
|
|
168
|
+
default: true,
|
|
169
|
+
},
|
|
170
|
+
];
|
|
171
|
+
responses = await new Promise((resolve) => {
|
|
172
|
+
inquirer.prompt(questions).then((answers) => {
|
|
173
|
+
resolve(answers);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
406
176
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
for (const type in buTypeDelta[bu]) {
|
|
177
|
+
if (argv.skipInteraction || responses.isPurgeDeployFolders) {
|
|
178
|
+
// Clear output folder structure for selected sub-type
|
|
179
|
+
File.removeSync(File.normalizePath([properties.directories.deploy]));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const bdPromises = [];
|
|
183
|
+
for (const type in typeDelta) {
|
|
415
184
|
Util.logger.info(
|
|
416
|
-
`⚡ mcdev
|
|
417
|
-
','
|
|
418
|
-
)}" ${sourceMarket}`
|
|
185
|
+
`⚡ mcdev bdb ${targetMlName} ${type} "${typeDelta[type].join(',')}"`
|
|
419
186
|
);
|
|
420
|
-
await
|
|
421
|
-
|
|
422
|
-
type,
|
|
423
|
-
buTypeDelta[bu][type].join(','),
|
|
424
|
-
sourceMarket
|
|
187
|
+
// omitting "await" to speed up creation
|
|
188
|
+
bdPromises.push(
|
|
189
|
+
this.buildDefinitionBulk(targetMlName, type, typeDelta[type].join(','))
|
|
425
190
|
);
|
|
426
191
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
// recommend to purge their content first
|
|
442
|
-
const questions = [
|
|
443
|
-
{
|
|
444
|
-
type: 'confirm',
|
|
445
|
-
name: 'isPurgeDeployFolder',
|
|
446
|
-
message:
|
|
447
|
-
'Do you want to empty the deploy folder (ensures no files from previous deployments remain)?',
|
|
448
|
-
default: true,
|
|
449
|
-
},
|
|
450
|
-
];
|
|
451
|
-
responses = await new Promise((resolve) => {
|
|
452
|
-
inquirer.prompt(questions).then((answers) => {
|
|
453
|
-
resolve(answers);
|
|
454
|
-
});
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
|
-
if (argv.skipInteraction || responses.isPurgeDeployFolders) {
|
|
458
|
-
// Clear output folder structure for selected sub-type
|
|
459
|
-
File.removeSync(File.normalizePath([properties.directories.deploy]));
|
|
192
|
+
await Promise.all(bdPromises);
|
|
193
|
+
Util.logger.info(`- ✔️ Deploy defintions created`);
|
|
194
|
+
if (
|
|
195
|
+
properties.directories.templateBuilds == properties.directories.deploy ||
|
|
196
|
+
(Array.isArray(properties.directories.templateBuilds) &&
|
|
197
|
+
properties.directories.templateBuilds.includes(
|
|
198
|
+
properties.directories.deploy
|
|
199
|
+
))
|
|
200
|
+
) {
|
|
201
|
+
Util.logger.info(`You can now run deploy on the prepared BUs`);
|
|
202
|
+
} else {
|
|
203
|
+
Util.logger.info(
|
|
204
|
+
`Your templated defintions are now ready to be copied into the deploy folder. Hint: You can have this auto-copied if you adjust directories.templateBuilds in your config.`
|
|
205
|
+
);
|
|
460
206
|
}
|
|
461
207
|
}
|
|
462
|
-
const bdPromises = [];
|
|
463
|
-
for (const type in typeDelta) {
|
|
464
|
-
Util.logger.info(
|
|
465
|
-
`⚡ mcdev bdb ${targetMlName} ${type} "${typeDelta[type].join(',')}"`
|
|
466
|
-
);
|
|
467
|
-
// omitting "await" to speed up creation
|
|
468
|
-
bdPromises.push(buildDefinitionBulk(targetMlName, type, typeDelta[type].join(',')));
|
|
469
|
-
}
|
|
470
|
-
await Promise.all(bdPromises);
|
|
471
|
-
Util.logger.info(`- ✔️ Deploy defintions created`);
|
|
472
|
-
if (
|
|
473
|
-
properties.directories.templateBuilds == properties.directories.deploy ||
|
|
474
|
-
(Array.isArray(properties.directories.templateBuilds) &&
|
|
475
|
-
properties.directories.templateBuilds.includes(properties.directories.deploy))
|
|
476
|
-
) {
|
|
477
|
-
Util.logger.info(`You can now run deploy on the prepared BUs`);
|
|
478
|
-
} else {
|
|
479
|
-
Util.logger.info(
|
|
480
|
-
`Your templated defintions are now ready to be copied into the deploy folder. Hint: You can have this auto-copied if you adjust directories.templateBuilds in your config.`
|
|
481
|
-
);
|
|
482
|
-
}
|
|
483
208
|
}
|
|
484
209
|
}
|
|
485
|
-
}
|
|
486
210
|
|
|
487
|
-
/**
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
/**
|
|
517
|
-
* @returns {Promise} .
|
|
518
|
-
*/
|
|
519
|
-
async function selectTypes() {
|
|
520
|
-
properties = properties || File.loadConfigFile();
|
|
521
|
-
if (!Util.checkProperties(properties)) {
|
|
522
|
-
return null;
|
|
523
|
-
}
|
|
524
|
-
await Cli.selectTypes(properties);
|
|
525
|
-
}
|
|
526
|
-
/**
|
|
527
|
-
* @returns {Promise} .
|
|
528
|
-
*/
|
|
529
|
-
function explainTypes() {
|
|
530
|
-
Cli.explainTypes();
|
|
531
|
-
}
|
|
532
|
-
/**
|
|
533
|
-
* @param {Boolean|Object} [skipInteraction] signals what to insert automatically for things usually asked via wizard
|
|
534
|
-
* @returns {Promise} .
|
|
535
|
-
*/
|
|
536
|
-
async function upgrade(skipInteraction) {
|
|
537
|
-
properties = properties || File.loadConfigFile();
|
|
538
|
-
if (!properties) {
|
|
539
|
-
Util.logger.error('No config found. Please run mcdev init');
|
|
540
|
-
return;
|
|
541
|
-
}
|
|
542
|
-
if ((await InitGit.initGitRepo(skipInteraction)).status === 'error') {
|
|
543
|
-
return;
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
Init.upgradeProject(properties, false);
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
/**
|
|
550
|
-
* Retrieve all metadata from the specified business unit into the local file system.
|
|
551
|
-
* @param {String} businessUnit references credentials from properties.json
|
|
552
|
-
* @param {String} [selectedType] limit retrieval to given metadata type
|
|
553
|
-
* @returns {Promise<void>} -
|
|
554
|
-
*/
|
|
555
|
-
async function retrieve(businessUnit, selectedType) {
|
|
556
|
-
Util.logger.info('mcdev:: Retrieve');
|
|
557
|
-
properties = properties || File.loadConfigFile();
|
|
558
|
-
if (!Util.checkProperties(properties)) {
|
|
559
|
-
// return null here to avoid seeing 2 error messages for the same issue
|
|
560
|
-
return null;
|
|
561
|
-
}
|
|
562
|
-
const [type, subType] = selectedType ? selectedType.split('-') : [];
|
|
563
|
-
if (type && !MetadataTypeInfo[type]) {
|
|
564
|
-
Util.logger.error(`:: '${type}' is not a valid metadata type`);
|
|
565
|
-
return;
|
|
566
|
-
} else if (
|
|
567
|
-
type &&
|
|
568
|
-
subType &&
|
|
569
|
-
(!MetadataTypeInfo[type] || !MetadataTypeDefinitions[type].subTypes.includes(subType))
|
|
570
|
-
) {
|
|
571
|
-
Util.logger.error(`:: '${selectedType}' is not a valid metadata type`);
|
|
572
|
-
return;
|
|
211
|
+
/**
|
|
212
|
+
* configures what is displayed in the console
|
|
213
|
+
* @param {object} argv list of command line parameters given by user
|
|
214
|
+
* @param {Boolean} [argv.silent] only errors printed to CLI
|
|
215
|
+
* @param {Boolean} [argv.verbose] chatty user CLI output
|
|
216
|
+
* @param {Boolean} [argv.debug] enables developer output & features
|
|
217
|
+
* @returns {void}
|
|
218
|
+
*/
|
|
219
|
+
static setLoggingLevel(argv) {
|
|
220
|
+
if (argv.silent) {
|
|
221
|
+
// only errors printed to CLI
|
|
222
|
+
Util.logger.level = 'error';
|
|
223
|
+
Util.loggerTransports.console.level = 'error';
|
|
224
|
+
} else if (argv.verbose) {
|
|
225
|
+
// chatty user cli logs
|
|
226
|
+
Util.logger.level = 'verbose';
|
|
227
|
+
Util.loggerTransports.console.level = 'verbose';
|
|
228
|
+
} else {
|
|
229
|
+
// default user cli logs
|
|
230
|
+
// TODO to be switched to "warn" when cli-process is integrated
|
|
231
|
+
Util.logger.level = 'info';
|
|
232
|
+
Util.loggerTransports.console.level = 'info';
|
|
233
|
+
}
|
|
234
|
+
if (argv.debug) {
|
|
235
|
+
// enables developer output & features. no change to actual logs
|
|
236
|
+
Util.logger.level = 'debug';
|
|
237
|
+
}
|
|
573
238
|
}
|
|
574
239
|
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
await _retrieveBU(cred, bu, selectedType);
|
|
583
|
-
counter_credBu++;
|
|
584
|
-
Util.restartLogger();
|
|
585
|
-
}
|
|
586
|
-
counter_credTotal += counter_credBu;
|
|
587
|
-
Util.logger.info(`\n:: ${counter_credBu} BUs for ${cred}\n`);
|
|
240
|
+
/**
|
|
241
|
+
* @returns {Promise} .
|
|
242
|
+
*/
|
|
243
|
+
static async selectTypes() {
|
|
244
|
+
properties = properties || File.loadConfigFile();
|
|
245
|
+
if (!Util.checkProperties(properties)) {
|
|
246
|
+
return null;
|
|
588
247
|
}
|
|
589
|
-
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
}
|
|
248
|
+
await Cli.selectTypes(properties);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* @returns {Promise} .
|
|
252
|
+
*/
|
|
253
|
+
static explainTypes() {
|
|
254
|
+
Cli.explainTypes();
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* @param {Boolean|Object} [skipInteraction] signals what to insert automatically for things usually asked via wizard
|
|
258
|
+
* @returns {Promise} .
|
|
259
|
+
*/
|
|
260
|
+
static async upgrade(skipInteraction) {
|
|
261
|
+
properties = properties || File.loadConfigFile();
|
|
262
|
+
if (!properties) {
|
|
263
|
+
Util.logger.error('No config found. Please run mcdev init');
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if ((await InitGit.initGitRepo(skipInteraction)).status === 'error') {
|
|
267
|
+
return;
|
|
610
268
|
}
|
|
611
269
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
270
|
+
Init.upgradeProject(properties, false);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Retrieve all metadata from the specified business unit into the local file system.
|
|
275
|
+
* @param {String} businessUnit references credentials from properties.json
|
|
276
|
+
* @param {String} [selectedType] limit retrieval to given metadata type
|
|
277
|
+
* @param {boolean} [changelogOnly] skip saving, only create json in memory
|
|
278
|
+
* @returns {Promise<Object>} -
|
|
279
|
+
*/
|
|
280
|
+
static async retrieve(businessUnit, selectedType, changelogOnly) {
|
|
281
|
+
Util.logger.info('mcdev:: Retrieve');
|
|
282
|
+
properties = properties || File.loadConfigFile();
|
|
283
|
+
if (!Util.checkProperties(properties)) {
|
|
284
|
+
// return null here to avoid seeing 2 error messages for the same issue
|
|
285
|
+
return null;
|
|
624
286
|
}
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* helper for retrieve()
|
|
629
|
-
* @param {String} cred name of Credential
|
|
630
|
-
* @param {String} bu name of BU
|
|
631
|
-
* @param {String} [selectedType] limit retrieval to given metadata type/subtype
|
|
632
|
-
* @returns {Promise} ensure that BUs are worked on sequentially
|
|
633
|
-
*/
|
|
634
|
-
async function _retrieveBU(cred, bu, selectedType) {
|
|
635
|
-
properties = properties || File.loadConfigFile();
|
|
636
|
-
const buObject = await Cli.getCredentialObject(
|
|
637
|
-
properties,
|
|
638
|
-
cred !== null ? cred + '/' + bu : null,
|
|
639
|
-
null,
|
|
640
|
-
true
|
|
641
|
-
);
|
|
642
|
-
if (buObject !== null) {
|
|
643
|
-
cred = buObject.credential;
|
|
644
|
-
bu = buObject.businessUnit;
|
|
645
|
-
Util.logger.info(`\n:: Retrieving ${cred}/${bu}\n`);
|
|
646
|
-
let retrieveTypesArr;
|
|
647
287
|
const [type, subType] = selectedType ? selectedType.split('-') : [];
|
|
648
|
-
if (
|
|
288
|
+
if (type && !MetadataTypeInfo[type]) {
|
|
289
|
+
Util.logger.error(`:: '${type}' is not a valid metadata type`);
|
|
290
|
+
return;
|
|
291
|
+
} else if (
|
|
649
292
|
type &&
|
|
650
293
|
subType &&
|
|
651
|
-
MetadataTypeInfo[type]
|
|
652
|
-
MetadataTypeDefinitions[type].subTypes.includes(subType)
|
|
294
|
+
(!MetadataTypeInfo[type] || !MetadataTypeDefinitions[type].subTypes.includes(subType))
|
|
653
295
|
) {
|
|
654
|
-
|
|
655
|
-
File.removeSync(
|
|
656
|
-
File.normalizePath([properties.directories.retrieve, cred, bu, type, subType])
|
|
657
|
-
);
|
|
658
|
-
retrieveTypesArr = [selectedType];
|
|
659
|
-
} else if (type && MetadataTypeInfo[type]) {
|
|
660
|
-
// Clear output folder structure for selected type
|
|
661
|
-
File.removeSync(File.normalizePath([properties.directories.retrieve, cred, bu, type]));
|
|
662
|
-
retrieveTypesArr = [type];
|
|
663
|
-
} else {
|
|
664
|
-
// Clear output folder structure
|
|
665
|
-
File.removeSync(File.normalizePath([properties.directories.retrieve, cred, bu]));
|
|
666
|
-
// assume no type was given and config settings are used instead:
|
|
667
|
-
// removes subtypes and removes duplicates
|
|
668
|
-
retrieveTypesArr = [
|
|
669
|
-
...new Set(properties.metaDataTypes.retrieve.map((type) => type.split('-')[0])),
|
|
670
|
-
];
|
|
671
|
-
}
|
|
672
|
-
let client;
|
|
673
|
-
try {
|
|
674
|
-
client = await Util.getETClient(buObject);
|
|
675
|
-
} catch (ex) {
|
|
676
|
-
Util.logger.error(ex.message);
|
|
296
|
+
Util.logger.error(`:: '${selectedType}' is not a valid metadata type`);
|
|
677
297
|
return;
|
|
678
298
|
}
|
|
679
|
-
const retriever = new Retriever(properties, buObject, client);
|
|
680
299
|
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
300
|
+
if (businessUnit === '*') {
|
|
301
|
+
Util.logger.info('\n:: Retrieving all BUs for all credentials');
|
|
302
|
+
let counter_credTotal = 0;
|
|
303
|
+
for (const cred in properties.credentials) {
|
|
304
|
+
Util.logger.info(`\n:: Retrieving all BUs for ${cred}`);
|
|
305
|
+
let counter_credBu = 0;
|
|
306
|
+
for (const bu in properties.credentials[cred].businessUnits) {
|
|
307
|
+
await this._retrieveBU(cred, bu, selectedType);
|
|
308
|
+
counter_credBu++;
|
|
309
|
+
Util.restartLogger();
|
|
310
|
+
}
|
|
311
|
+
counter_credTotal += counter_credBu;
|
|
312
|
+
Util.logger.info(`\n:: ${counter_credBu} BUs for ${cred}\n`);
|
|
690
313
|
}
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
314
|
+
Util.logger.info(`\n:: ${counter_credTotal} BUs in total\n`);
|
|
315
|
+
} else {
|
|
316
|
+
let [cred, bu] = businessUnit ? businessUnit.split('/') : [null, null];
|
|
317
|
+
// to allow all-BU via user selection we need to run this here already
|
|
318
|
+
if (
|
|
319
|
+
properties.credentials &&
|
|
320
|
+
(!properties.credentials[cred] ||
|
|
321
|
+
(bu !== '*' && properties.credentials[cred].businessUnits[bu]))
|
|
322
|
+
) {
|
|
323
|
+
const buObject = await Cli.getCredentialObject(
|
|
324
|
+
properties,
|
|
325
|
+
cred !== null ? cred + '/' + bu : null,
|
|
326
|
+
null,
|
|
327
|
+
true
|
|
328
|
+
);
|
|
329
|
+
if (buObject !== null) {
|
|
330
|
+
cred = buObject.credential;
|
|
331
|
+
bu = buObject.businessUnit;
|
|
332
|
+
} else {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (bu === '*' && properties.credentials && properties.credentials[cred]) {
|
|
338
|
+
Util.logger.info(`\n:: Retrieving all BUs for ${cred}`);
|
|
339
|
+
let counter_credBu = 0;
|
|
340
|
+
for (const bu in properties.credentials[cred].businessUnits) {
|
|
341
|
+
await this._retrieveBU(cred, bu, selectedType);
|
|
342
|
+
counter_credBu++;
|
|
343
|
+
Util.restartLogger();
|
|
344
|
+
}
|
|
345
|
+
Util.logger.info(`\n:: ${counter_credBu} BUs for ${cred}\n`);
|
|
346
|
+
} else {
|
|
347
|
+
// retrieve a single BU; return
|
|
348
|
+
const retrieveChangelog = await this._retrieveBU(
|
|
349
|
+
cred,
|
|
350
|
+
bu,
|
|
351
|
+
selectedType,
|
|
352
|
+
changelogOnly
|
|
353
|
+
);
|
|
354
|
+
if (changelogOnly) {
|
|
355
|
+
return retrieveChangelog;
|
|
356
|
+
}
|
|
357
|
+
Util.logger.info(`:: Done\n`);
|
|
696
358
|
}
|
|
697
359
|
}
|
|
698
360
|
}
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
async
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
361
|
+
/**
|
|
362
|
+
* helper for retrieve()
|
|
363
|
+
* @param {String} cred name of Credential
|
|
364
|
+
* @param {String} bu name of BU
|
|
365
|
+
* @param {String} [selectedType] limit retrieval to given metadata type/subtype
|
|
366
|
+
* @param {boolean} [changelogOnly] skip saving, only create json in memory
|
|
367
|
+
* @returns {Promise<Object>} ensure that BUs are worked on sequentially
|
|
368
|
+
*/
|
|
369
|
+
static async _retrieveBU(cred, bu, selectedType, changelogOnly) {
|
|
370
|
+
properties = properties || File.loadConfigFile();
|
|
371
|
+
const buObject = await Cli.getCredentialObject(
|
|
372
|
+
properties,
|
|
373
|
+
cred !== null ? cred + '/' + bu : null,
|
|
374
|
+
null,
|
|
375
|
+
true
|
|
376
|
+
);
|
|
377
|
+
if (buObject !== null) {
|
|
378
|
+
cred = buObject.credential;
|
|
379
|
+
bu = buObject.businessUnit;
|
|
380
|
+
Util.logger.info(`\n:: Retrieving ${cred}/${bu}\n`);
|
|
381
|
+
let retrieveTypesArr;
|
|
382
|
+
const [type, subType] = selectedType ? selectedType.split('-') : [];
|
|
383
|
+
if (
|
|
384
|
+
type &&
|
|
385
|
+
subType &&
|
|
386
|
+
MetadataTypeInfo[type] &&
|
|
387
|
+
MetadataTypeDefinitions[type].subTypes.includes(subType)
|
|
388
|
+
) {
|
|
389
|
+
// Clear output folder structure for selected sub-type
|
|
390
|
+
File.removeSync(
|
|
391
|
+
File.normalizePath([properties.directories.retrieve, cred, bu, type, subType])
|
|
392
|
+
);
|
|
393
|
+
retrieveTypesArr = [selectedType];
|
|
394
|
+
} else if (type && MetadataTypeInfo[type]) {
|
|
395
|
+
// Clear output folder structure for selected type
|
|
396
|
+
File.removeSync(
|
|
397
|
+
File.normalizePath([properties.directories.retrieve, cred, bu, type])
|
|
398
|
+
);
|
|
399
|
+
retrieveTypesArr = [type];
|
|
400
|
+
} else {
|
|
401
|
+
// Clear output folder structure
|
|
402
|
+
File.removeSync(File.normalizePath([properties.directories.retrieve, cred, bu]));
|
|
403
|
+
// assume no type was given and config settings are used instead:
|
|
404
|
+
// removes subtypes and removes duplicates
|
|
405
|
+
retrieveTypesArr = [
|
|
406
|
+
...new Set(properties.metaDataTypes.retrieve.map((type) => type.split('-')[0])),
|
|
407
|
+
];
|
|
408
|
+
}
|
|
409
|
+
let client;
|
|
410
|
+
try {
|
|
411
|
+
client = await Util.getETClient(buObject);
|
|
412
|
+
} catch (ex) {
|
|
413
|
+
Util.logger.error(ex.message);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
const retriever = new Retriever(properties, buObject, client);
|
|
417
|
+
|
|
418
|
+
try {
|
|
419
|
+
// await is required or the calls end up conflicting
|
|
420
|
+
const retrieveChangelog = await retriever.retrieve(
|
|
421
|
+
retrieveTypesArr,
|
|
422
|
+
null,
|
|
423
|
+
null,
|
|
424
|
+
changelogOnly
|
|
425
|
+
);
|
|
426
|
+
if (changelogOnly) {
|
|
427
|
+
return retrieveChangelog;
|
|
428
|
+
}
|
|
429
|
+
if (properties.options.documentOnRetrieve) {
|
|
430
|
+
// todo: find the underlying async issue that makes this wait necessary
|
|
431
|
+
await new Promise((resolve) => {
|
|
432
|
+
setTimeout(() => resolve('done!'), 1000);
|
|
433
|
+
});
|
|
434
|
+
await this.badKeys(`${cred}/${bu}`);
|
|
435
|
+
}
|
|
436
|
+
} catch (ex) {
|
|
437
|
+
Util.logger.error('mcdev.retrieve failed: ' + ex.message);
|
|
438
|
+
Util.logger.debug(ex.stack);
|
|
439
|
+
if (Util.logger.level === 'debug') {
|
|
440
|
+
console.log(ex.stack);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
719
443
|
}
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* helper for deploy()
|
|
447
|
+
* @param {String} cred name of Credential
|
|
448
|
+
* @param {String} bu name of BU
|
|
449
|
+
* @param {String} [type] limit deployment to given metadata type
|
|
450
|
+
* @returns {Promise} ensure that BUs are worked on sequentially
|
|
451
|
+
*/
|
|
452
|
+
static async _deployBU(cred, bu, type) {
|
|
453
|
+
const buPath = `${cred}/${bu}`;
|
|
454
|
+
Util.logger.info(`::Deploying ${buPath}`);
|
|
455
|
+
properties = properties || File.loadConfigFile();
|
|
456
|
+
const buObject = await Cli.getCredentialObject(properties, buPath, null, true);
|
|
457
|
+
if (buObject !== null) {
|
|
458
|
+
let client;
|
|
459
|
+
try {
|
|
460
|
+
client = await Util.getETClient(buObject);
|
|
461
|
+
} catch (ex) {
|
|
462
|
+
Util.logger.error(ex.message);
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
const deployer = new Deployer(properties, buObject, client, type);
|
|
466
|
+
try {
|
|
467
|
+
// await is required or the calls end up conflicting
|
|
468
|
+
await deployer.deploy();
|
|
469
|
+
} catch (ex) {
|
|
470
|
+
Util.logger.error('mcdev.deploy failed: ' + ex.message);
|
|
471
|
+
Util.logger.debug(ex.stack);
|
|
472
|
+
if (Util.logger.level === 'debug') {
|
|
473
|
+
console.log(ex.stack);
|
|
474
|
+
}
|
|
729
475
|
}
|
|
730
476
|
}
|
|
731
477
|
}
|
|
732
|
-
}
|
|
733
478
|
|
|
734
|
-
/**
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
async
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
const [type, subType] = selectedType ? selectedType.split('-') : [];
|
|
745
|
-
if (type && !MetadataTypeInfo[type]) {
|
|
746
|
-
Util.logger.error(`:: '${type}' is not a valid metadata type`);
|
|
747
|
-
return;
|
|
748
|
-
} else if (
|
|
749
|
-
type &&
|
|
750
|
-
subType &&
|
|
751
|
-
(!MetadataTypeInfo[type] || !MetadataTypeDefinitions[type].subTypes.includes(subType))
|
|
752
|
-
) {
|
|
753
|
-
Util.logger.error(`:: '${selectedType}' is not a valid metadata type`);
|
|
754
|
-
return;
|
|
755
|
-
}
|
|
756
|
-
let counter_credBu = 0;
|
|
757
|
-
if (businessUnit === '*') {
|
|
758
|
-
// all credentials and all BUs shall be deployed to
|
|
759
|
-
const deployFolders = await File.readDirectories(properties.directories.deploy, 2, false);
|
|
760
|
-
for (const buPath of deployFolders.filter((r) => r.includes('/'))) {
|
|
761
|
-
const [cred, bu] = buPath.split('/');
|
|
762
|
-
await _deployBU(cred, bu, type);
|
|
763
|
-
counter_credBu++;
|
|
764
|
-
Util.logger.info('');
|
|
765
|
-
Util.restartLogger();
|
|
766
|
-
}
|
|
767
|
-
} else {
|
|
768
|
-
// anything but "*" passed in
|
|
769
|
-
let [cred, bu] = businessUnit ? businessUnit.split('/') : [null, null];
|
|
479
|
+
/**
|
|
480
|
+
* Deploys all metadata located in the 'deploy' directory to the specified business unit
|
|
481
|
+
* @param {String} businessUnit references credentials from properties.json
|
|
482
|
+
* @param {String} [selectedType] limit deployment to given metadata type
|
|
483
|
+
* @returns {Promise<void>} -
|
|
484
|
+
*/
|
|
485
|
+
static async deploy(businessUnit, selectedType) {
|
|
486
|
+
Util.logger.info('mcdev:: Deploy');
|
|
487
|
+
properties = properties || File.loadConfigFile();
|
|
770
488
|
|
|
771
|
-
|
|
772
|
-
if (
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
489
|
+
const [type, subType] = selectedType ? selectedType.split('-') : [];
|
|
490
|
+
if (type && !MetadataTypeInfo[type]) {
|
|
491
|
+
Util.logger.error(`:: '${type}' is not a valid metadata type`);
|
|
492
|
+
return;
|
|
493
|
+
} else if (
|
|
494
|
+
type &&
|
|
495
|
+
subType &&
|
|
496
|
+
(!MetadataTypeInfo[type] || !MetadataTypeDefinitions[type].subTypes.includes(subType))
|
|
776
497
|
) {
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
cred !== null ? cred + '/' + bu : null,
|
|
780
|
-
null,
|
|
781
|
-
true
|
|
782
|
-
);
|
|
783
|
-
if (buObject !== null) {
|
|
784
|
-
cred = buObject.credential;
|
|
785
|
-
bu = buObject.businessUnit;
|
|
786
|
-
} else {
|
|
787
|
-
return;
|
|
788
|
-
}
|
|
498
|
+
Util.logger.error(`:: '${selectedType}' is not a valid metadata type`);
|
|
499
|
+
return;
|
|
789
500
|
}
|
|
790
|
-
|
|
791
|
-
if (
|
|
792
|
-
//
|
|
793
|
-
Util.logger.info(`\n:: Deploying all BUs for ${cred}`);
|
|
794
|
-
let counter_credBu = 0;
|
|
795
|
-
// for (const bu in properties.credentials[cred].businessUnits) {
|
|
501
|
+
let counter_credBu = 0;
|
|
502
|
+
if (businessUnit === '*') {
|
|
503
|
+
// all credentials and all BUs shall be deployed to
|
|
796
504
|
const deployFolders = await File.readDirectories(
|
|
797
|
-
|
|
798
|
-
|
|
505
|
+
properties.directories.deploy,
|
|
506
|
+
2,
|
|
799
507
|
false
|
|
800
508
|
);
|
|
801
|
-
for (const buPath of deployFolders) {
|
|
802
|
-
|
|
509
|
+
for (const buPath of deployFolders.filter((r) => r.includes('/'))) {
|
|
510
|
+
const [cred, bu] = buPath.split('/');
|
|
511
|
+
await this._deployBU(cred, bu, type);
|
|
803
512
|
counter_credBu++;
|
|
804
513
|
Util.logger.info('');
|
|
805
514
|
Util.restartLogger();
|
|
806
515
|
}
|
|
807
|
-
Util.logger.info(`\n:: ${counter_credBu} BUs for ${cred}\n`);
|
|
808
516
|
} else {
|
|
809
|
-
//
|
|
810
|
-
|
|
811
|
-
counter_credBu++;
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
if (counter_credBu !== 0) {
|
|
815
|
-
Util.logger.info(`\n:: Deployed ${counter_credBu} BUs\n`);
|
|
816
|
-
}
|
|
817
|
-
}
|
|
517
|
+
// anything but "*" passed in
|
|
518
|
+
let [cred, bu] = businessUnit ? businessUnit.split('/') : [null, null];
|
|
818
519
|
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
*
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
520
|
+
// to allow all-BU via user selection we need to run this here already
|
|
521
|
+
if (
|
|
522
|
+
properties.credentials &&
|
|
523
|
+
(!properties.credentials[cred] ||
|
|
524
|
+
(bu !== '*' && properties.credentials[cred].businessUnits[bu]))
|
|
525
|
+
) {
|
|
526
|
+
const buObject = await Cli.getCredentialObject(
|
|
527
|
+
properties,
|
|
528
|
+
cred !== null ? cred + '/' + bu : null,
|
|
529
|
+
null,
|
|
530
|
+
true
|
|
531
|
+
);
|
|
532
|
+
if (buObject !== null) {
|
|
533
|
+
cred = buObject.credential;
|
|
534
|
+
bu = buObject.businessUnit;
|
|
535
|
+
} else {
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
830
539
|
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
540
|
+
if (bu === '*' && properties.credentials && properties.credentials[cred]) {
|
|
541
|
+
// valid credential given and -all- BUs targeted
|
|
542
|
+
Util.logger.info(`\n:: Deploying all BUs for ${cred}`);
|
|
543
|
+
let counter_credBu = 0;
|
|
544
|
+
// for (const bu in properties.credentials[cred].businessUnits) {
|
|
545
|
+
const deployFolders = await File.readDirectories(
|
|
546
|
+
File.normalizePath([properties.directories.deploy, cred]),
|
|
547
|
+
1,
|
|
548
|
+
false
|
|
549
|
+
);
|
|
550
|
+
for (const buPath of deployFolders) {
|
|
551
|
+
await this._deployBU(cred, buPath, type);
|
|
552
|
+
counter_credBu++;
|
|
553
|
+
Util.logger.info('');
|
|
554
|
+
Util.restartLogger();
|
|
555
|
+
}
|
|
556
|
+
Util.logger.info(`\n:: ${counter_credBu} BUs for ${cred}\n`);
|
|
557
|
+
} else {
|
|
558
|
+
// either bad credential or specific BU or no BU given
|
|
559
|
+
await this._deployBU(cred, bu, type);
|
|
560
|
+
counter_credBu++;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
if (counter_credBu !== 0) {
|
|
564
|
+
Util.logger.info(`\n:: Deployed ${counter_credBu} BUs\n`);
|
|
565
|
+
}
|
|
842
566
|
}
|
|
843
|
-
}
|
|
844
567
|
|
|
845
|
-
/**
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
);
|
|
568
|
+
/**
|
|
569
|
+
* Creates template file for properties.json
|
|
570
|
+
* @param {string} [credentialsName] identifying name of the installed package / project
|
|
571
|
+
* @param {Boolean|Object} [skipInteraction] signals what to insert automatically for things usually asked via wizard
|
|
572
|
+
* @returns {Promise<void>} -
|
|
573
|
+
*/
|
|
574
|
+
static async initProject(credentialsName, skipInteraction) {
|
|
575
|
+
Util.logger.info('mcdev:: Setting up project');
|
|
576
|
+
properties = properties || File.loadConfigFile(!!credentialsName);
|
|
577
|
+
await Init.initProject(properties, credentialsName, skipInteraction);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* Refreshes BU names and ID's from MC instance
|
|
582
|
+
* @param {string} credentialsName identifying name of the installed package / project
|
|
583
|
+
* @returns {Promise<void>} -
|
|
584
|
+
*/
|
|
585
|
+
static async findBUs(credentialsName) {
|
|
586
|
+
Util.logger.info('mcdev:: Load BUs');
|
|
587
|
+
properties = properties || File.loadConfigFile();
|
|
588
|
+
const buObject = await Cli.getCredentialObject(properties, credentialsName, true);
|
|
866
589
|
if (buObject !== null) {
|
|
867
|
-
|
|
868
|
-
MetadataTypeInfo[type].document(buObject);
|
|
590
|
+
BuHelper.refreshBUProperties(properties, buObject.credential);
|
|
869
591
|
}
|
|
870
|
-
} catch (ex) {
|
|
871
|
-
Util.logger.error('mcdev.document ' + ex.message);
|
|
872
|
-
Util.logger.debug(ex.stack);
|
|
873
|
-
Util.logger.info('If the directoy does not exist, you may need to retrieve this BU first.');
|
|
874
592
|
}
|
|
875
|
-
}
|
|
876
593
|
|
|
877
|
-
/**
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
if (buObject !== null) {
|
|
890
|
-
if ('string' !== typeof type) {
|
|
891
|
-
Util.logger.error('mcdev.delete failed: Bad metadata type passed in');
|
|
594
|
+
/**
|
|
595
|
+
* Creates docs for supported metadata types in Markdown and/or HTML format
|
|
596
|
+
*
|
|
597
|
+
* @param {String} businessUnit references credentials from properties.json
|
|
598
|
+
* @param {String} type metadata type
|
|
599
|
+
* @returns {Promise<void>} -
|
|
600
|
+
*/
|
|
601
|
+
static async document(businessUnit, type) {
|
|
602
|
+
Util.logger.info('mcdev:: Document');
|
|
603
|
+
properties = properties || File.loadConfigFile();
|
|
604
|
+
if (type && !MetadataTypeInfo[type]) {
|
|
605
|
+
Util.logger.error(`:: '${type}' is not a valid metadata type`);
|
|
892
606
|
return;
|
|
893
607
|
}
|
|
894
608
|
try {
|
|
895
|
-
|
|
896
|
-
|
|
609
|
+
const parentBUOnlyTypes = ['role'];
|
|
610
|
+
const buObject = await Cli.getCredentialObject(
|
|
611
|
+
properties,
|
|
612
|
+
parentBUOnlyTypes.includes(type) ? businessUnit.split('/')[0] : businessUnit,
|
|
613
|
+
parentBUOnlyTypes.includes(type) ? Util.parentBuName : null
|
|
614
|
+
);
|
|
615
|
+
if (buObject !== null) {
|
|
616
|
+
MetadataTypeInfo[type].properties = properties;
|
|
617
|
+
MetadataTypeInfo[type].document(buObject);
|
|
618
|
+
}
|
|
897
619
|
} catch (ex) {
|
|
898
|
-
Util.logger.error('mcdev.
|
|
620
|
+
Util.logger.error('mcdev.document ' + ex.message);
|
|
621
|
+
Util.logger.debug(ex.stack);
|
|
622
|
+
Util.logger.info(
|
|
623
|
+
'If the directoy does not exist, you may need to retrieve this BU first.'
|
|
624
|
+
);
|
|
899
625
|
}
|
|
900
626
|
}
|
|
901
|
-
}
|
|
902
627
|
|
|
903
|
-
/**
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
Util.logger.info('
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
]);
|
|
927
|
-
if (!File.existsSync(docPath)) {
|
|
928
|
-
File.mkdirpSync(docPath);
|
|
929
|
-
} else if (File.existsSync(filename)) {
|
|
930
|
-
File.removeSync(filename);
|
|
628
|
+
/**
|
|
629
|
+
* Creates docs for supported metadata types in Markdown and/or HTML format
|
|
630
|
+
*
|
|
631
|
+
* @param {String} businessUnit references credentials from properties.json
|
|
632
|
+
* @param {String} type supported metadata type
|
|
633
|
+
* @param {String} customerKey Identifier of data extension
|
|
634
|
+
* @returns {Promise<void>} -
|
|
635
|
+
*/
|
|
636
|
+
static async deleteByKey(businessUnit, type, customerKey) {
|
|
637
|
+
Util.logger.info('mcdev:: delete');
|
|
638
|
+
properties = properties || File.loadConfigFile();
|
|
639
|
+
const buObject = await Cli.getCredentialObject(properties, businessUnit);
|
|
640
|
+
if (buObject !== null) {
|
|
641
|
+
if ('string' !== typeof type) {
|
|
642
|
+
Util.logger.error('mcdev.delete failed: Bad metadata type passed in');
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
try {
|
|
646
|
+
MetadataTypeInfo[type].properties = properties;
|
|
647
|
+
MetadataTypeInfo[type].deleteByKey(buObject, customerKey);
|
|
648
|
+
} catch (ex) {
|
|
649
|
+
Util.logger.error('mcdev.delete ' + ex.message);
|
|
650
|
+
}
|
|
931
651
|
}
|
|
652
|
+
}
|
|
932
653
|
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
654
|
+
/**
|
|
655
|
+
* Converts metadata to legacy format. Output is saved in 'converted' directory
|
|
656
|
+
* @param {String} businessUnit references credentials from properties.json
|
|
657
|
+
* @returns {Promise<void>} -
|
|
658
|
+
*/
|
|
659
|
+
static async badKeys(businessUnit) {
|
|
660
|
+
properties = properties || File.loadConfigFile();
|
|
661
|
+
const buObject = await Cli.getCredentialObject(properties, businessUnit);
|
|
662
|
+
if (buObject !== null) {
|
|
663
|
+
Util.logger.info('Gathering list of Name<>External Key mismatches (bad keys)');
|
|
664
|
+
const retrieveDir = File.filterIllegalPathChars(
|
|
665
|
+
File.normalizePath([
|
|
666
|
+
properties.directories.retrieve,
|
|
667
|
+
buObject.credential,
|
|
668
|
+
buObject.businessUnit,
|
|
669
|
+
])
|
|
940
670
|
);
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
671
|
+
const docPath = File.filterIllegalPathChars(
|
|
672
|
+
properties.directories.badKeys + buObject.credential
|
|
673
|
+
);
|
|
674
|
+
const filename = File.normalizePath([
|
|
675
|
+
docPath,
|
|
676
|
+
File.filterIllegalFilenames(buObject.businessUnit) + '.badKeys.md',
|
|
677
|
+
]);
|
|
678
|
+
if (!File.existsSync(docPath)) {
|
|
679
|
+
File.mkdirpSync(docPath);
|
|
680
|
+
} else if (File.existsSync(filename)) {
|
|
681
|
+
File.removeSync(filename);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
const regex = RegExp('(\\w+-){4}\\w+');
|
|
685
|
+
let metadata;
|
|
686
|
+
if (File.existsSync(retrieveDir)) {
|
|
687
|
+
metadata = Deployer.readBUMetadata(retrieveDir, null, true);
|
|
688
|
+
} else {
|
|
689
|
+
Util.logger.warn(
|
|
690
|
+
`Looks like ${retrieveDir} does not exist. If there was no metadata retrieved this is expected, in other cases re-run retrieve to attempt to fix this issue`
|
|
691
|
+
);
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
let output = '# List of Metadata with Name-Key mismatches\n';
|
|
695
|
+
for (const metadataType in metadata) {
|
|
696
|
+
let listEntries = '';
|
|
697
|
+
for (const entry in metadata[metadataType]) {
|
|
698
|
+
const metadataEntry = metadata[metadataType][entry];
|
|
699
|
+
if (regex.test(entry)) {
|
|
700
|
+
if (metadataType === 'query' && metadataEntry.Status === 'Inactive') {
|
|
701
|
+
continue;
|
|
702
|
+
}
|
|
703
|
+
listEntries +=
|
|
704
|
+
'- ' +
|
|
705
|
+
entry +
|
|
706
|
+
(metadataEntry.name || metadataEntry.Name
|
|
707
|
+
? ' => ' + (metadataEntry.name || metadataEntry.Name)
|
|
708
|
+
: '') +
|
|
709
|
+
'\n';
|
|
951
710
|
}
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
(metadataEntry.name || metadataEntry.Name
|
|
956
|
-
? ' => ' + (metadataEntry.name || metadataEntry.Name)
|
|
957
|
-
: '') +
|
|
958
|
-
'\n';
|
|
711
|
+
}
|
|
712
|
+
if (listEntries !== '') {
|
|
713
|
+
output += '\n## ' + metadataType + '\n\n' + listEntries;
|
|
959
714
|
}
|
|
960
715
|
}
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
716
|
+
await File.writeToFile(
|
|
717
|
+
docPath,
|
|
718
|
+
File.filterIllegalFilenames(buObject.businessUnit) + '.badKeys',
|
|
719
|
+
'md',
|
|
720
|
+
output
|
|
721
|
+
);
|
|
722
|
+
Util.logger.info('Bad keys documented in ' + filename);
|
|
964
723
|
}
|
|
965
|
-
await File.writeToFile(
|
|
966
|
-
docPath,
|
|
967
|
-
File.filterIllegalFilenames(buObject.businessUnit) + '.badKeys',
|
|
968
|
-
'md',
|
|
969
|
-
output
|
|
970
|
-
);
|
|
971
|
-
Util.logger.info('Bad keys documented in ' + filename);
|
|
972
724
|
}
|
|
973
|
-
}
|
|
974
725
|
|
|
975
|
-
/**
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
async
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
return;
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
let retrieveTypesArr;
|
|
1000
|
-
if (
|
|
1001
|
-
type &&
|
|
1002
|
-
subType &&
|
|
1003
|
-
MetadataTypeInfo[type] &&
|
|
1004
|
-
MetadataTypeDefinitions[type].subTypes.includes(subType)
|
|
1005
|
-
) {
|
|
1006
|
-
retrieveTypesArr = [selectedType];
|
|
1007
|
-
} else if (type && MetadataTypeInfo[type]) {
|
|
1008
|
-
retrieveTypesArr = [type];
|
|
1009
|
-
}
|
|
1010
|
-
const buObject = await Cli.getCredentialObject(properties, businessUnit);
|
|
1011
|
-
if (buObject !== null) {
|
|
1012
|
-
let client;
|
|
1013
|
-
try {
|
|
1014
|
-
client = await Util.getETClient(buObject);
|
|
1015
|
-
} catch (ex) {
|
|
1016
|
-
Util.logger.error(ex.message);
|
|
726
|
+
/**
|
|
727
|
+
* Retrieve a specific metadata file and templatise.
|
|
728
|
+
* @param {String} businessUnit references credentials from properties.json
|
|
729
|
+
* @param {String} selectedType supported metadata type
|
|
730
|
+
* @param {String} name name of the metadata
|
|
731
|
+
* @param {String} market market which should be used to revert template
|
|
732
|
+
* @returns {Promise<void>} -
|
|
733
|
+
*/
|
|
734
|
+
static async retrieveAsTemplate(businessUnit, selectedType, name, market) {
|
|
735
|
+
Util.logger.info('mcdev:: Retrieve as Template');
|
|
736
|
+
properties = properties || File.loadConfigFile();
|
|
737
|
+
const [type, subType] = selectedType ? selectedType.split('-') : [];
|
|
738
|
+
if (type && !MetadataTypeInfo[type]) {
|
|
739
|
+
Util.logger.error(`:: '${type}' is not a valid metadata type`);
|
|
740
|
+
return;
|
|
741
|
+
} else if (
|
|
742
|
+
type &&
|
|
743
|
+
subType &&
|
|
744
|
+
(!MetadataTypeInfo[type] || !MetadataTypeDefinitions[type].subTypes.includes(subType))
|
|
745
|
+
) {
|
|
746
|
+
Util.logger.error(`:: '${selectedType}' is not a valid metadata type`);
|
|
1017
747
|
return;
|
|
1018
748
|
}
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
749
|
+
|
|
750
|
+
let retrieveTypesArr;
|
|
751
|
+
if (
|
|
752
|
+
type &&
|
|
753
|
+
subType &&
|
|
754
|
+
MetadataTypeInfo[type] &&
|
|
755
|
+
MetadataTypeDefinitions[type].subTypes.includes(subType)
|
|
756
|
+
) {
|
|
757
|
+
retrieveTypesArr = [selectedType];
|
|
758
|
+
} else if (type && MetadataTypeInfo[type]) {
|
|
759
|
+
retrieveTypesArr = [type];
|
|
760
|
+
}
|
|
761
|
+
const buObject = await Cli.getCredentialObject(properties, businessUnit);
|
|
762
|
+
if (buObject !== null) {
|
|
763
|
+
let client;
|
|
764
|
+
try {
|
|
765
|
+
client = await Util.getETClient(buObject);
|
|
766
|
+
} catch (ex) {
|
|
767
|
+
Util.logger.error(ex.message);
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
const retriever = new Retriever(properties, buObject, client);
|
|
771
|
+
if (this._checkMarket(market)) {
|
|
772
|
+
return retriever.retrieve(retrieveTypesArr, name, properties.markets[market]);
|
|
773
|
+
}
|
|
1022
774
|
}
|
|
1023
775
|
}
|
|
1024
|
-
}
|
|
1025
776
|
|
|
1026
|
-
/**
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
async
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
777
|
+
/**
|
|
778
|
+
* Build a specific metadata file based on a template.
|
|
779
|
+
* @param {String} businessUnit references credentials from properties.json
|
|
780
|
+
* @param {String} type supported metadata type
|
|
781
|
+
* @param {String} name name of the metadata
|
|
782
|
+
* @param {String} market market localizations
|
|
783
|
+
* @returns {Promise<void>} -
|
|
784
|
+
*/
|
|
785
|
+
static async buildDefinition(businessUnit, type, name, market) {
|
|
786
|
+
Util.logger.info('mcdev:: Build Definition from Template');
|
|
787
|
+
properties = properties || File.loadConfigFile();
|
|
788
|
+
if (type.includes('-')) {
|
|
789
|
+
Util.logger.error(
|
|
790
|
+
`:: '${type}' is not a valid metadata type. Please don't include subtypes.`
|
|
791
|
+
);
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
if (type && !MetadataTypeInfo[type]) {
|
|
795
|
+
Util.logger.error(`:: '${type}' is not a valid metadata type`);
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
const buObject = await Cli.getCredentialObject(properties, businessUnit);
|
|
799
|
+
if (buObject !== null) {
|
|
800
|
+
const builder = new Builder(properties, buObject, null);
|
|
801
|
+
if (market === '*') {
|
|
802
|
+
for (const oneMarket in properties.markets) {
|
|
803
|
+
builder.buildDefinition(type, name, properties.markets[oneMarket]);
|
|
804
|
+
}
|
|
805
|
+
} else {
|
|
806
|
+
if (this._checkMarket(market)) {
|
|
807
|
+
builder.buildDefinition(type, name, properties.markets[market]);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
}
|
|
1046
811
|
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
812
|
+
/**
|
|
813
|
+
* check if a market name exists in current mcdev config
|
|
814
|
+
* @param {String} market market localizations
|
|
815
|
+
* @returns {Boolean} found market or not
|
|
816
|
+
*/
|
|
817
|
+
static _checkMarket(market) {
|
|
818
|
+
properties = properties || File.loadConfigFile();
|
|
819
|
+
if (properties.markets[market]) {
|
|
820
|
+
return true;
|
|
821
|
+
} else {
|
|
822
|
+
Util.logger.error(`Could not find the market '${market}' in your configuration file.`);
|
|
823
|
+
const marketArr = [];
|
|
1051
824
|
for (const oneMarket in properties.markets) {
|
|
1052
|
-
|
|
825
|
+
marketArr.push(oneMarket);
|
|
1053
826
|
}
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
builder.buildDefinition(type, name, properties.markets[market]);
|
|
827
|
+
if (marketArr.length) {
|
|
828
|
+
Util.logger.info('Available markets are: ' + marketArr.join(', '));
|
|
1057
829
|
}
|
|
830
|
+
return false;
|
|
1058
831
|
}
|
|
1059
832
|
}
|
|
1060
|
-
}
|
|
1061
|
-
/**
|
|
1062
|
-
* check if a market name exists in current mcdev config
|
|
1063
|
-
* @param {String} market market localizations
|
|
1064
|
-
* @returns {Boolean} found market or not
|
|
1065
|
-
*/
|
|
1066
|
-
function _checkMarket(market) {
|
|
1067
|
-
properties = properties || File.loadConfigFile();
|
|
1068
|
-
if (properties.markets[market]) {
|
|
1069
|
-
return true;
|
|
1070
|
-
} else {
|
|
1071
|
-
Util.logger.error(`Could not find the market '${market}' in your configuration file.`);
|
|
1072
|
-
const marketArr = [];
|
|
1073
|
-
for (const oneMarket in properties.markets) {
|
|
1074
|
-
marketArr.push(oneMarket);
|
|
1075
|
-
}
|
|
1076
|
-
if (marketArr.length) {
|
|
1077
|
-
Util.logger.info('Available markets are: ' + marketArr.join(', '));
|
|
1078
|
-
}
|
|
1079
|
-
return false;
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
833
|
|
|
1083
|
-
/**
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
async
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
}
|
|
1097
|
-
if (!properties.marketList[listName]) {
|
|
1098
|
-
Util.logger.error(`Please define properties.marketList.${listName} in your config`);
|
|
1099
|
-
return;
|
|
1100
|
-
}
|
|
1101
|
-
if (type && !MetadataTypeInfo[type]) {
|
|
1102
|
-
Util.logger.error(`:: '${type}' is not a valid metadata type`);
|
|
1103
|
-
return;
|
|
1104
|
-
}
|
|
1105
|
-
let i = 0;
|
|
1106
|
-
for (const businessUnit in properties.marketList[listName]) {
|
|
1107
|
-
if (businessUnit === 'description') {
|
|
1108
|
-
// skip, it's just a metadata on this list and not a BU
|
|
1109
|
-
continue;
|
|
834
|
+
/**
|
|
835
|
+
* Build a specific metadata file based on a template using a list of bu-market combos
|
|
836
|
+
* @param {String} listName name of list of BU-market combos
|
|
837
|
+
* @param {String} type supported metadata type
|
|
838
|
+
* @param {String} name name of the metadata
|
|
839
|
+
* @returns {Promise<void>} -
|
|
840
|
+
*/
|
|
841
|
+
static async buildDefinitionBulk(listName, type, name) {
|
|
842
|
+
Util.logger.info('mcdev:: Build Definition from Template Bulk');
|
|
843
|
+
properties = properties || File.loadConfigFile();
|
|
844
|
+
if (!properties.marketList) {
|
|
845
|
+
Util.logger.error('Please define properties.marketList object in your config');
|
|
846
|
+
return;
|
|
1110
847
|
}
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
848
|
+
if (!properties.marketList[listName]) {
|
|
849
|
+
Util.logger.error(`Please define properties.marketList.${listName} in your config`);
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
if (type && !MetadataTypeInfo[type]) {
|
|
853
|
+
Util.logger.error(`:: '${type}' is not a valid metadata type`);
|
|
854
|
+
return;
|
|
1118
855
|
}
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
856
|
+
let i = 0;
|
|
857
|
+
for (const businessUnit in properties.marketList[listName]) {
|
|
858
|
+
if (businessUnit === 'description') {
|
|
859
|
+
// skip, it's just a metadata on this list and not a BU
|
|
860
|
+
continue;
|
|
861
|
+
}
|
|
862
|
+
i++;
|
|
863
|
+
const market = properties.marketList[listName][businessUnit];
|
|
864
|
+
let marketList = [];
|
|
865
|
+
if ('string' === typeof market) {
|
|
866
|
+
marketList.push(market);
|
|
1123
867
|
} else {
|
|
1124
|
-
|
|
1125
|
-
`Could not find '${market}' in properties.markets. Please check your properties.marketList.${listName} confguration.`
|
|
1126
|
-
);
|
|
868
|
+
marketList = market;
|
|
1127
869
|
}
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
870
|
+
marketList.forEach((market) => {
|
|
871
|
+
if (market && properties.markets[market]) {
|
|
872
|
+
Util.logger.info(`Executing for '${businessUnit}': '${market}'`);
|
|
873
|
+
this.buildDefinition(businessUnit, type, name, market);
|
|
874
|
+
} else {
|
|
875
|
+
Util.logger.error(
|
|
876
|
+
`Could not find '${market}' in properties.markets. Please check your properties.marketList.${listName} confguration.`
|
|
877
|
+
);
|
|
878
|
+
}
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
if (!i) {
|
|
882
|
+
Util.logger.error('Please define properties.marketList in your config');
|
|
883
|
+
}
|
|
1132
884
|
}
|
|
1133
885
|
}
|
|
886
|
+
|
|
887
|
+
module.exports = Mcdev;
|