-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathargsManager.js
More file actions
88 lines (80 loc) · 2.46 KB
/
argsManager.js
File metadata and controls
88 lines (80 loc) · 2.46 KB
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
const minimist = require('minimist');
const _ = require('lodash');
const chalk = require('chalk');
const recognizedActions = {
generate: 'generate',
g: 'generate',
create: 'create',
c: 'create',
remove: 'remove',
r: 'remove',
list: 'list',
l: 'list',
un: 'unshallow',
unshallow: 'unshallow',
start: 'start',
};
const genericProcessor = (args) => {
const argsToProcess = args.slice(1);
const action = {
type: recognizedActions[args[0]],
args: [],
};
if (argsToProcess.length > 0) {
action.component = argsToProcess[0];
}
argsToProcess.shift();
if (argsToProcess.length > 0) {
action.args = argsToProcess;
}
return action;
};
const createProcessor = (args) => {
return {
type: 'create',
args: args.splice(0, 3)
}};
const argsProcessors = {
generate: genericProcessor,
remove: genericProcessor,
list: genericProcessor,
create: createProcessor,
start: genericProcessor,
};
function usage () {
const values = _.uniq(_.values(recognizedActions));
console.log(chalk.green('\nvulcan usage:'));
console.log(chalk.grey('\nSynopsis'));
console.log(' vulcan <action> <object> <...>\n');
console.log(' <action> Operation to perform ');
console.log(' <object> Asset type (contextual to action)');
console.log(' <...> Parameters. If not provided, interactively entered');
// console.log(chalk.grey('\nProject run'));
// console.log(' vulcan start');
console.log(chalk.grey('\nProject initialisation'));
console.log(' vulcan create <projectName> --style=(bootstrap|material)');
// console.log(' vulcan unshallow ');
console.log(chalk.grey('\nAssets creation'));
console.log(' vulcan (generate|g) package <packageName>');
console.log(' vulcan (generate|g) module <packageName> <moduleName>');
console.log(' vulcan (generate|g) component <packageName> <componentName>');
console.log(' vulcan (generate|g) route <packageName> <routeName> <routePath>');
console.log(chalk.grey('\nAssets removal'));
console.log(' vulcan (remove|r) package');
console.log(' vulcan (remove|r) module');
console.log(chalk.grey('\nAssets listing'));
console.log(' vulcan (list|l) packages');
process.exit();
}
function getAction () {
const args = minimist(process.argv.slice(2))._;
if (!recognizedActions[args[0]]) {
usage();
}
const actionName = recognizedActions[args[0]];
const actionObj = argsProcessors[actionName](args);
return actionObj;
}
module.exports = {
getAction,
};