1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
7 | if (k2 === undefined) k2 = k;
|
8 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
9 | }) : (function(o, m, k, k2) {
|
10 | if (k2 === undefined) k2 = k;
|
11 | o[k2] = m[k];
|
12 | }));
|
13 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15 | }) : function(o, v) {
|
16 | o["default"] = v;
|
17 | });
|
18 | var __importStar = (this && this.__importStar) || function (mod) {
|
19 | if (mod && mod.__esModule) return mod;
|
20 | var result = {};
|
21 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22 | __setModuleDefault(result, mod);
|
23 | return result;
|
24 | };
|
25 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
26 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
27 | };
|
28 | Object.defineProperty(exports, "__esModule", { value: true });
|
29 | exports.Build = void 0;
|
30 | const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
|
31 | const fs = __importStar(require("fs-extra"));
|
32 | const glob = __importStar(require("glob"));
|
33 | const path = __importStar(require("path"));
|
34 |
|
35 |
|
36 |
|
37 | var Build;
|
38 | (function (Build) {
|
39 | |
40 |
|
41 |
|
42 |
|
43 |
|
44 | function ensureAssets(options) {
|
45 | var _a;
|
46 | const { output, schemaOutput = output, themeOutput = output, packageNames } = options;
|
47 | const themeConfig = [];
|
48 | const packagePaths = ((_a = options.packagePaths) === null || _a === void 0 ? void 0 : _a.slice()) || [];
|
49 | let cssImports = [];
|
50 | packageNames.forEach(name => {
|
51 | packagePaths.push(path.dirname(require.resolve(path.join(name, 'package.json'))));
|
52 | });
|
53 | packagePaths.forEach(packagePath => {
|
54 | const packageDataPath = require.resolve(path.join(packagePath, 'package.json'));
|
55 | const packageDir = path.dirname(packageDataPath);
|
56 | const data = fs.readJSONSync(packageDataPath);
|
57 | const name = data.name;
|
58 | const extension = normalizeExtension(data);
|
59 | const { schemaDir, themePath } = extension;
|
60 |
|
61 |
|
62 | if (typeof data.styleModule === 'string') {
|
63 | cssImports.push(`${name}/${data.styleModule}`);
|
64 | }
|
65 | else if (typeof data.style === 'string') {
|
66 | cssImports.push(`${name}/${data.style}`);
|
67 | }
|
68 |
|
69 | if (schemaDir) {
|
70 | const schemas = glob.sync(path.join(path.join(packageDir, schemaDir), '*'));
|
71 | const destination = path.join(schemaOutput, 'schemas', name);
|
72 |
|
73 | if (fs.existsSync(destination)) {
|
74 | try {
|
75 | const oldPackagePath = path.join(destination, 'package.json.orig');
|
76 | const oldPackageData = fs.readJSONSync(oldPackagePath);
|
77 | if (oldPackageData.version === data.version) {
|
78 | fs.removeSync(destination);
|
79 | }
|
80 | }
|
81 | catch (e) {
|
82 | fs.removeSync(destination);
|
83 | }
|
84 | }
|
85 |
|
86 | fs.mkdirpSync(destination);
|
87 |
|
88 | schemas.forEach(schema => {
|
89 | const file = path.basename(schema);
|
90 | fs.copySync(schema, path.join(destination, file));
|
91 | });
|
92 |
|
93 | fs.copySync(path.join(packageDir, 'package.json'), path.join(destination, 'package.json.orig'));
|
94 | }
|
95 | if (!themePath) {
|
96 | return;
|
97 | }
|
98 | themeConfig.push({
|
99 | mode: 'production',
|
100 | entry: {
|
101 | index: path.join(packageDir, themePath)
|
102 | },
|
103 | output: {
|
104 | path: path.resolve(path.join(themeOutput, 'themes', name)),
|
105 |
|
106 | filename: '[name].js',
|
107 | hashFunction: 'sha256'
|
108 | },
|
109 | module: {
|
110 | rules: [
|
111 | {
|
112 | test: /\.css$/,
|
113 | use: [mini_css_extract_plugin_1.default.loader, 'css-loader']
|
114 | },
|
115 | {
|
116 | test: /\.svg/,
|
117 | use: [{ loader: 'svg-url-loader', options: { encoding: 'none' } }]
|
118 | },
|
119 | {
|
120 | test: /\.(cur|png|jpg|gif|ttf|woff|woff2|eot)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
|
121 | use: [{ loader: 'url-loader', options: { limit: 10000 } }]
|
122 | }
|
123 | ]
|
124 | },
|
125 | plugins: [
|
126 | new mini_css_extract_plugin_1.default({
|
127 |
|
128 |
|
129 | filename: '[name].css',
|
130 | chunkFilename: '[id].css'
|
131 | })
|
132 | ]
|
133 | });
|
134 | });
|
135 | cssImports.sort((a, b) => a.localeCompare(b));
|
136 | const styleContents = `/* This is a generated file of CSS imports */
|
137 | /* It was generated by @jupyterlab/builder in Build.ensureAssets() */
|
138 |
|
139 | ${cssImports.map(x => `import '${x}';`).join('\n')}
|
140 | `;
|
141 | const stylePath = path.join(output, 'style.js');
|
142 |
|
143 | if (!fs.existsSync(output)) {
|
144 | fs.mkdirSync(output);
|
145 | }
|
146 | fs.writeFileSync(stylePath, styleContents, {
|
147 | encoding: 'utf8'
|
148 | });
|
149 | return themeConfig;
|
150 | }
|
151 | Build.ensureAssets = ensureAssets;
|
152 | |
153 |
|
154 |
|
155 | function normalizeExtension(module) {
|
156 | let { jupyterlab, main, name } = module;
|
157 | main = main || 'index.js';
|
158 | if (!jupyterlab) {
|
159 | throw new Error(`Module ${name} does not contain JupyterLab metadata.`);
|
160 | }
|
161 | let { extension, mimeExtension, schemaDir, themePath } = jupyterlab;
|
162 | extension = extension === true ? main : extension;
|
163 | mimeExtension = mimeExtension === true ? main : mimeExtension;
|
164 | if (extension && mimeExtension && extension === mimeExtension) {
|
165 | const message = 'extension and mimeExtension cannot be the same export.';
|
166 | throw new Error(message);
|
167 | }
|
168 | return { extension, mimeExtension, schemaDir, themePath };
|
169 | }
|
170 | Build.normalizeExtension = normalizeExtension;
|
171 | })(Build = exports.Build || (exports.Build = {}));
|
172 |
|
\ | No newline at end of file |