UNPKG

1.84 kBJavaScriptView Raw
1const { is } = require("@algebraic/type");
2const build = require("../isomorphic-build.js");
3const Target = require("../target");
4
5const { basename, extname, resolve } = require("path");
6const glob = require("fast-glob");
7const moment = require("moment");
8const expand = path => path.replace(/^~/, process.env.HOME);
9
10const options = require("commander")
11 .version(require("../package").version)
12 .option("-c, --concurrency [concurrency]",
13 "Max number of test files running at the same time (Default: CPU cores)",
14 require("os").cpus().length)
15 .option("--cache", undefined)
16 .option("-o, --output [output]", "", `${process.cwd()}/output`)
17 .option("-r, --root [root]", "", process.cwd())
18 .parse(process.argv);
19
20const patterns = options.args.length <= 0 ? [] : options.args;
21
22(async function ()
23{
24 const entrypoints = Array.from(new Set(
25 [].concat(...patterns.map(pattern => glob.sync(pattern)))))
26 .map(path => resolve(path));
27
28 if (entrypoints.length <= 0)
29 return fail(
30 `\nNo files to process, perhaps there is a typo in your pattern:` +
31 `\n${patterns.map(pattern => ` ${pattern}`).join("\n")}\n`);
32
33 const cache = expand(options.cache || options.output + "/cache");
34 const destination = expand(options.output);
35 const toDestination = entrypoint =>
36 `${destination}/${basename(entrypoint, extname(entrypoint))}.bundle.js`;
37
38 const targets = entrypoints
39 .map(entrypoint => [entrypoint, toDestination(entrypoint)])
40 .map(([entrypoint, destination ]) =>
41 Target({ entrypoint, destination }));
42
43 const start = Date.now();
44 await build({ ...options, cache, targets });
45
46 console.log("TIME: " + (Date.now() - start));
47})();
48
49
50function fail(...args)
51{
52 console.error(...args);
53 process.exit(1);
54}
55