addons/isl/textmate.jsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318/*
b69ab319 * Runs the build script in the `textmate/` directory and produces two sets of
b69ab3110 * generated files:
b69ab3111 *
b69ab3112 * - `isl/src/generated/textmate/TextMateGrammarManifest.ts` is a
b69ab3113 * TypeScript source file that is used directly by other TypeScript code in
b69ab3114 * `isl/src`
b69ab3115 * - A folder of static resources written to `isl/public/generated/textmate`,
b69ab3116 * which allows ISL to fetch grammars at runtime.
b69ab3117 *
b69ab3118 * This script is expected to be run from the isl/ folder.
b69ab3119 */
b69ab3120
b69ab3121import * as child_process from 'node:child_process';
b69ab3122import * as fs from 'node:fs';
b69ab3123import * as url from 'node:url';
b69ab3124
b69ab3125const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
b69ab3126
b69ab3127process.chdir(__dirname); // always run relative to isl/
b69ab3128
b69ab3129// If no argument is specified, write the static resources to
b69ab3130// `isl/public/generated/textmate`.
b69ab3131const outputFolderArg = process.argv[2];
b69ab3132const grammarsFolder = outputFolderArg ?? './public/generated/textmate';
b69ab3133const textmateModule = '../textmate';
b69ab3134
b69ab3135rm_rf(grammarsFolder);
b69ab3136mkdir_p(grammarsFolder);
b69ab3137
b69ab3138function rm_rf(path) {
b69ab3139 fs.rmSync(path, {force: true, recursive: true});
b69ab3140}
b69ab3141
b69ab3142function mkdir_p(path) {
b69ab3143 fs.mkdirSync(path, {recursive: true});
b69ab3144}
b69ab3145
b69ab3146// Clear out the previous build of the textmate module.
b69ab3147rm_rf(`${textmateModule}/dist`);
b69ab3148// Rebuild the textmate module.
b69ab3149child_process.execSync('yarn', {cwd: textmateModule});
b69ab3150child_process.execSync('yarn run tsc', {cwd: textmateModule});
b69ab3151
b69ab3152const manifestFolder = 'src/generated/textmate';
b69ab3153rm_rf(manifestFolder);
b69ab3154mkdir_p(manifestFolder);
b69ab3155const manifestPath = `${manifestFolder}/TextMateGrammarManifest.ts`;
b69ab3156
b69ab3157const node = 'node';
b69ab3158child_process.execSync(`${node} ${textmateModule}/dist/index.js ${manifestPath} ${grammarsFolder}`);
b69ab3159
b69ab3160fs.copyFileSync(
b69ab3161 '../node_modules/vscode-oniguruma/release/onig.wasm',
b69ab3162 `${grammarsFolder}/onig.wasm`,
b69ab3163);