Migrate frontend sources to TypeScript

This commit is contained in:
2026-02-24 21:35:15 +01:00
parent fa3b46c8a9
commit 757f9a259e
13 changed files with 403 additions and 51 deletions

View File

@@ -1,21 +1,20 @@
import { readFile } from "node:fs/promises";
import path from "node:path";
import { spawnSync } from "node:child_process";
import { fileURLToPath } from "node:url";
const scriptDirectory = path.dirname(fileURLToPath(import.meta.url));
const repoRoot = path.resolve(scriptDirectory, "..");
const openApiPath = path.join(repoRoot, "openapi", "RpgRoller.json");
const appJsPath = path.join(repoRoot, "RpgRoller", "wwwroot", "app.js");
const generatedClientPath = path.join(repoRoot, "RpgRoller", "wwwroot", "generated", "api-client.js");
const appTsPath = path.join(repoRoot, "RpgRoller", "frontend", "app.ts");
const generatedClientPath = path.join(repoRoot, "RpgRoller", "frontend", "generated", "api-client.ts");
const openApi = JSON.parse(await readFile(openApiPath, "utf8"));
const generatedClient = await readFile(generatedClientPath, "utf8");
const appSource = await readFile(appTsPath, "utf8");
const errors = [];
const appSyntaxCheck = spawnSync(process.execPath, ["--check", appJsPath], { encoding: "utf8" });
if (appSyntaxCheck.status !== 0) {
errors.push(`Syntax error in ${path.relative(repoRoot, appJsPath)}:\n${appSyntaxCheck.stderr}`);
if (!appSource.includes("from \"./generated/api-client.js\"")) {
errors.push("Frontend app.ts must import the generated api-client module.");
}
for (const [pathKey, pathItem] of Object.entries(openApi.paths ?? {})) {