1 | #!/usr/bin/env node
|
2 | "use strict";
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
8 | if (k2 === undefined) k2 = k;
|
9 | var desc = Object.getOwnPropertyDescriptor(m, k);
|
10 | if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
11 | desc = { enumerable: true, get: function() { return m[k]; } };
|
12 | }
|
13 | Object.defineProperty(o, k2, desc);
|
14 | }) : (function(o, m, k, k2) {
|
15 | if (k2 === undefined) k2 = k;
|
16 | o[k2] = m[k];
|
17 | }));
|
18 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
19 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
20 | }) : function(o, v) {
|
21 | o["default"] = v;
|
22 | });
|
23 | var __importStar = (this && this.__importStar) || function (mod) {
|
24 | if (mod && mod.__esModule) return mod;
|
25 | var result = {};
|
26 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
27 | __setModuleDefault(result, mod);
|
28 | return result;
|
29 | };
|
30 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
31 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
32 | };
|
33 | Object.defineProperty(exports, "__esModule", { value: true });
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | const path = __importStar(require("path"));
|
68 | const commander_1 = require("commander");
|
69 | const webpack_1 = __importDefault(require("webpack"));
|
70 | const extensionConfig_1 = __importDefault(require("./extensionConfig"));
|
71 | const supports_color_1 = require("supports-color");
|
72 | commander_1.program
|
73 | .description('Build an extension')
|
74 | .option('--development', 'build in development mode (implies --source-map)')
|
75 | .option('--source-map', 'generate source maps')
|
76 | .requiredOption('--core-path <path>', 'the core package directory')
|
77 | .option('--static-url <url>', 'url for build assets, if hosted outside the built extension')
|
78 | .option('--watch')
|
79 | .action(async (options, command) => {
|
80 | const mode = options.development ? 'development' : 'production';
|
81 | const corePath = path.resolve(options.corePath || process.cwd());
|
82 | const packagePath = path.resolve(command.args[0]);
|
83 | const devtool = options.sourceMap ? 'source-map' : undefined;
|
84 | const config = (0, extensionConfig_1.default)({
|
85 | packagePath,
|
86 | mode,
|
87 | corePath,
|
88 | staticUrl: options.staticUrl,
|
89 | devtool,
|
90 | watchMode: options.watch
|
91 | });
|
92 | const compiler = (0, webpack_1.default)(config);
|
93 | let lastHash = null;
|
94 | function compilerCallback(err, stats) {
|
95 | if (!options.watch || err) {
|
96 |
|
97 | compiler.purgeInputFileSystem();
|
98 | }
|
99 | if (err) {
|
100 | console.error(err.stack || err);
|
101 | if (err.details) {
|
102 | console.error(err.details);
|
103 | }
|
104 | throw new Error(err.details);
|
105 | }
|
106 | const info = stats.toJson();
|
107 | if (stats.hasErrors()) {
|
108 | console.error(info.errors);
|
109 | if (!options.watch) {
|
110 | process.exit(2);
|
111 | }
|
112 | }
|
113 | if (stats.hash !== lastHash) {
|
114 | lastHash = stats.hash;
|
115 | const statsString = stats.toString({ colors: supports_color_1.stdout });
|
116 | const delimiter = '';
|
117 | if (statsString) {
|
118 | process.stdout.write(`${statsString}\n${delimiter}`);
|
119 | }
|
120 | }
|
121 | }
|
122 | if (options.watch) {
|
123 | compiler.hooks.watchRun.tap('WebpackInfo', () => {
|
124 | console.error('\nWatch Compilation starting…\n');
|
125 | });
|
126 | compiler.hooks.done.tap('WebpackInfo', () => {
|
127 | console.error('\nWatch Compilation finished\n');
|
128 | });
|
129 | }
|
130 | else {
|
131 | compiler.hooks.run.tap('WebpackInfo', () => {
|
132 | console.error('\nCompilation starting…\n');
|
133 | });
|
134 | compiler.hooks.done.tap('WebpackInfo', () => {
|
135 | console.error('\nCompilation finished\n');
|
136 | });
|
137 | }
|
138 | if (options.watch) {
|
139 | compiler.watch(config[0].watchOptions || {}, compilerCallback);
|
140 | console.error('\nwebpack is watching the files…\n');
|
141 | }
|
142 | else {
|
143 | compiler.run((err, stats) => {
|
144 | if (compiler.close) {
|
145 | compiler.close((err2) => {
|
146 | compilerCallback(err || err2, stats);
|
147 | });
|
148 | }
|
149 | else {
|
150 | compilerCallback(err, stats);
|
151 | }
|
152 | });
|
153 | }
|
154 | });
|
155 | commander_1.program.parse(process.argv);
|
156 |
|
157 | if (!process.argv.slice(2).length) {
|
158 | commander_1.program.outputHelp();
|
159 | process.exit(1);
|
160 | }
|
161 |
|
\ | No newline at end of file |