feat: add justfile

This commit is contained in:
2026-01-12 00:43:59 +08:00
parent 3a74da85d2
commit fa217ce0f2
3 changed files with 27 additions and 11 deletions

View File

@@ -42,25 +42,21 @@ export function isOn(val: string | undefined | null): boolean {
lowerVal === "true";
}
export async function getEnv(key: string): Promise<string | null> {
export function getEnv(envKey: string): string | null {
const homeDir = getHomeDir();
if ((homeDir !== null) && key) {
const envValue = await readFileToString(
`${homeDir}/.config/envs/${key}`,
if ((homeDir !== null) && envKey) {
const envValue = readFileToStringSync(
`${homeDir}/.config/envs/${envKey}`,
);
if (envValue !== null) {
return envValue.trim();
}
}
return Deno.env.get(key) || null;
return Deno.env.get(envKey) || null;
}
export function isEnvOn(envKey: string): boolean {
return isOn(Deno.env.get(envKey));
}
export async function isEnvOnAsync(envKey: string): Promise<boolean> {
return isOn(await getEnv(envKey));
return isOn(getEnv(envKey));
}
export function formatHumanTime(timeMillis: number): string {
@@ -311,6 +307,17 @@ export async function readFileToString(
}
}
export function readFileToStringSync(filename: string): string | null {
try {
return Deno.readTextFileSync(resolveFilename(filename));
} catch (e) {
if (e instanceof Error && e.name == "NotFound") {
return null;
}
throw e;
}
}
export async function writeStringToFile(
filename: string,
data: string | null,