/
tape
executable file
·68 lines (54 loc) · 1.74 KB
/
tape
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
#!/usr/bin/env node
'use strict';
var parseOpts = require('minimist');
var opts = parseOpts(process.argv.slice(2), {
alias: { r: 'require', i: 'ignore' },
string: ['require', 'ignore'],
boolean: ['only'],
default: { r: [], i: null, only: null }
});
if (typeof opts.only === 'boolean') {
process.env.NODE_TAPE_NO_ONLY_TEST = !opts.only;
}
var cwd = process.cwd();
if (typeof opts.require === 'string') {
opts.require = [opts.require];
}
var resolveModule;
opts.require.forEach(function (module) {
if (module) {
if (!resolveModule) { resolveModule = require('resolve').sync; }
// This check ensures we ignore `-r ""`, trailing `-r`, or other silly things the user might (inadvertently) be doing.
require(resolveModule(module, { basedir: cwd }));
}
});
var resolvePath = require('path').resolve;
var matcher;
if (typeof opts.ignore === 'string') {
var readFileSync = require('fs').readFileSync;
try {
var ignoreStr = readFileSync(resolvePath(cwd, opts.ignore || '.gitignore'), 'utf-8');
} catch (e) {
console.error(e.message);
process.exit(2);
}
var ignore = require('dotignore');
matcher = ignore.createMatcher(ignoreStr);
}
var glob = require('glob');
opts._.reduce(function (result, arg) {
if (glob.hasMagic(arg)) {
// If glob does not match, `files` will be an empty array. Note: `glob.sync` may throw an error and crash the node process.
var files = glob.sync(arg);
if (!Array.isArray(files)) {
throw new TypeError('unknown error: glob.sync did not return an array or throw. Please report this.');
}
return result.concat(files);
}
return result.concat(arg);
}, []).filter(function (file) {
return !matcher || !matcher.shouldIgnore(file);
}).forEach(function (file) {
require(resolvePath(cwd, file));
});
// vim: ft=javascript