refactor: move generateEnv script inside folder
This commit is contained in:
23
src/libs/logStep.ts
Normal file
23
src/libs/logStep.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
export async function logStep<T = void>(
|
||||||
|
inProgressText: string,
|
||||||
|
step: () => Promise<T> | T,
|
||||||
|
): Promise<T>;
|
||||||
|
export async function logStep<T = void>(
|
||||||
|
inProgressText: string,
|
||||||
|
step: () => Promise<T> | T,
|
||||||
|
doneText: string,
|
||||||
|
): Promise<T>;
|
||||||
|
|
||||||
|
export async function logStep<T = void>(
|
||||||
|
inProgressText: string,
|
||||||
|
step: () => Promise<T> | T,
|
||||||
|
doneText: string = `Completed step "${inProgressText}"`,
|
||||||
|
) {
|
||||||
|
console.time(doneText);
|
||||||
|
console.log(`${inProgressText}...`);
|
||||||
|
|
||||||
|
return Promise.resolve(step()).then((value) => {
|
||||||
|
console.timeEnd(doneText);
|
||||||
|
return value;
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,19 +1,23 @@
|
|||||||
import { $ } from "bun";
|
import { $ } from "bun";
|
||||||
import { Project } from "ts-morph";
|
import { Project } from "ts-morph";
|
||||||
|
|
||||||
await logStep('Re-generating "env.d.ts"', "Generated env.d.ts", () =>
|
import { logStep } from "~/libs/logStep";
|
||||||
$`bunx wrangler types src/types/env.d.ts`.quiet(),
|
|
||||||
|
await logStep(
|
||||||
|
'Re-generating "env.d.ts"',
|
||||||
|
() => $`bunx wrangler types src/types/env.d.ts`.quiet(),
|
||||||
|
"Generated env.d.ts",
|
||||||
);
|
);
|
||||||
|
|
||||||
const secretNames = await logStep(
|
const secretNames = await logStep(
|
||||||
"Fetching secrets from Cloudflare",
|
"Fetching secrets from Cloudflare",
|
||||||
"Fetched secrets",
|
|
||||||
async (): Promise<string[]> => {
|
async (): Promise<string[]> => {
|
||||||
const { stdout } = await $`bunx wrangler secret list`.quiet();
|
const { stdout } = await $`bunx wrangler secret list`.quiet();
|
||||||
return JSON.parse(stdout.toString()).map(
|
return JSON.parse(stdout.toString()).map(
|
||||||
(secret: { name: string; type: "secret_text" }) => secret.name,
|
(secret: { name: string; type: "secret_text" }) => secret.name,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
"Fetched secrets",
|
||||||
);
|
);
|
||||||
|
|
||||||
const project = new Project({});
|
const project = new Project({});
|
||||||
@@ -33,20 +37,8 @@ envFile.getInterfaceOrThrow("Env").addProperties(
|
|||||||
|
|
||||||
await project.save();
|
await project.save();
|
||||||
|
|
||||||
await logStep("Formatting env.d.ts", "Formatted env.d.ts", () =>
|
await logStep(
|
||||||
$`bunx prettier --write src/types/env.d.ts`.quiet(),
|
"Formatting env.d.ts",
|
||||||
|
() => $`bunx prettier --write src/types/env.d.ts`.quiet(),
|
||||||
|
"Formatted env.d.ts",
|
||||||
);
|
);
|
||||||
|
|
||||||
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;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user