-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.ts
executable file
·70 lines (51 loc) · 1.46 KB
/
cli.ts
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
'use strict';
//core
import path = require('path');
//npm
import residence = require('residence');
const dashdash = require('dashdash');
//project
import index = require('.');
import log from './lib/logging';
////////////////////////////////////////////////////////////////////////////////
const projectRoot = residence.findProjectRoot(process.cwd());
if (!projectRoot) {
log.error('your project root could not be found.');
process.exit(1);
}
let sumanConf;
try {
sumanConf = require(projectRoot + '/suman.conf.js');
}
catch (err) {
log.error('cannot find suman.conf.js in your project root.');
log.error(`your project root was presumed to be: ${projectRoot}.`);
process.exit(1);
}
let testDir = process.env.TEST_DIR = sumanConf.testDir;
if (!testDir) {
testDir = process.env.TEST_DIR = path.resolve(projectRoot + '/test');
}
log.info('testDir => ', testDir);
const options = require('./lib/cmd-opts');
let opts, parser = dashdash.createParser({options});
try {
opts = parser.parse(process.argv);
}
catch (e) {
console.error('There was an error parsing a Suman-Watch CLI option:\n%s', e.message);
process.exit(1);
}
log.info("# opts:", opts);
log.info("# args:", opts._args);
if (opts.help) {
var help = parser.help({includeEnv: true}).trimRight();
console.log('usage: node foo.js [OPTIONS]\n'
+ 'options:\n'
+ help);
process.exit(0);
}
index.run(opts, function (err: Error) {
if (err) throw err;
log.good('watch process ready.')
});