UNPKG

1.61 kBJavaScriptView Raw
1#!/usr/bin/env node
2"use strict";
3/**
4 * @license
5 * Copyright Google LLC All Rights Reserved.
6 *
7 * Use of this source code is governed by an MIT-style license that can be
8 * found in the LICENSE file at https://angular.io/license
9 */
10Object.defineProperty(exports, "__esModule", { value: true });
11const fs_1 = require("fs");
12const path_1 = require("path");
13const build_optimizer_1 = require("./build-optimizer");
14/* eslint-disable no-console */
15if (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}
23const currentDir = process.cwd();
24const inputFile = process.argv[2];
25const tsOrJsRegExp = /\.(j|t)s$/;
26if (!inputFile.match(tsOrJsRegExp)) {
27 throw new Error(`Input file must be .js or .ts.`);
28}
29// Use provided output file, or add the .bo suffix before the extension.
30const outputFile = process.argv[3] || inputFile.replace(tsOrJsRegExp, (subStr) => `.bo${subStr}`);
31const boOutput = build_optimizer_1.buildOptimizer({
32 inputFilePath: path_1.join(currentDir, inputFile),
33 outputFilePath: path_1.join(currentDir, outputFile),
34 emitSourceMap: true,
35});
36if (boOutput.emitSkipped) {
37 console.log('Nothing to emit.');
38}
39else {
40 fs_1.writeFileSync(path_1.join(currentDir, outputFile), boOutput.content);
41 fs_1.writeFileSync(path_1.join(currentDir, `${outputFile}.map`), JSON.stringify(boOutput.sourceMap));
42 console.log('Emitted:');
43 console.log(` ${outputFile}`);
44 console.log(` ${outputFile}.map`);
45}