UNPKG

1.01 kBJavaScriptView Raw
1const ora = require('ora');
2const base = require('./base');
3
4module.exports = (middleware, args, cli) => {
5 const commandName = args._[0];
6 const spinner = ora({ text: `Running ${commandName}` });
7
8 return base({
9 cli,
10 middleware,
11 args,
12 NODE_ENV: 'production',
13 commandName: `${commandName}-cli`,
14 commandHandler(config, neutrino) {
15 if (!args.quiet) {
16 spinner.enabled = global.interactive;
17 spinner.start();
18 }
19
20 const command = neutrino.commands[commandName];
21
22 if (!command) {
23 throw new Error(`A command with the name "${commandName}" was not registered`);
24 }
25
26 return command(config, neutrino);
27 },
28 errorsHandler() {
29 if (!args.quiet) {
30 spinner.fail(`Running ${commandName} failed`);
31 }
32 },
33 successHandler(output) {
34 if (!args.quiet) {
35 spinner.succeed(`Running ${commandName} completed`);
36
37 if (output != null) {
38 console.log(output);
39 }
40 }
41 }
42 });
43};