Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vocab/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
13 changes: 13 additions & 0 deletions packages/vocab/scripts/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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) {
Expand All @@ -12,6 +24,7 @@ async function codegen() {
const realPath = join(schemaDir, "vocab.ts");

await generateVocab(schemaDir, generatedPath);
await formatFile(generatedPath);
await rename(generatedPath, realPath);
}

Expand Down
Loading