Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/294 task run checkproperties on config load #324

Draft
wants to merge 19 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 72 additions & 83 deletions docs/dist/documentation.md

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions lib/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const TYPE = require('../types/mcdev.d');
const Util = require('./util/util');
const File = require('./util/file');
const Cli = require('./util/cli');
const config = require('./util/config');
const auth = require('./util/auth');
const MetadataTypeInfo = require('./MetadataTypeInfo');
// @ts-ignore
Expand Down Expand Up @@ -103,7 +104,7 @@ saved
*/
static async buildTemplate(businessUnit, selectedType, keyArr, market) {
Util.logger.info('mcdev:: Build Definition from Template');
const properties = File.loadConfigFile();
const properties = await config.getProperties();
DougMidgley marked this conversation as resolved.
Show resolved Hide resolved
if (!Util._isValidType(selectedType)) {
return;
}
Expand Down Expand Up @@ -170,7 +171,7 @@ saved
* @returns {Promise.<TYPE.MultiMetadataTypeList>} -
*/
static async buildDefinition(businessUnit, selectedType, name, market) {
const properties = File.loadConfigFile();
const properties = await config.getProperties();
DougMidgley marked this conversation as resolved.
Show resolved Hide resolved
if (!Util._isValidType(selectedType)) {
return;
}
Expand All @@ -197,7 +198,7 @@ saved
* @returns {Promise.<void>} -
*/
static async buildDefinitionBulk(listName, type, name) {
const properties = File.loadConfigFile();
const properties = await config.getProperties();
DougMidgley marked this conversation as resolved.
Show resolved Hide resolved
Util.verifyMarketList(listName, properties);
if (type && !MetadataTypeInfo[type]) {
Util.logger.error(`:: '${type}' is not a valid metadata type`);
Expand Down
4 changes: 3 additions & 1 deletion lib/Deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const Util = require('./util/util');
const File = require('./util/file');
const cache = require('./util/cache');
const auth = require('./util/auth');
const config = require('./util/config');

/**
* Reads metadata from local directory and deploys it to specified target business unit.
Expand Down Expand Up @@ -51,7 +52,8 @@ class Deployer {
*/
static async deploy(businessUnit, selectedTypesArr, keyArr, fromRetrieve) {
Util.logger.info('mcdev:: Deploy');
const properties = File.loadConfigFile();

const properties = await config.getProperties();
DougMidgley marked this conversation as resolved.
Show resolved Hide resolved
if (fromRetrieve) {
properties.directories.deploy = properties.directories.retrieve;
}
Expand Down
74 changes: 39 additions & 35 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ yargs
describe: 'metadata keys that shall be exclusively downloaded',
});
},
handler: (argv) => {
handler: async (argv) => {
Mcdev.setSkipInteraction(argv.skipInteraction);
Mcdev.setLoggingLevel(argv);
Mcdev.retrieve(argv.BU, csvToArray(argv.TYPE), csvToArray(argv.KEY));
await Mcdev.retrieve(argv.BU, csvToArray(argv.TYPE), csvToArray(argv.KEY));
},
})
.command({
Expand All @@ -63,41 +63,41 @@ yargs
describe: 'optionally deploy from retrieve folder',
});
},
handler: (argv) => {
handler: async (argv) => {
Mcdev.setSkipInteraction(argv.skipInteraction);
Mcdev.setLoggingLevel(argv);
Mcdev.deploy(argv.BU, csvToArray(argv.TYPE), csvToArray(argv.KEY), argv.fromRetrieve);
},
})
.command({
command: 'init [credentialsName]',
command: 'init [credentialName]',
desc: `creates '${Util.configFileName}' in your root or adds additional credentials to the existing one`,
builder: (yargs) => {
yargs.positional('credentialsName', {
yargs.positional('credentialName', {
type: 'string',
describe: 'name of your installed package',
});
},
handler: (argv) => {
handler: async (argv) => {
Mcdev.setSkipInteraction(argv.skipInteraction);
Mcdev.setLoggingLevel(argv);
Mcdev.initProject(argv.credentialsName, argv.skipInteraction);
await Mcdev.initProject(argv.credentialsName, argv.skipInteraction);
},
})
.command({
command: 'reloadBUs [credentialsName]',
command: 'reloadBUs [credentialName]',
aliases: ['rb'],
desc: 'loads the list of available BUs from the server and saves it to your config',
builder: (yargs) => {
yargs.positional('credentialsName', {
yargs.positional('credentialName', {
type: 'string',
describe: 'name of your installed package',
});
},
handler: (argv) => {
handler: async (argv) => {
Mcdev.setSkipInteraction(argv.skipInteraction);
Mcdev.setLoggingLevel(argv);
Mcdev.findBUs(argv.credentialsName);
await Mcdev.findBUs(argv.credentialsName);
},
})
.command({
Expand All @@ -109,10 +109,10 @@ yargs
describe: 'the business unit to deploy to',
});
},
handler: (argv) => {
handler: async (argv) => {
Mcdev.setSkipInteraction(argv.skipInteraction);
Mcdev.setLoggingLevel(argv);
Mcdev.badKeys(argv.BU);
await Mcdev.badKeys(argv.BU);
},
})
.command({
Expand All @@ -132,10 +132,10 @@ yargs
'metadata type to generate docs for; currently supported: dataExtension, role',
});
},
handler: (argv) => {
handler: async (argv) => {
Mcdev.setSkipInteraction(argv.skipInteraction);
Mcdev.setLoggingLevel(argv);
Mcdev.document(argv.BU, argv.TYPE);
await Mcdev.document(argv.BU, argv.TYPE);
},
})
.command({
Expand All @@ -158,10 +158,10 @@ yargs
describe: 'the key to delete',
});
},
handler: (argv) => {
handler: async (argv) => {
Mcdev.setSkipInteraction(argv.skipInteraction);
Mcdev.setLoggingLevel(argv);
Mcdev.deleteByKey(argv.BU, argv.TYPE, argv.EXTERNALKEY);
await Mcdev.deleteByKey(argv.BU, argv.TYPE, argv.EXTERNALKEY);
},
})
.command({
Expand All @@ -188,10 +188,10 @@ yargs
describe: 'market used for reverse building template',
});
},
handler: (argv) => {
handler: async (argv) => {
Mcdev.setSkipInteraction(argv.skipInteraction);
Mcdev.setLoggingLevel(argv);
Mcdev.retrieveAsTemplate(argv.BU, argv.TYPE, csvToArray(argv.NAME), argv.MARKET);
await Mcdev.retrieveAsTemplate(argv.BU, argv.TYPE, csvToArray(argv.NAME), argv.MARKET);
},
})
.command({
Expand All @@ -218,12 +218,12 @@ yargs
describe: 'market used for reverse building template',
});
},
handler: (argv) => {
handler: async (argv) => {
Mcdev.setSkipInteraction(argv.skipInteraction);
Mcdev.setLoggingLevel(argv);
const keyArr = csvToArray(argv.KEY);

Mcdev.buildTemplate(argv.BU, argv.TYPE, keyArr, argv.MARKET);
await Mcdev.buildTemplate(argv.BU, argv.TYPE, keyArr, argv.MARKET);
},
})
.command({
Expand All @@ -249,10 +249,10 @@ yargs
describe: 'the business unit to deploy to',
});
},
handler: (argv) => {
handler: async (argv) => {
Mcdev.setSkipInteraction(argv.skipInteraction);
Mcdev.setLoggingLevel(argv);
Mcdev.buildDefinition(argv.BU, argv.TYPE, argv.NAME, argv.MARKET);
await Mcdev.buildDefinition(argv.BU, argv.TYPE, argv.NAME, argv.MARKET);
},
})
.command({
Expand All @@ -274,30 +274,30 @@ yargs
describe: 'name of the metadata component',
});
},
handler: (argv) => {
handler: async (argv) => {
Mcdev.setSkipInteraction(argv.skipInteraction);
Mcdev.setLoggingLevel(argv);
Mcdev.buildDefinitionBulk(argv.LISTNAME, argv.TYPE, argv.NAME);
await Mcdev.buildDefinitionBulk(argv.LISTNAME, argv.TYPE, argv.NAME);
},
})
.command({
command: 'selectTypes',
aliases: ['st'],
desc: 'lets you choose what metadata types to retrieve',
handler: (argv) => {
handler: async (argv) => {
Mcdev.setSkipInteraction(argv.skipInteraction);
Mcdev.setLoggingLevel(argv);
Mcdev.selectTypes();
await Mcdev.selectTypes();
},
})
.command({
command: 'explainTypes',
aliases: ['et'],
desc: 'explains metadata types that can be retrieved',
handler: (argv) => {
handler: async (argv) => {
Mcdev.setSkipInteraction(argv.skipInteraction);
Mcdev.setLoggingLevel(argv);
Mcdev.explainTypes();
await Mcdev.explainTypes();
},
})
.command({
Expand All @@ -316,10 +316,10 @@ yargs
'Disable templating & instead filter by the specified file path (comma separated)',
});
},
handler: (argv) => {
handler: async (argv) => {
Mcdev.setSkipInteraction(argv.skipInteraction);
Mcdev.setLoggingLevel(argv);
Mcdev.createDeltaPkg(argv);
await Mcdev.createDeltaPkg(argv);
},
})
.command({
Expand All @@ -342,22 +342,22 @@ yargs
describe: 'key(s) of the metadata component(s)',
});
},
handler: (argv) => {
handler: async (argv) => {
Mcdev.setSkipInteraction(argv.skipInteraction);
Mcdev.setLoggingLevel(argv);
const keyArr = csvToArray(argv.KEY);

Mcdev.getFilesToCommit(argv.BU, argv.TYPE, keyArr);
await Mcdev.getFilesToCommit(argv.BU, argv.TYPE, keyArr);
},
})
.command({
command: 'upgrade',
aliases: ['up'],
desc: 'Add NPM dependencies and IDE configuration files to your project',
handler: (argv) => {
handler: async (argv) => {
Mcdev.setSkipInteraction(argv.skipInteraction);
Mcdev.setLoggingLevel(argv);
Mcdev.upgrade(argv.skipInteraction);
await Mcdev.upgrade(argv.skipInteraction);
},
})
.option('verbose', {
Expand All @@ -378,6 +378,10 @@ yargs
})
.demandCommand(1, 'Please enter a valid command')
.strict()
.fail((_, err) => {
Util.logger.error(err.message);
process.exit(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

our adaption of Util.logger.error already sets the exit code to 1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error: function (msg) {

Copy link
Contributor

@JoernBerkefeld JoernBerkefeld Jun 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also there is a method to wrap around exit code 1:

signalFatalError() {

apparently the right way to do it for async-functions was process.exitCode = 1;
here more on the why: https://nodejs.dev/learn/how-to-exit-from-a-nodejs-program

})
.recommendCommands()
.wrap(yargs.terminalWidth())
.epilog(
Expand Down
Loading