This repository has been archived by the owner on Dec 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
executable file
·73 lines (65 loc) · 1.76 KB
/
index.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
'use strict';
const commands = require('./commands');
const inquire = require('erector-set').inquire;
const colorize = require('./tools/utilities/colorize');
const logging = require('./tools/logging');
const main = (cliArgs) => {
const command = getCommandName(cliArgs[0]);
const commandArgs = cliArgs.slice(command === 'npm' ? 0 : 1);
const logger = logging.create('Librarian');
const rootDir = process.cwd();
if (typeof commands[command] === 'function') {
commands[command].apply(null, [rootDir].concat(commandArgs))
.catch((error) => logger.error(colorize.colorize(error, 'red')));
} else {
askForCommand();
}
};
const getCommandName = (command) => {
command = command ? command.replace(/^-+/, '') : command;
switch (command) {
case 'b':
case 'build':
case 'l':
case 'lint':
case 'pub':
case 'publish':
case 'serve':
case 't':
case 'test':
case 'v':
return 'npm';
case 'c':
case 'component':
return 'component';
case 'd':
case 'directive':
return 'directive';
case 'i':
case 'init':
case 'initial':
return 'initial';
case 'p':
case 'pipe':
return 'pipe';
case 's':
case 'service':
return 'service';
case 'u':
case 'up':
case 'upgrade':
return 'upgrade';
default:
return '';
}
};
const askForCommand = () => {
inquire([{
name: 'command',
question: 'What would you like to do?'
}])
.then((answers) => main(answers[0].answer.split(/\s+/)));
};
if (!module.parent) {
main(process.argv.slice(2));
}