UNPKG

1.6 kBPlain TextView Raw
1#!/usr/bin/env node
2
3var fs = require('fs');
4var minimist = require('minimist');
5var path = require('path');
6var waitOn = require('../');
7
8var minimistOpts = {
9 string: ['c', 'd', 'i', 't', 'w', 'httpTimeout', 'tcpTimeout'],
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
24var argv = minimist(process.argv.slice(2), minimistOpts);
25
26
27if (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
33var opts = {};
34
35// if a js/json configuration file is provided require it
36var configFile = argv.config;
37if (configFile) {
38 opts = require(path.resolve(configFile));
39}
40
41// add in the resources listed on the command line
42opts.resources = argv._;
43
44// now check for specific options and set those
45opts = ['delay', 'httpTimeout', 'interval', 'log', 'reverse', 'timeout', 'tcpTimeout', 'verbose', 'window']
46 .reduce(function (accum, x) {
47 if (argv[x]) { accum[x] = argv[x]; }
48 return accum;
49 }, opts);
50
51waitOn(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
59function 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}