UNPKG

1.16 kBPlain TextView Raw
1#!/usr/bin/env node
2
3var resolveModule = require('resolve').sync;
4var resolvePath = require('path').resolve;
5var parseOpts = require('minimist');
6var glob = require('glob');
7
8var opts = parseOpts(process.argv.slice(2), {
9 alias: { r: 'require' },
10 string: 'require',
11 default: { r: [] }
12 });
13
14var cwd = process.cwd();
15
16if (typeof opts.require === 'string') {
17 opts.require = [opts.require];
18}
19
20opts.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
29opts._.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