1 | #!/usr/bin/env node
|
2 |
|
3 | var resolveModule = require('resolve').sync;
|
4 | var resolvePath = require('path').resolve;
|
5 | var parseOpts = require('minimist');
|
6 | var glob = require('glob');
|
7 |
|
8 | var opts = parseOpts(process.argv.slice(2), {
|
9 | alias: { r: 'require' },
|
10 | string: 'require',
|
11 | default: { r: [] }
|
12 | });
|
13 |
|
14 | var cwd = process.cwd();
|
15 |
|
16 | if (typeof opts.require === 'string') {
|
17 | opts.require = [opts.require];
|
18 | }
|
19 |
|
20 | opts.require.forEach(function (module) {
|
21 | if (module) {
|
22 | /* This check ensures we ignore `-r ""`, trailing `-r`, or
|
23 | * other silly things the user might (inadvertently) be doing.
|
24 | */
|
25 | require(resolveModule(module, { basedir: cwd }));
|
26 | }
|
27 | });
|
28 |
|
29 | opts._.forEach(function (arg) {
|
30 | // If glob does not match, `files` will be an empty array.
|
31 | // Note: `glob.sync` may throw an error and crash the node process.
|
32 | var files = glob.sync(arg);
|
33 |
|
34 | if (!Array.isArray(files)) {
|
35 | throw new TypeError('unknown error: glob.sync did not return an array or throw. Please report this.');
|
36 | }
|
37 |
|
38 | files.forEach(function (file) {
|
39 | require(resolvePath(cwd, file));
|
40 | });
|
41 | });
|
42 |
|
43 | // vim: ft=javascript
|