| 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 | |
| 21 | import * as child_process from 'node:child_process'; |
| 22 | import * as fs from 'node:fs'; |
| 23 | import * as url from 'node:url'; |
| 24 | |
| 25 | const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); |
| 26 | |
| 27 | process.chdir(__dirname); // always run relative to isl/ |
| 28 | |
| 29 | // If no argument is specified, write the static resources to |
| 30 | // `isl/public/generated/textmate`. |
| 31 | const outputFolderArg = process.argv[2]; |
| 32 | const grammarsFolder = outputFolderArg ?? './public/generated/textmate'; |
| 33 | const textmateModule = '../textmate'; |
| 34 | |
| 35 | rm_rf(grammarsFolder); |
| 36 | mkdir_p(grammarsFolder); |
| 37 | |
| 38 | function rm_rf(path) { |
| 39 | fs.rmSync(path, {force: true, recursive: true}); |
| 40 | } |
| 41 | |
| 42 | function mkdir_p(path) { |
| 43 | fs.mkdirSync(path, {recursive: true}); |
| 44 | } |
| 45 | |
| 46 | // Clear out the previous build of the textmate module. |
| 47 | rm_rf(`${textmateModule}/dist`); |
| 48 | // Rebuild the textmate module. |
| 49 | child_process.execSync('yarn', {cwd: textmateModule}); |
| 50 | child_process.execSync('yarn run tsc', {cwd: textmateModule}); |
| 51 | |
| 52 | const manifestFolder = 'src/generated/textmate'; |
| 53 | rm_rf(manifestFolder); |
| 54 | mkdir_p(manifestFolder); |
| 55 | const manifestPath = `${manifestFolder}/TextMateGrammarManifest.ts`; |
| 56 | |
| 57 | const node = 'node'; |
| 58 | child_process.execSync(`${node} ${textmateModule}/dist/index.js ${manifestPath} ${grammarsFolder}`); |
| 59 | |
| 60 | fs.copyFileSync( |
| 61 | '../node_modules/vscode-oniguruma/release/onig.wasm', |
| 62 | `${grammarsFolder}/onig.wasm`, |
| 63 | ); |
| 64 | |