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

9
justfile Normal file
View File

@@ -0,0 +1,9 @@
alias tl:=test-libraries
_:
@just --list
# test all libraries
test-libraries:
deno test --allow-all libraries/*

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,

View File

@@ -3,7 +3,7 @@ import {
encodeBase64Url,
getHomeDirOrDie,
hexStringToUint8Array,
} from "https://global.hatter.ink/script/get/@8/deno-commons-mod.ts";
} from "https://global.hatter.ink/script/get/@9/deno-commons-mod.ts";
import {getRandomValues} from "node:crypto";
import {assertEquals} from "jsr:@std/assert";