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