microsoft/typespec
Publicmirrored from https://github.com/microsoft/typespecAvailable
packages/compiler/scripts/watch-tmlanguage.js
25lines · modecode
| 1 | import { runWatch } from "@cadl-lang/internal-build-utils"; |
| 2 | import { copyFile } from "fs/promises"; |
| 3 | import mkdirp from "mkdirp"; |
| 4 | import { resolve } from "path"; |
| 5 | import { pathToFileURL } from "url"; |
| 6 | |
| 7 | let count = 0; |
| 8 | const scriptPath = resolve("dist/server/tmlanguage.js"); |
| 9 | |
| 10 | async function regenerate() { |
| 11 | const script = await import(`${pathToFileURL(scriptPath)}?q=${count++}`); |
| 12 | await script.main(); |
| 13 | await mkdirp("../cadl-vscode/dist"); |
| 14 | await copyFile("dist/cadl.tmLanguage", "../cadl-vscode/dist/cadl.tmLanguage"); |
| 15 | } |
| 16 | |
| 17 | runWatch("dist/server", regenerate, { |
| 18 | // This filter doesn't do as much as one might hope because tsc writes out all |
| 19 | // the files on recompilation. So tmlanguage.js changes when other .ts files |
| 20 | // in cadl-vscode change but tmlanguage.ts has not changed. We could check the |
| 21 | // tmlanguage.ts timestamp to fix it, but it didn't seem worth the complexity. |
| 22 | // We can't just watch tmlanguage.ts because we need to wait for tsc to |
| 23 | // compile it. |
| 24 | filter: (file) => file === scriptPath, |
| 25 | }); |
| 26 | |