-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·55 lines (46 loc) · 2.11 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
#! /usr/bin/env node
import chalk from 'ansi-colors';
import Console from './lib/utils/console.js';
process.title = 'mber';
global.mainContext = global; // NOTE: needed for ember-template-compiler
let shouldRunCommand = false;
const CLI = {
async default(commandHandler) {
if (!process.argv[2]) {
shouldRunCommand = true;
return await commandHandler();
}
},
async command(commandName, commandHandler) {
const commandMatchesArray = Array.isArray(commandName) && commandName.includes(process.argv[2]);
if (commandMatchesArray || commandName === process.argv[2]) {
shouldRunCommand = true;
return await commandHandler();
}
}
};
(async () => {
CLI.default(async () => await runCommand('./lib/commands/index.js'));
CLI.command(['serve', 'server', 's'], async () => await runCommand('./lib/commands/serve.js')); // TODO: add proxy
CLI.command(['test', 't'], async () => await runCommand('./lib/commands/test.js')); // TODO: add --proxy
CLI.command(['build', 'b'], async () => await runCommand('./lib/commands/build.js')); // TODO: add --proxy
CLI.command(['compile', 'transpile', 'c'], async () => await runCommand('./lib/commands/compile.js'));
CLI.command(['console'], async () => await runCommand('./lib/commands/console.js'));
CLI.command(['help', 'h', 'print', 'p'], async () => await runCommand('./lib/commands/index.js'));
CLI.command(['init', 'new'], async () => await runCommand('./lib/commands/new.js'));
CLI.command(['generate', 'g', 'create'], async () => {
return (await import('./lib/commands/generate.js')).default(process.argv[3], process.argv[4])
});
CLI.command(['delete', 'd', 'destroy', 'remove'], async () => {
(await import('./lib/commands/delete.js')).default(process.argv[3], process.argv[4]);
});
if (!shouldRunCommand) {
Console.log(chalk.red('unknown command. Available options are:'));
await runCommand('./lib/commands/index.js');
setTimeout(() => process.exit(1), 100);
}
})();
async function runCommand(commandPath) {
return (await import(commandPath)).default();
}
// NOTE: maybe merge server and console commands in future?