1 | #!/usr/bin/env node
|
2 |
|
3 | var fs = require('fs');
|
4 | var minimist = require('minimist');
|
5 | var path = require('path');
|
6 | var waitOn = require('../');
|
7 |
|
8 | var minimistOpts = {
|
9 | string: ['c', 'd', 'i', 't', 'w'],
|
10 | boolean: ['h', 'l', 'r', 'v'],
|
11 | alias: {
|
12 | c: 'config',
|
13 | d: 'delay',
|
14 | i: 'interval',
|
15 | l: 'log',
|
16 | r: 'reverse',
|
17 | t: 'timeout',
|
18 | v: 'verbose',
|
19 | w: 'window',
|
20 | h: 'help'
|
21 | }
|
22 | };
|
23 |
|
24 | var argv = minimist(process.argv.slice(2), minimistOpts);
|
25 |
|
26 |
|
27 | if (argv.help || !argv._.length) { // help
|
28 | return fs.createReadStream(__dirname + '/usage.txt')
|
29 | .pipe(process.stdout)
|
30 | .on('close', function () { process.exit(1); });
|
31 | }
|
32 |
|
33 | var opts = {};
|
34 |
|
35 | // if a js/json configuration file is provided require it
|
36 | var configFile = argv.config;
|
37 | if (configFile) {
|
38 | opts = require(path.resolve(configFile));
|
39 | }
|
40 |
|
41 | // add in the resources listed on the command line
|
42 | opts.resources = argv._;
|
43 |
|
44 | // now check for specific options and set those
|
45 | opts = ['delay', 'interval', 'log', 'reverse', 'timeout', 'verbose', 'window']
|
46 | .reduce(function (accum, x) {
|
47 | if (argv[x]) { accum[x] = argv[x]; }
|
48 | return accum;
|
49 | }, opts);
|
50 |
|
51 | waitOn(opts, function (err) {
|
52 | if (err) { return errorExit(err); }
|
53 | // success, could just let it exit on its own, however since
|
54 | // rxjs window waits an extra loop before heeding the unsubscribe
|
55 | // we can exit to speed things up
|
56 | process.exit(0);
|
57 | });
|
58 |
|
59 | function errorExit(err) {
|
60 | if (err.stack) {
|
61 | console.error(err.stack);
|
62 | }
|
63 | else {
|
64 | console.error(String(err));
|
65 | }
|
66 | process.exit(1);
|
67 | }
|