2021-04-27 02:58:24 +00:00
|
|
|
/*---------------------------------------------------------------------------------------------
|
|
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
|
|
*--------------------------------------------------------------------------------------------*/
|
2022-02-22 21:28:05 +00:00
|
|
|
//@ts-check
|
|
|
|
|
2021-04-27 02:58:24 +00:00
|
|
|
const path = require('path');
|
|
|
|
const fse = require('fs-extra');
|
|
|
|
const esbuild = require('esbuild');
|
|
|
|
|
|
|
|
const args = process.argv.slice(2);
|
|
|
|
|
|
|
|
const isWatch = args.indexOf('--watch') >= 0;
|
|
|
|
|
|
|
|
let outputRoot = __dirname;
|
|
|
|
const outputRootIndex = args.indexOf('--outputRoot');
|
|
|
|
if (outputRootIndex >= 0) {
|
|
|
|
outputRoot = args[outputRootIndex + 1];
|
|
|
|
}
|
|
|
|
|
2022-03-24 21:13:18 +00:00
|
|
|
const srcDir = path.join(__dirname, 'notebook');
|
2021-04-27 02:58:24 +00:00
|
|
|
const outDir = path.join(outputRoot, 'notebook-out');
|
2022-03-24 21:13:18 +00:00
|
|
|
|
|
|
|
async function build() {
|
|
|
|
await esbuild.build({
|
|
|
|
entryPoints: [
|
|
|
|
path.join(srcDir, 'katex.ts'),
|
|
|
|
],
|
|
|
|
bundle: true,
|
|
|
|
minify: true,
|
|
|
|
sourcemap: false,
|
|
|
|
format: 'esm',
|
|
|
|
outdir: outDir,
|
|
|
|
platform: 'browser',
|
|
|
|
target: ['es2020'],
|
|
|
|
});
|
|
|
|
|
|
|
|
fse.copySync(
|
|
|
|
path.join(__dirname, 'node_modules', 'katex', 'dist', 'katex.min.css'),
|
|
|
|
path.join(outDir, 'katex.min.css'));
|
|
|
|
|
|
|
|
const fontsDir = path.join(__dirname, 'node_modules', 'katex', 'dist', 'fonts');
|
|
|
|
const fontsOutDir = path.join(outDir, 'fonts/');
|
|
|
|
|
|
|
|
fse.mkdirSync(fontsOutDir, { recursive: true });
|
|
|
|
|
|
|
|
for (const file of fse.readdirSync(fontsDir)) {
|
|
|
|
if (file.endsWith('.woff2')) {
|
|
|
|
fse.copyFileSync(path.join(fontsDir, file), path.join(fontsOutDir, file));
|
|
|
|
}
|
2022-02-22 21:28:05 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-24 21:13:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
build().catch(() => process.exit(1));
|
|
|
|
|
|
|
|
if (isWatch) {
|
|
|
|
const watcher = require('@parcel/watcher');
|
2023-01-17 22:53:24 +00:00
|
|
|
watcher.subscribe(srcDir, async () => {
|
|
|
|
try {
|
|
|
|
await build();
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
2022-03-24 21:13:18 +00:00
|
|
|
});
|
|
|
|
}
|