Commit b3ee5f64 authored by HanseoSong's avatar HanseoSong
Browse files

fix(codegen): randomize output filename to prevent race condition in parallel test runs

parent 0f5c486a
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
import { loadSchemaFiles } from "./schema.ts";
import { generateClasses } from "./class.ts";
import { loadSchemaFiles } from "./schema.ts";

export async function main() {
  if (Deno.args.length != 2) {
    if (Deno.args.length < 2) {
  if (Deno.args.length != 3) {
    if (Deno.args.length < 3) {
      console.error("error: too few arguments");
    } else {
      console.error("error: too many arguments");
@@ -17,14 +17,19 @@ export async function main() {
  }
  const schemaDir = Deno.args[0];
  const runtimePath = Deno.args[1];
  const outputPath = Deno.args[2];
  if (!(await Deno.stat(schemaDir)).isDirectory) {
    console.error("error:", schemaDir, "is not a directory");
    Deno.exit(1);
  }
  const types = await loadSchemaFiles(schemaDir);
  const encoder = new TextEncoder();

  using file = await Deno.open(outputPath, { write: true, create: true });
  const writer = file.writable.getWriter();

  for await (const code of generateClasses(types, runtimePath)) {
    await Deno.stdout.write(encoder.encode(code));
    await writer.write(encoder.encode(code));
  }
}

+1 −1
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@
    "!vocab/vocab.ts"
  ],
  "tasks": {
    "codegen": "deno run --allow-read --allow-write --check codegen/main.ts vocab/ ../runtime/ > vocab/.vocab.ts && deno fmt vocab/.vocab.ts && mv vocab/.vocab.ts vocab/vocab.ts && deno cache vocab/vocab.ts && deno check vocab/vocab.ts",
    "codegen": "GENPATH=vocab-$(deno eval \"console.log(crypto.randomUUID());\").ts && deno run --allow-read --allow-write --check codegen/main.ts vocab/ ../runtime/ vocab/$GENPATH && deno fmt vocab/$GENPATH && deno cache vocab/$GENPATH && deno check vocab/$GENPATH && mv vocab/$GENPATH vocab/vocab.ts",
    "cache": {
      "command": "deno cache mod.ts",
      "dependencies": [
+1 −0
Original line number Diff line number Diff line
vocab.ts
.vocab.ts
vocab-*.ts