-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
63 lines (51 loc) · 1.32 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
#!/usr/bin/env node
const docParse = require('./docParse');
const [, , ...args] = process.argv;
const helpMessage = () => {
const message = `
Useage: gendoc option argument ...
Generate documentation from from tags
/**
* @author Andrew Musgrave
* @see gendoc
* @since 0.1.0
* @example
* gendoc -e src\\components -o docs.json
*/
-h --help display help message
-e --entry entry point path
-o --output output path
`;
return message;
};
const unknownArg = arg => {
const message = `
${arg} is not a supported argument
`;
return message;
};
const logRed = message => {
console.log('\x1b[31m', message);
};
const logCyan = message => {
console.log('\x1b[36m', message);
};
const doubleOr = (value, a, b) => {
return value === a || value === b;
};
const settings = {};
for (let i = 0, length = args.length; i < length; i++) {
const currentArg = args[i];
if (doubleOr(currentArg, '-h', '--help')) {
logCyan(helpMessage());
process.exit(0);
} else if (doubleOr(currentArg, '-e', '--entry')) {
settings.entry = args[++i];
} else if (doubleOr(currentArg, '-o', '--output')) {
settings.output = args[++i];
} else {
logRed(unknownArg(currentArg));
process.exit(0);
}
}
docParse(settings);