Skip to content

Commit

Permalink
feat(public/kpo): adds -- to kpo commands on raise so they can take a…
Browse files Browse the repository at this point in the history
…rguments out of the box
  • Loading branch information
rafamel committed May 5, 2019
1 parent 2d4d9be commit ef05508
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions src/public/kpo/raise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,48 @@ function raise(options: IRaiseOptions = {}): () => Promise<void> {
if (argv.shift() !== 'kpo') return false;
if (argv[0] === ':run') argv.shift();
return (
argv.length === 1 &&
argv.length === 2 &&
argv[0][0] !== ':' &&
argv[0][0] !== '@' &&
argv[0] === key
argv[0] === key &&
argv[1] === '--'
);
});
const nonSelected = Object.keys(scripts).filter(
(key) => !selected.includes(key)
);

const toAdd = taskNames.filter((key) => !selected.includes(key));
const toRemove = selected
let toAdd = taskNames.filter((key) => !selected.includes(key));
let toRemove = selected
.filter((key) => !taskNames.includes(key))
.concat(Object.keys(scripts).filter((key) => toAdd.includes(key)));
const toReplace = toAdd.filter((key) => toRemove.includes(key));
if (toReplace.length) {
toAdd = toAdd.filter((key) => !toReplace.includes(key));
toRemove = toRemove.filter((key) => !toReplace.includes(key));
}

let msg = chalk.bold('No pending scripts changes');
if (toRemove.length || toAdd.length) {
msg = toRemove.length
? chalk.bold.yellow('Scripts to remove: ') + toRemove.join(', ')
: chalk.bold('No scripts to remove');
msg +=
'\n' +
(toAdd.length
? chalk.bold.yellow('Scripts to add: ') + toAdd.join(', ')
: chalk.bold('No scripts to add'));
if (toAdd.length || toReplace.length || toRemove.length) {
msg = '';
if (toAdd.length) {
msg += chalk.bold.yellow('Scripts to add: ') + `${toAdd.join(', ')}\n`;
}
if (toReplace.length) {
msg +=
chalk.bold.yellow('Scripts to replace: ') +
`${toReplace.join(', ')}\n`;
}
if (toRemove.length) {
msg +=
chalk.bold.yellow('Scripts to remove: ') + `${toRemove.join(', ')}\n`;
}
}

// eslint-disable-next-line no-console
(options.confirm || options.dry ? console.log : logger.info)(msg);

if (!toRemove.length && !toAdd.length) return;
if (!toAdd.length && !toReplace.length && !toRemove.length) return;
if (options.dry) {
if (options.fail) throw Error(`There are pending scripts changes`);
return;
Expand All @@ -104,7 +115,7 @@ function raise(options: IRaiseOptions = {}): () => Promise<void> {
return acc;
}, {}),
...taskNames.reduce((acc: IOfType<string>, key) => {
acc[key] = `kpo ${key}`;
acc[key] = `kpo ${key} --`;
return acc;
}, {})
};
Expand Down

0 comments on commit ef05508

Please sign in to comment.