import { readFile } from "fs/promises"; import { $, sleep } from "zx"; import { logStep } from "~/libs/logStep"; await $`cp src/types/env.d.ts /tmp/env.d.ts`.quiet(); await logStep( 'Generating "env.d.ts"', // @ts-ignore () => import("./generateEnv"), "Generated env.d.ts", ); await logStep("Comparing env.d.ts", async () => { function filterComments(content: Buffer) { return content .toString() .split("\n") .filter((line) => !line.trim().startsWith("//")) .join("\n"); } const currentFileContent = filterComments(await readFile("/tmp/env.d.ts")); const generatedFileContent = filterComments( await readFile("src/types/env.d.ts"), ); if (currentFileContent === generatedFileContent) { console.log("env.d.ts is up to date"); return; } const isCI = process.env["IS_CI"] === "true"; const vcsCommand = isCI ? "git" : "sl"; await $`${vcsCommand} diff src/types/env.d.ts`.stdio("inherit"); // add 1 second to make sure spawn completes await sleep(1000); throw new Error("env.d.ts is out of date"); });