-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmopar
executable file
·59 lines (50 loc) · 1.7 KB
/
mopar
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
#!/usr/bin/env node
'use strict';
var fmt = require('util').format;
var os = require('os');
var parallelize = require('./lib/parallelizer').parallelize;
var program = require('commander');
var reporters = require('./reporters');
function main() {
program
.description('Run a list of tasks in parallel')
.usage('--cwd /path/to/cwd ' +
'--env "FOO=bar BAR=baz" ' +
'--format "some mocha command %s" ' +
'--tasks "one_test.js two_test.js three_test.js"')
.version(require('./package').version)
.option('-c, --cwd [cwd]', 'directory to execute tasks')
.option('-e, --env [env]', 'environment variables')
.option('-f, --format [format]', 'template for tasks')
.option('-p, --parallel [parallel]', 'number of parallel tasks')
.option('-t, --tasks [tasks]', 'list of tasks')
.option('-r, --reporter [reporter]', 'reporter for output, `dot` or `xunit`')
.parse(process.argv);
var format = program.format || '%s';
var tasks = program.tasks.split(/\s+/).map(function (task) {
return fmt(format, task);
});
var opts = {
cwd: program.cwd || process.cwd(),
reporter: reporters[program.reporter ? program.reporter : 'dot']
};
if (program.env) {
var envs = program.env.split(/\s+/);
var env = {};
envs.forEach(function (pair) {
pair = pair.split('=');
env[pair[0]] = pair[1];
});
opts.env = env;
}
if (program.parallel && /\d+/.test(program.parallel)) {
opts.parallel = parseInt(program.parallel, 10);
} else {
opts.parallel = os.cpus().length; /* default to number of cpus */
}
opts.reporter.init(tasks.length, opts.parallel);
parallelize(tasks, opts);
}
if (require.main === module) {
main();
}