-
-
Notifications
You must be signed in to change notification settings - Fork 152
/
cli.js
executable file
·107 lines (88 loc) · 2.65 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env node
'use strict';
// Require Modules.
import '@babel/polyfill';
import chalk from 'chalk';
import envinfo from 'envinfo';
import leven from 'leven';
import program from 'commander';
import updateNotifier from 'update-notifier';
// Defining action handlers for respective commands.
import add from './commands/add';
import codesplit from './commands/codesplit';
import deploy from './commands/deploy/';
import dockerize from './commands/dockerize';
import generate from './commands/generate';
import init from './commands/init';
import serve from './commands/serve';
import * as logger from './utils/logger';
import pkg from '../package';
updateNotifier({ pkg }).notify();
const suggestCommands = (cmd) => {
const availableCommands = program.commands.map((c) => c._name);
const suggestion = availableCommands.find(
(c) => leven(c, cmd) < c.length * 0.4,
);
if (suggestion) {
logger.error(` Did you mean ${chalk.yellow(suggestion)}?`);
}
};
// Defining all the available commands.
program.version(pkg.version).usage('<command> [options]');
program
.command('init <appname>')
.description('Scaffolds a MEVN stack project in the current path')
.action(init);
program
.command('codesplit')
.description('Lazy load components as required')
.action(codesplit);
program
.command('generate')
.description(
'Generates client side component files and server side CRUD boilerplate template',
)
.action(generate);
program
.command('add [deps...]')
.option('-d, --dev', 'install dev-dependencies')
.description('Install dependencies on the go')
.action(add);
program
.command('serve')
.description('Serves client/server locally')
.action(serve);
program
.command('dockerize')
.description('Serves the webapp as mult-container Docker applications')
.action(dockerize);
program
.command('deploy')
.description('Deploys the webapp to a cloud solution of choice')
.action(deploy);
program
.command('info')
.description('Prints debugging information about the local environment')
.action(() => {
console.log(chalk.bold('\nEnvironment Info:'));
envinfo
.run({
System: ['OS', 'CPU'],
Binaries: ['Node', 'Yarn', 'npm'],
Browsers: ['Chrome', 'Edge', 'Firefox', 'Safari'],
npmGlobalPackages: ['mevn-cli'],
})
.then(console.log);
});
// Validation for unknown commands
program.on('command:*', ([cmd]) => {
program.outputHelp();
logger.error(`\n Unknown command ${chalk.yellow(cmd)}.\n`);
suggestCommands(cmd);
process.exitCode = 1;
});
program.parse(process.argv);
// Shows up help if no arguments were provided.
if (!program.args.length) {
program.help();
}