1.9 KB64 lines
Blame
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8/*
9 * Runs the build script in the `textmate/` directory and produces two sets of
10 * generated files:
11 *
12 * - `isl/src/generated/textmate/TextMateGrammarManifest.ts` is a
13 * TypeScript source file that is used directly by other TypeScript code in
14 * `isl/src`
15 * - A folder of static resources written to `isl/public/generated/textmate`,
16 * which allows ISL to fetch grammars at runtime.
17 *
18 * This script is expected to be run from the isl/ folder.
19 */
20
21import * as child_process from 'node:child_process';
22import * as fs from 'node:fs';
23import * as url from 'node:url';
24
25const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
26
27process.chdir(__dirname); // always run relative to isl/
28
29// If no argument is specified, write the static resources to
30// `isl/public/generated/textmate`.
31const outputFolderArg = process.argv[2];
32const grammarsFolder = outputFolderArg ?? './public/generated/textmate';
33const textmateModule = '../textmate';
34
35rm_rf(grammarsFolder);
36mkdir_p(grammarsFolder);
37
38function rm_rf(path) {
39 fs.rmSync(path, {force: true, recursive: true});
40}
41
42function mkdir_p(path) {
43 fs.mkdirSync(path, {recursive: true});
44}
45
46// Clear out the previous build of the textmate module.
47rm_rf(`${textmateModule}/dist`);
48// Rebuild the textmate module.
49child_process.execSync('yarn', {cwd: textmateModule});
50child_process.execSync('yarn run tsc', {cwd: textmateModule});
51
52const manifestFolder = 'src/generated/textmate';
53rm_rf(manifestFolder);
54mkdir_p(manifestFolder);
55const manifestPath = `${manifestFolder}/TextMateGrammarManifest.ts`;
56
57const node = 'node';
58child_process.execSync(`${node} ${textmateModule}/dist/index.js ${manifestPath} ${grammarsFolder}`);
59
60fs.copyFileSync(
61 '../node_modules/vscode-oniguruma/release/onig.wasm',
62 `${grammarsFolder}/onig.wasm`,
63);
64