Files
WRNexusJS/scripts/build-editor-language-server.mjs
T
Clintchiz 586a6db8ff
Quality / quality (ubuntu-latest) (push) Failing after 21s
Quality / quality (windows-latest) (push) Canceled after 0s
release: WRNexusJS 0.8.0
2026-08-02 23:18:51 +05:30

31 lines
1.4 KiB
JavaScript

import console from "node:console";
import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, relative, resolve } from "node:path";
import { spawnSync } from "node:child_process";
import process from "node:process";
const root = resolve(import.meta.dirname, "..");
const source = join(root, "packages", "language-server", "src", "server.ts");
const destination = join(root, "editors", "vscode", "src", "language-server.cjs");
const check = process.argv.includes("--check");
const temporary = check ? mkdtempSync(join(tmpdir(), "wrnexus-editor-lsp-")) : null;
const output = temporary ? join(temporary, "language-server.cjs") : destination;
try {
const built = spawnSync(
process.env.WRNEXUS_BUN_BINARY || "bun",
["build", source, "--target=node", "--format=cjs", `--outfile=${output}`],
{ cwd: root, encoding: "utf8" },
);
if (built.status !== 0) throw new Error(built.stderr || built.stdout || "LSP bundle failed");
if (check) {
if (!existsSync(destination) || readFileSync(destination).compare(readFileSync(output)) !== 0)
throw new Error(
`${relative(root, destination)} is stale. Run bun run --cwd editors/vscode build.`,
);
console.log(`Verified ${relative(root, destination)} matches the language server sources.`);
} else console.log(`Built ${relative(root, destination)}.`);
} finally {
if (temporary) rmSync(temporary, { recursive: true, force: true });
}