UNPKG

atomic-reactor-cli

Version:

A CLI for creating Atomic Reactor Awesomeness

93 lines (82 loc) 2.73 kB
/** * ----------------------------------------------------------------------------- * Imports * ----------------------------------------------------------------------------- */ const path = require('path'); const chalk = require('chalk'); const op = require('object-path'); const GENERATOR = require('./generator'); const mod = path.dirname(require.main.filename); const { message } = require(`${mod}/lib/messenger`); /** * NAME String * @description Constant defined as the command name. Value passed to the commander.command() function. * @example $ arcli install * @see https://www.npmjs.com/package/commander#command-specific-options * @since 2.0.0 */ const NAME = 'install [name]'; /** * DESC String * @description Constant defined as the command description. Value passed to * the commander.desc() function. This string is also used in the --help flag output. * @see https://www.npmjs.com/package/commander#automated---help * @since 2.0.0 */ const DESC = 'Install a Reactium Plugin'; /** * CANCELED String * @description Message sent when the command is canceled * @since 2.0.0 */ const CANCELED = 'Action canceled!'; /** * HELP Function * @description Function called in the commander.on('--help', callback) callback. * @see https://www.npmjs.com/package/commander#automated---help * @since 2.0.0 */ const HELP = () => console.log(` Example: $ arcli install @atomic-reactor/admin For devops purposes you can call: $ arcli install This will install any previously installed plugins registered in the package.json > reactiumDependencies and package.json actiniumDependencies `); /** * ACTION Function * @description Function used as the commander.action() callback. * @see https://www.npmjs.com/package/commander * @param opt Object The commander options passed into the function. * @param props Object The CLI props passed from the calling class `orcli.js`. * @since 2.0.0 */ const ACTION = ({ name, opt, props }) => GENERATOR({ params: { name }, props }) .then(() => process.exit()) .catch(err => message(op.get(err, 'message', op.get(err, 'msg', CANCELED))), ); /** * COMMAND Function * @description Function that executes program.command() */ const COMMAND = ({ program, props }) => program .command(NAME) .description(DESC) .action((name, opt) => ACTION({ name, opt, props })) .on('--help', HELP); /** * Module Constructor * @description Internal constructor of the module that is being exported. * @param program Class Commander.program reference. * @param props Object The CLI props passed from the calling class `arcli.js`. * @since 2.0.0 */ module.exports = { COMMAND, NAME, };