Skip to content

Commit 62b9b39

Browse files
Merge pull request #503 from Accenture/502-bug-mcdev-init-in-unattended-mode-asks-if-bus-should-be-downloaded
#501 + #502 bug mcdev init in unattended mode asks if bus should be downloaded
2 parents 2bb8d02 + 0ac33ba commit 62b9b39

File tree

8 files changed

+106
-231
lines changed

8 files changed

+106
-231
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ Example url: `https://mcg123abcysykllg-0321cbs8bbt64.auth.marketingcloudapis.com
476476
> You can run this command without the interactive wizard asking questions using the `--skipInteraction` (or short`--yes`/`--y`) flag. In this case, you need to provide a few values in the command:
477477
>
478478
> ```bash
479-
> mcdev init --y.credentialsName "yourCustomCredentialName" --y.client_id "yourClientIdHere" --y.client_secret "yourClientSecretHere" --y.auth_url "https://yourTenantSubdomainHere.auth.marketingcloudapis.com/" --y.gitRemoteUrl "https://my.git.server.com/myrepo.git" --y.account_id 00000000
479+
> mcdev init --y.credentialName "yourCustomCredentialName" --y.client_id "yourClientIdHere" --y.client_secret "yourClientSecretHere" --y.auth_url "https://yourTenantSubdomainHere.auth.marketingcloudapis.com/" --y.gitRemoteUrl "https://my.git.server.com/myrepo.git" --y.account_id 00000000 --y.backupBUs "yes" --y.gitPush "yes"
480480
> ```
481481
482482
#### 6.1.2. upgrade

docs/dist/documentation.md

Lines changed: 62 additions & 166 deletions
Large diffs are not rendered by default.

lib/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ yargs
8181
handler: (argv) => {
8282
Mcdev.setSkipInteraction(argv.skipInteraction);
8383
Mcdev.setLoggingLevel(argv);
84-
Mcdev.initProject(argv.credentialsName, argv.skipInteraction);
84+
Mcdev.initProject(argv.credentialsName);
8585
},
8686
})
8787
.command({

lib/index.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@ class Mcdev {
5050
into deploy directory
5151
* @param {string} [argv.filter] filter file paths that start with any
5252
* @param {TYPE.DeltaPkgItem[]} [argv.diffArr] list of files to include in delta package (skips git diff when provided)
53-
* @param {TYPE.skipInteraction} [argv.skipInteraction] allows to skip interactive wizard
5453
* @returns {Promise.<TYPE.DeltaPkgItem[]>} list of changed items
5554
*/
5655
static async createDeltaPkg(argv) {
5756
Util.logger.info('Create Delta Package ::');
58-
Mcdev.setSkipInteraction(argv.skipInteraction);
5957
const properties = await config.getProperties();
6058
if (!(await config.checkProperties(properties))) {
6159
return null;
@@ -65,12 +63,7 @@ class Mcdev {
6563
? // get source market and source BU from config
6664
DevOps.getDeltaList(properties, argv.range, true, argv.filter)
6765
: // If no custom filter was provided, use deployment marketLists & templating
68-
DevOps.buildDeltaDefinitions(
69-
properties,
70-
argv.range,
71-
argv.diffArr,
72-
argv.skipInteraction
73-
);
66+
DevOps.buildDeltaDefinitions(properties, argv.range, argv.diffArr);
7467
}
7568

7669
/**
@@ -90,17 +83,15 @@ class Mcdev {
9083
Cli.explainTypes();
9184
}
9285
/**
93-
* @param {boolean | TYPE.skipInteraction} [skipInteraction] signals what to insert automatically for things usually asked via wizard
9486
* @returns {Promise.<boolean>} success flag
9587
*/
96-
static async upgrade(skipInteraction) {
97-
Mcdev.setSkipInteraction(skipInteraction);
88+
static async upgrade() {
9889
const properties = await config.getProperties();
9990
if (!properties) {
10091
Util.logger.error('No config found. Please run mcdev init');
10192
return false;
10293
}
103-
if ((await InitGit.initGitRepo(skipInteraction)).status === 'error') {
94+
if ((await InitGit.initGitRepo()).status === 'error') {
10495
return false;
10596
}
10697

@@ -295,14 +286,12 @@ class Mcdev {
295286
* Creates template file for properties.json
296287
*
297288
* @param {string} [credentialsName] identifying name of the installed package / project
298-
* @param {boolean | TYPE.skipInteraction} [skipInteraction] signals what to insert automatically for things usually asked via wizard
299289
* @returns {Promise.<void>} -
300290
*/
301-
static async initProject(credentialsName, skipInteraction) {
291+
static async initProject(credentialsName) {
302292
Util.logger.info('mcdev:: Setting up project');
303-
Mcdev.setSkipInteraction(skipInteraction);
304293
const properties = await config.getProperties(!!credentialsName);
305-
await Init.initProject(properties, credentialsName, skipInteraction);
294+
await Init.initProject(properties, credentialsName);
306295
}
307296

308297
/**

lib/util/cli.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,25 @@ const Cli = {
1818
* used when initially setting up a project.
1919
* loads default config and adds first credential
2020
*
21-
* @param {TYPE.skipInteraction} [skipInteraction] signals what to insert automatically for things usually asked via wizard
2221
* @returns {Promise.<boolean>} success of init
2322
*/
24-
async initMcdevConfig(skipInteraction) {
23+
async initMcdevConfig() {
2524
Util.logger.info('-- Initialising server connection --');
2625
Util.logger.info('Please enter a name for your "Installed Package" credentials:');
2726
const propertiesTemplate = await config.getDefaultProperties();
2827
delete propertiesTemplate.credentials.default;
2928

3029
// wait for the interaction to finish or else an outer await will run before this is done
31-
return this._setCredential(propertiesTemplate, null, skipInteraction);
30+
return this._setCredential(propertiesTemplate, null);
3231
},
3332
/**
3433
* Extends template file for properties.json
3534
*
3635
* @param {TYPE.Mcdevrc} properties config file's json
37-
* @param {TYPE.skipInteraction} [skipInteraction] signals what to insert automatically for things usually asked via wizard
3836
* @returns {Promise.<void>} -
3937
*/
40-
async addExtraCredential(properties, skipInteraction) {
38+
async addExtraCredential(properties) {
39+
const skipInteraction = Util.skipInteraction;
4140
if (!(await config.checkProperties(properties))) {
4241
// return null here to avoid seeing 2 error messages for the same issue
4342
return null;
@@ -54,7 +53,7 @@ const Cli = {
5453
`Credential '${skipInteraction.credentialName}' already existing. If you tried updating please provide run 'mcdev init ${skipInteraction.credentialName}'`
5554
);
5655
}
57-
return this._setCredential(properties, null, skipInteraction);
56+
return this._setCredential(properties, null);
5857
}
5958
},
6059
/**
@@ -63,15 +62,15 @@ const Cli = {
6362
*
6463
* @param {TYPE.Mcdevrc} properties config file's json
6564
* @param {string} credName name of credential that needs updating
66-
* @param {TYPE.skipInteraction} [skipInteraction] signals what to insert automatically for things usually asked via wizard
6765
* @returns {Promise.<boolean>} success of update
6866
*/
69-
async updateCredential(properties, credName, skipInteraction) {
67+
async updateCredential(properties, credName) {
68+
const skipInteraction = Util.skipInteraction;
7069
if (credName) {
7170
if (!skipInteraction) {
7271
Util.logger.info(`Please enter the details for '${credName}'`);
7372
}
74-
return await this._setCredential(properties, credName, skipInteraction);
73+
return await this._setCredential(properties, credName);
7574
}
7675
},
7776
/**
@@ -226,10 +225,10 @@ const Cli = {
226225
*
227226
* @param {TYPE.Mcdevrc} properties from config file
228227
* @param {string} [credName] name of credential that needs updating
229-
* @param {TYPE.skipInteraction} [skipInteraction] signals what to insert automatically for things usually asked via wizard
230228
* @returns {Promise.<boolean | string>} success of refresh or credential name
231229
*/
232-
async _setCredential(properties, credName, skipInteraction) {
230+
async _setCredential(properties, credName) {
231+
const skipInteraction = Util.skipInteraction;
233232
// Get user input
234233
let credentialsGood = null;
235234
let inputData;

lib/util/devops.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,10 @@ const DevOps = {
249249
* @param {TYPE.Mcdevrc} properties project config file
250250
* @param {string} range git commit range
251251
* @param {TYPE.DeltaPkgItem[]} [diffArr] instead of running git diff the method can also get a list of files to process
252-
* @param {TYPE.SkipInteraction} [skipInteraction] allows to skip interactive wizard
253252
* @returns {Promise.<TYPE.DeltaPkgItem[]>} -
254253
*/
255-
async buildDeltaDefinitions(properties, range, diffArr, skipInteraction) {
254+
async buildDeltaDefinitions(properties, range, diffArr) {
255+
const skipInteraction = Util.skipInteraction;
256256
// check if sourceTargetMapping is valid
257257
if (
258258
!properties.options.deployment.sourceTargetMapping ||

lib/util/init.git.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
const TYPE = require('../../types/mcdev.d');
2+
// const TYPE = require('../../types/mcdev.d');
33
const File = require('./file');
44
const inquirer = require('inquirer');
55
const Util = require('./util');
@@ -14,10 +14,9 @@ const Init = {
1414
/**
1515
* check if git repo exists and otherwise create one
1616
*
17-
* @param {TYPE.skipInteraction} [skipInteraction] signals what to insert automatically for things usually asked via wizard
1817
* @returns {Promise.<{status: string, repoName: string}>} success flag
1918
*/
20-
async initGitRepo(skipInteraction) {
19+
async initGitRepo() {
2120
const result = { status: null, repoName: null };
2221
// check if git is installed (https://www.npmjs.com/package/command-exists)
2322
if (!commandExists.sync('git')) {
@@ -65,10 +64,10 @@ const Init = {
6564
}
6665

6766
// offer to update local user.name and user.email
68-
await this._updateGitConfigUser(skipInteraction);
67+
await this._updateGitConfigUser();
6968
if (newRepoInitialized) {
7069
// offer to insert git remote url now
71-
result.repoName = await this._addGitRemote(skipInteraction);
70+
result.repoName = await this._addGitRemote();
7271
}
7372

7473
Util.logger.info('✔️ Git initialization done.');
@@ -78,10 +77,10 @@ const Init = {
7877
/**
7978
* offer to push the new repo straight to the server
8079
*
81-
* @param {boolean | TYPE.skipInteraction} [skipInteraction] signals what to insert automatically for things usually asked via wizard
8280
* @returns {void}
8381
*/
84-
async gitPush(skipInteraction) {
82+
async gitPush() {
83+
const skipInteraction = Util.skipInteraction;
8584
const gitRemotes = (await git.getRemotes(true)).filter((item) => item.name === 'origin');
8685
if (gitRemotes.length && gitRemotes[0].refs.push) {
8786
// check if remote repo is still empty (otherwise to risky to blindly push)
@@ -101,7 +100,7 @@ const Init = {
101100
`Your remote Git repository is still empty and ready to store your initial backup. Hint: This is the server version of the repo which you share with your team.`
102101
);
103102
let responses;
104-
if (!skipInteraction) {
103+
if (!skipInteraction || !skipInteraction.gitPush !== 'yes') {
105104
responses = await inquirer.prompt([
106105
{
107106
type: 'confirm',
@@ -111,7 +110,7 @@ const Init = {
111110
},
112111
]);
113112
}
114-
if (skipInteraction || responses.gitPush) {
113+
if (skipInteraction.gitPush === 'yes' || responses.gitPush) {
115114
Util.execSync('git', ['push', '-u', 'origin', 'master']);
116115
}
117116
} else if (remoteBranchesExist === true) {
@@ -124,10 +123,10 @@ const Init = {
124123
/**
125124
* offers to add the git remote origin
126125
*
127-
* @param {TYPE.skipInteraction} [skipInteraction] signals what to insert automatically for things usually asked via wizard
128126
* @returns {string} repo name (optionally)
129127
*/
130-
async _addGitRemote(skipInteraction) {
128+
async _addGitRemote() {
129+
const skipInteraction = Util.skipInteraction;
131130
// #1 ask if the user wants to do it now
132131
let responses;
133132
if (!skipInteraction) {
@@ -177,10 +176,10 @@ const Init = {
177176
/**
178177
* checks global config and ask to config the user info and then store it locally
179178
*
180-
* @param {boolean | TYPE.skipInteraction} [skipInteraction] signals what to insert automatically for things usually asked via wizard
181179
* @returns {void}
182180
*/
183-
async _updateGitConfigUser(skipInteraction) {
181+
async _updateGitConfigUser() {
182+
const skipInteraction = Util.skipInteraction;
184183
const gitUser = (await this._getGitConfigUser()) || {};
185184
Util.logger.info(
186185
`Please confirm your Git user name & email. It should be in the format 'FirstName LastName' and 'your.email@accenture.com'. The current (potentially wrong) values are provided as default. If correct, confirm with ENTER, otherwise please update:`

lib/util/init.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ const Init = {
1919
*
2020
* @param {TYPE.Mcdevrc} properties config file's json
2121
* @param {string} credentialName identifying name of the installed package / project
22-
* @param {TYPE.skipInteraction} [skipInteraction] signals what to insert automatically for things usually asked via wizard
2322
* @returns {Promise.<void>} -
2423
*/
25-
async initProject(properties, credentialName, skipInteraction) {
24+
async initProject(properties, credentialName) {
25+
const skipInteraction = Util.skipInteraction;
2626
if (!properties) {
2727
// try to get cached properties because we return null in case of a crucial error
2828
properties = config.properties;
@@ -42,11 +42,7 @@ const Init = {
4242
do {
4343
error = false;
4444
try {
45-
const success = await Cli.updateCredential(
46-
properties,
47-
credentialName,
48-
skipInteraction
49-
);
45+
const success = await Cli.updateCredential(properties, credentialName);
5046
if (success) {
5147
Util.logger.info(`✔️ Credential '${credentialName}' updated.`);
5248
} else {
@@ -72,11 +68,7 @@ const Init = {
7268
do {
7369
error = false;
7470
try {
75-
const success = await Cli.updateCredential(
76-
properties,
77-
badCredName,
78-
skipInteraction
79-
);
71+
const success = await Cli.updateCredential(properties, badCredName);
8072
if (success) {
8173
Util.logger.info(`✔️ Credential '${badCredName}' updated.`);
8274
} else {
@@ -128,18 +120,18 @@ const Init = {
128120
}
129121
let credentialName;
130122
if (skipInteraction || responses.isAddCredential) {
131-
credentialName = await Cli.addExtraCredential(properties, skipInteraction);
123+
credentialName = await Cli.addExtraCredential(properties);
132124
}
133125
if (credentialName) {
134-
await this._downloadAllBUs(`${credentialName}/*`, 'update', skipInteraction);
126+
await this._downloadAllBUs(`${credentialName}/*`, 'update');
135127
}
136128
}
137129
} else {
138130
// config does not exist
139131
// assuming it's the first time this command is run for this project
140132

141133
// initialize git repo
142-
const initGit = await InitGit.initGitRepo(skipInteraction);
134+
const initGit = await InitGit.initGitRepo();
143135
if (initGit.status === 'error') {
144136
return;
145137
}
@@ -152,7 +144,7 @@ const Init = {
152144
}
153145

154146
// ask for credentials and create mcdev config
155-
status = await Cli.initMcdevConfig(skipInteraction);
147+
status = await Cli.initMcdevConfig();
156148
if (!status) {
157149
return;
158150
}
@@ -169,7 +161,7 @@ const Init = {
169161
await this._downloadAllBUs('"*"', initGit.status);
170162

171163
// backup to server
172-
await InitGit.gitPush(skipInteraction);
164+
await InitGit.gitPush();
173165

174166
// all done
175167
Util.logger.info('You are now ready to work with Accenture SFMC DevTools!');
@@ -183,12 +175,12 @@ const Init = {
183175
*
184176
* @param {string} bu cred/bu or cred/* or *
185177
* @param {string} gitStatus signals what state the git repo is in
186-
* @param {boolean | TYPE.skipInteraction} [skipInteraction] signals what to insert automatically for things usually asked via wizard
187178
* @returns {Promise.<void>} -
188179
*/
189-
async _downloadAllBUs(bu, gitStatus, skipInteraction) {
180+
async _downloadAllBUs(bu, gitStatus) {
181+
const skipInteraction = Util.skipInteraction;
190182
let responses;
191-
if (!skipInteraction) {
183+
if (!skipInteraction || skipInteraction.backupBUs !== 'yes') {
192184
responses = await inquirer.prompt([
193185
{
194186
type: 'confirm',
@@ -198,7 +190,7 @@ const Init = {
198190
},
199191
]);
200192
}
201-
if (skipInteraction || responses.initialRetrieveAll) {
193+
if (skipInteraction.backupBUs === 'yes' || responses.initialRetrieveAll) {
202194
Util.execSync('mcdev', ['retrieve', bu]);
203195

204196
if (gitStatus === 'init') {

0 commit comments

Comments
 (0)