1 | #!/usr/bin/env node
|
2 | "use strict";
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | Object.defineProperty(exports, "__esModule", { value: true });
|
11 | const fs_1 = require("fs");
|
12 | const path_1 = require("path");
|
13 | const build_optimizer_1 = require("./build-optimizer");
|
14 |
|
15 | if (process.argv.length < 3 || process.argv.length > 4) {
|
16 | throw new Error(`
|
17 | build-optimizer should be called with either one or two arguments:
|
18 |
|
19 | build-optimizer input.js
|
20 | build-optimizer input.js output.js
|
21 | `);
|
22 | }
|
23 | const currentDir = process.cwd();
|
24 | const inputFile = process.argv[2];
|
25 | const tsOrJsRegExp = /\.(j|t)s$/;
|
26 | if (!inputFile.match(tsOrJsRegExp)) {
|
27 | throw new Error(`Input file must be .js or .ts.`);
|
28 | }
|
29 |
|
30 | const outputFile = process.argv[3] || inputFile.replace(tsOrJsRegExp, (subStr) => `.bo${subStr}`);
|
31 | const boOutput = (0, build_optimizer_1.buildOptimizer)({
|
32 | inputFilePath: (0, path_1.join)(currentDir, inputFile),
|
33 | outputFilePath: (0, path_1.join)(currentDir, outputFile),
|
34 | emitSourceMap: true,
|
35 | });
|
36 | if (boOutput.emitSkipped) {
|
37 | console.log('Nothing to emit.');
|
38 | }
|
39 | else {
|
40 | (0, fs_1.writeFileSync)((0, path_1.join)(currentDir, outputFile), boOutput.content);
|
41 | (0, fs_1.writeFileSync)((0, path_1.join)(currentDir, `${outputFile}.map`), JSON.stringify(boOutput.sourceMap));
|
42 | console.log('Emitted:');
|
43 | console.log(` ${outputFile}`);
|
44 | console.log(` ${outputFile}.map`);
|
45 | }
|