This may not work exceptionally well if logic is more complex ... but, here's one quick way to do nested scripts:
// index.js
import yargs from 'yargs';
import pkg from '../package.json';
import utilities from './scripts/utilities';
import find from './scripts/find';
let argv = yargs
.version(pkg.version)
.usage(`Usage: $0 --script [name of script]`)
.option('script', {
description: 'Name of script to run (no extension).',
type: 'string',
demand: true,
})
.argv;
switch (argv.script) {
case 'find':
find.getOptions();
break;
default:
utilities.o('log', `Script does not exist: ${argv.script}`.red.bold);
utilities.exitGraceful();
}
In fact, might be nice to convert index.js into this kind of setup (minus the script/yargs bits) so it's easy to convert to users if they need a little more flex.
This may not work exceptionally well if logic is more complex ... but, here's one quick way to do nested scripts:
Example call:
In fact, might be nice to convert
index.js
into this kind of setup (minus the script/yargs bits) so it's easy to convert to users if they need a little more flex.