forked from CruGlobal/ab-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·83 lines (72 loc) · 2.06 KB
/
index.js
File metadata and controls
executable file
·83 lines (72 loc) · 2.06 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
#! /usr/bin/env node
// to add on debugging: #! /usr/bin/env node --inspect-brk
const fs = require("fs");
const path = require("path");
const clear = require("clear");
const chalk = require("chalk");
const junk = require("junk");
const utils = require(path.join(__dirname, "lib", "utils", "utils"));
// process command line arguments
let args = require("minimist")(process.argv.slice(2));
// console.log(args);
//// Load the command list:
var listFiles = fs.readdirSync(path.join(__dirname, "lib")).filter(junk.not);
var commandHash = {};
listFiles.forEach((file) => {
var stat = fs.statSync(path.join(__dirname, "lib", file));
if (stat.isFile()) {
var command = file.split(".")[0];
commandHash[command] = require(path.join(__dirname, "lib", command));
}
});
// console.log(commandHash);
//// find if command exists
var commandArg = args._.shift();
if (commandHash[commandArg]) {
// Run the Command
var command = commandHash[commandArg];
command
.run(args)
.then(() => {
console.log(`
done.
`);
process.exit(0);
})
.catch((err) => {
// if the calling command already displayed an error message
// we don't need to display this here.
if (!err._handled) {
clear();
console.log(err);
}
process.exit(1);
});
} else {
// display help screen with list of available commands:
clear();
console.log(`
$ appbuilder ${chalk.red.bold(commandArg)} ${process.argv.slice(3).join(" ")}
Unknown command: ${chalk.red.bold(commandArg)}
Available commands:
`);
var maxLength = 0;
for (var cmd in commandHash) {
if (cmd.length > maxLength) {
maxLength = cmd.length;
}
}
for (var c in commandHash) {
var cPad = utils.stringPad(c, maxLength + 1);
console.log(` ${cPad}: ${commandHash[c].descriptionShort}`);
}
console.log(`
`);
console.log(
`For more info on a specific command type: ${
chalk.green("appbuilder [command]") + chalk.yellow.bold(" --help ")
}`
);
console.log(`
`);
}