refactor: create generic function to log steps, fix type

This commit is contained in:
2024-06-03 08:39:41 -04:00
parent 9c1559bce5
commit 9f899ac6d1
2 changed files with 28 additions and 12 deletions

View File

@@ -1,18 +1,20 @@
import { $ } from "bun"; import { $ } from "bun";
import { Project } from "ts-morph"; import { Project } from "ts-morph";
console.log('Re-generating "env.d.ts"'); await logStep('Re-generating "env.d.ts"', "Generated env.d.ts", () =>
console.time("Generated env.d.ts"); $`bunx wrangler types src/types/env.d.ts`.quiet(),
await $`bunx wrangler types src/types/env.d.ts`.quiet(); );
console.timeEnd("Generated env.d.ts");
const secretNames = await logStep(
console.time("Fetched secrets"); "Fetching secrets from Cloudflare",
console.log("Fetching secrets from Cloudflare"); "Fetched secrets",
const { stdout } = await $`bunx wrangler secret list`.quiet(); async (): Promise<string[]> => {
const secretNames: string[] = JSON.parse(stdout.toString()).map( const { stdout } = await $`bunx wrangler secret list`.quiet();
(secret: { name: string; type: "secret_text" }) => secret.name, return JSON.parse(stdout.toString()).map(
(secret: { name: string; type: "secret_text" }) => secret.name,
);
},
); );
console.timeEnd("Fetched secrets");
const project = new Project({}); const project = new Project({});
@@ -30,3 +32,17 @@ envFile.getInterfaceOrThrow("Env").addProperties(
); );
await project.save(); await project.save();
async function logStep<T = void>(
inProgressText: string,
doneText: string,
step: () => Promise<T> | T,
) {
console.time(doneText);
console.log(`${inProgressText}...`);
return Promise.resolve(step()).then((value) => {
console.timeEnd(doneText);
return value;
});
}

2
src/types/env.d.ts vendored
View File

@@ -1,4 +1,4 @@
// Generated by Wrangler on Mon Jun 03 2024 08:28:23 GMT-0400 (Eastern Daylight Time) // Generated by Wrangler on Mon Jun 03 2024 08:35:59 GMT-0400 (Eastern Daylight Time)
// by running `wrangler types src/types/env.d.ts` // by running `wrangler types src/types/env.d.ts`
import type { Env as HonoEnv } from "hono"; import type { Env as HonoEnv } from "hono";