Migrate frontend sources to TypeScript
This commit is contained in:
@@ -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 ?? {})) {
|
||||
|
||||
Reference in New Issue
Block a user