permitir generar solo algunos secretos

This commit is contained in:
Cat /dev/Nulo 2023-02-22 22:18:22 -03:00
parent 505178ec2f
commit 2a39aeb94b

View file

@ -1,5 +1,6 @@
import { mkdir, readFile, writeFile } from "node:fs/promises"; import { mkdir, readFile, writeFile } from "node:fs/promises";
import { join } from "node:path"; import { join } from "node:path";
import { exists } from "./better-api";
const secretsFileName = (name: string) => join("secrets", name + ".json"); const secretsFileName = (name: string) => join("secrets", name + ".json");
export function loadSecretsFile<T>(name: string): () => Promise<T> { export function loadSecretsFile<T>(name: string): () => Promise<T> {
@ -15,8 +16,13 @@ export function generateSecretsFile<T>(
return async () => { return async () => {
const secrets = await generate(); const secrets = await generate();
await mkdir("secrets", { recursive: true }); await mkdir("secrets", { recursive: true });
await writeFile(secretsFileName(name), JSON.stringify(secrets, null, 2), { const fileName = secretsFileName(name);
flag: "wx", if (await exists(fileName)) {
}); console.warn(`${fileName} ya existe, salteando..`);
} else {
await writeFile(fileName, JSON.stringify(secrets, null, 2), {
flag: "wx",
});
}
}; };
} }