-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (45 loc) · 1.49 KB
/
index.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
#! /usr/bin/env node
var program = require('commander');
var damon = require('damon');
var pkg = require('./package.json');
var chalk = require('chalk');
program._name = pkg.name;
var timeoutExit;
function exitHandler (options, err) {
if (options.cleanup) {
damon.runner.clean();
}
if (err) {
console.log(chalk.bgRed(' -[ ERROR ]- '), err);
}
if (options.exit) {
clearTimeout(timeoutExit);
// Delay the exit to let async task to finish.
// Runner's logging for example.
timeoutExit = setTimeout(function () {
process.exit();
}, 100);
}
}
program
.version(pkg.version)
.option('-R, --reporter <path>', 'The reporter\'s file to use.')
.command('run <files...>')
.description('Run the list of JSON tasks files. Accepts glob.')
.action(function (files) {
damon.attachReporter(program.reporter);
damon.start(files);
damon.runner.on('finish', exitHandler.bind(null, {exit: true}, null));
});
program.parse(process.argv);
// TODO needs to instrumentalize the tmp folder for bots
// TODO pass actions files
// TODO pass helpers files
// so the program will not close instantly
process.stdin.resume();
// do something when app is closing
process.on('exit', exitHandler.bind(null, {cleanup: true}));
// catches ctrl+c event
process.on('SIGINT', exitHandler.bind(null, {exit: true}));
// catches uncaught exceptions
process.on('uncaughtException', exitHandler.bind(null, {exit: true}));