microsoft/typespec

Public

mirrored from https://github.com/microsoft/typespecAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
bead6d153df3e7bd00100e72ae51a740bba955e6

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

packages/compiler/scripts/watch-tmlanguage.js

25lines · modecode

1import { runWatch } from "@cadl-lang/internal-build-utils";
2import { copyFile } from "fs/promises";
3import mkdirp from "mkdirp";
4import { resolve } from "path";
5import { pathToFileURL } from "url";
6
7let count = 0;
8const scriptPath = resolve("dist/server/tmlanguage.js");
9
10async 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
17runWatch("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