feat: create script to verify env is up to date
This commit is contained in:
37
src/scripts/verifyEnv.ts
Normal file
37
src/scripts/verifyEnv.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import { $, sleep, spawn } from "bun";
|
||||||
|
import { readFile } from "fs/promises";
|
||||||
|
|
||||||
|
import { logStep } from "~/libs/logStep";
|
||||||
|
|
||||||
|
await $`cp src/types/env.d.ts /tmp/env.d.ts`.quiet();
|
||||||
|
|
||||||
|
await logStep(
|
||||||
|
'Generating "env.d.ts"',
|
||||||
|
() => 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
spawn({ cmd: ["sl", "diff", "src/types/env.d.ts"], stdout: "inherit" });
|
||||||
|
// add 1 second to make sure spawn completes
|
||||||
|
await sleep(1000);
|
||||||
|
throw new Error("env.d.ts is out of date");
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user