-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
executable file
·58 lines (50 loc) · 1.36 KB
/
main.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
#!/usr/bin/env node
var cli = require('cli').enable('status'),
fs = require('fs'),
_ = require('underscore')._;
var commands = {
'build': require('./builder/main.js'),
'serve': require('./serve/main.js'),
'test': require('./test/main.js'),
// {
// run: function(opt){
// opt.test = true
// commands.build.run(opt, function(){
// commands.serve.run(opt);
// });
// },
// name: 'Test',
// options: {}
// }
}
cli.parse(
// extend global options with the options member of each command module
_.reduce(commands, function(ops, cmd){
return _.extend(ops, cmd.options);
}, { // global options
src: ['s', 'Source directory', 'path', './src'],
build: ['b', 'Build directory', 'path', './build'],
verbose: ['v', 'Print more', 'boolean', false],
silent: ['s', 'stop output', 'boolean', false]
}),
_.keys(commands)
);
cli.main(function(args, opt){
if (opt.silent)
cli.status = function (msg, type) {}
cleanOpt(opt, function(opt){
cli.debug('options: '+ JSON.stringify(opt));
commands[cli.command].run(opt);
});
});
function cleanOpt(opt, clbk){
fs.realpath(opt.build, function(err, buildPath){
if (err) cli.fatal(err);
opt.build = buildPath;
fs.realpath(opt.src, function(err, srcPath){
if (err) cli.fatal(err);
opt.src = srcPath;
clbk(opt);
});
});
}