diff --git a/packages/vocab/deno.json b/packages/vocab/deno.json index a7afbdb3..73dd5120 100644 --- a/packages/vocab/deno.json +++ b/packages/vocab/deno.json @@ -25,7 +25,7 @@ ], "tasks": { "check": "deno fmt --check && deno lint && deno check src/*.ts", - "compile": "deno run --allow-read --allow-write --allow-env --check scripts/codegen.ts && deno fmt src/vocab.ts && deno cache src/vocab.ts && deno check src/vocab.ts", + "compile": "deno run --allow-read --allow-write --allow-env --allow-run --check scripts/codegen.ts && deno cache src/vocab.ts && deno check src/vocab.ts", "test": "deno test --allow-read --allow-write --allow-env --unstable-kv --trace-leaks --parallel" } } diff --git a/packages/vocab/scripts/codegen.ts b/packages/vocab/scripts/codegen.ts index 9a178a88..02038c9b 100644 --- a/packages/vocab/scripts/codegen.ts +++ b/packages/vocab/scripts/codegen.ts @@ -2,6 +2,18 @@ import { generateVocab } from "@fedify/vocab-tools"; import { rename } from "node:fs/promises"; import { dirname, join } from "node:path"; +async function formatFile(filePath: string): Promise { + const command = new Deno.Command("deno", { + args: ["fmt", filePath], + stderr: "piped", + }); + const { code, stderr } = await command.output(); + if (code !== 0) { + const errorOutput = new TextDecoder().decode(stderr); + throw new Error(`deno fmt failed with exit code ${code}: ${errorOutput}`); + } +} + async function codegen() { const scriptsDir = import.meta.dirname; if (!scriptsDir) { @@ -12,6 +24,7 @@ async function codegen() { const realPath = join(schemaDir, "vocab.ts"); await generateVocab(schemaDir, generatedPath); + await formatFile(generatedPath); await rename(generatedPath, realPath); }