UNPKG

6.61 kBJavaScriptView Raw
1#!/usr/bin/env node
2"use strict";
3/* -----------------------------------------------------------------------------
4| Copyright (c) Jupyter Development Team.
5| Distributed under the terms of the Modified BSD License.
6|----------------------------------------------------------------------------*/
7var __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}));
18var __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});
23var __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};
30var __importDefault = (this && this.__importDefault) || function (mod) {
31 return (mod && mod.__esModule) ? mod : { "default": mod };
32};
33Object.defineProperty(exports, "__esModule", { value: true });
34// Build an extension
35// Inputs:
36// Path to extension (required)
37// Dev vs prod (dev is default)
38// Output path (defaults to <extension>/build)
39// Outputs
40// Webpack build assets
41///////////////////////////////////////////////////////
42// Portions of the below code handling watch mode and displaying output were
43// adapted from the https://github.com/webpack/webpack-cli project, which has
44// an MIT license (https://github.com/webpack/webpack-cli/blob/4dc6dfbf29da16e61745770f7b48638963fb05c5/LICENSE):
45//
46// Copyright JS Foundation and other contributors
47//
48// Permission is hereby granted, free of charge, to any person obtaining
49// a copy of this software and associated documentation files (the
50// 'Software'), to deal in the Software without restriction, including
51// without limitation the rights to use, copy, modify, merge, publish,
52// distribute, sublicense, and/or sell copies of the Software, and to
53// permit persons to whom the Software is furnished to do so, subject to
54// the following conditions:
55//
56// The above copyright notice and this permission notice shall be
57// included in all copies or substantial portions of the Software.
58//
59// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
60// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
61// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
62// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
63// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
64// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
65// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
66///////////////////////////////////////////////////////
67const path = __importStar(require("path"));
68const commander_1 = require("commander");
69const webpack_1 = __importDefault(require("webpack"));
70const extensionConfig_1 = __importDefault(require("./extensionConfig"));
71const supports_color_1 = require("supports-color");
72commander_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 // Do not keep cache anymore
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});
155commander_1.program.parse(process.argv);
156// If no arguments supplied
157if (!process.argv.slice(2).length) {
158 commander_1.program.outputHelp();
159 process.exit(1);
160}
161//# sourceMappingURL=build-labextension.js.map
\No newline at end of file