chore: remove unnecessary env scripts
since `wrangler types` works as intended now
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
import { Project } from "ts-morph";
|
||||
import { $ } from "zx";
|
||||
|
||||
import { logStep } from "~/libs/logStep";
|
||||
|
||||
await logStep(
|
||||
'Re-generating "env.d.ts"',
|
||||
() => $`wrangler types src/types/env.d.ts`.quiet(),
|
||||
"Generated env.d.ts",
|
||||
);
|
||||
|
||||
const secretNames = await logStep(
|
||||
"Fetching secrets from Cloudflare",
|
||||
async (): Promise<string[]> => {
|
||||
const { stdout } = await $`wrangler secret list`.quiet();
|
||||
return JSON.parse(stdout.toString()).map(
|
||||
(secret: { name: string; type: "secret_text" }) => secret.name,
|
||||
);
|
||||
},
|
||||
"Fetched secrets",
|
||||
);
|
||||
|
||||
const project = new Project({});
|
||||
|
||||
const envSourceFile = project.addSourceFileAtPath("src/types/env.d.ts");
|
||||
envSourceFile.insertImportDeclaration(2, {
|
||||
isTypeOnly: true,
|
||||
moduleSpecifier: "hono",
|
||||
namedImports: ["Env as HonoEnv"],
|
||||
});
|
||||
envSourceFile
|
||||
.getInterfaceOrThrow("Env")
|
||||
.addExtends(["HonoEnv", "Record<string, unknown>"]);
|
||||
envSourceFile.getInterfaceOrThrow("Env").addProperties(
|
||||
secretNames.map((name) => ({
|
||||
name,
|
||||
type: `string`,
|
||||
})),
|
||||
);
|
||||
|
||||
await project.save();
|
||||
|
||||
await logStep(
|
||||
"Formatting env.d.ts",
|
||||
() => $`prettier --write src/types/env.d.ts`.quiet(),
|
||||
"Formatted env.d.ts",
|
||||
);
|
||||
@@ -1,40 +0,0 @@
|
||||
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");
|
||||
});
|
||||
Reference in New Issue
Block a user