1 | const { is } = require("@algebraic/type");
|
2 | const build = require("../isomorphic-build.js");
|
3 | const Target = require("../target");
|
4 |
|
5 | const { basename, extname, resolve } = require("path");
|
6 | const glob = require("fast-glob");
|
7 | const moment = require("moment");
|
8 | const expand = path => path.replace(/^~/, process.env.HOME);
|
9 |
|
10 | const 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 |
|
20 | const 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 |
|
50 | function fail(...args)
|
51 | {
|
52 | console.error(...args);
|
53 | process.exit(1);
|
54 | }
|
55 |
|