mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-27 09:21:35 +07:00
refactor: dedupe test and script helpers
This commit is contained in:
20
vitest.pattern-file.ts
Normal file
20
vitest.pattern-file.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import fs from "node:fs";
|
||||
|
||||
export function loadPatternListFile(filePath: string, label: string): string[] {
|
||||
const parsed = JSON.parse(fs.readFileSync(filePath, "utf8")) as unknown;
|
||||
if (!Array.isArray(parsed)) {
|
||||
throw new TypeError(`${label} must point to a JSON array: ${filePath}`);
|
||||
}
|
||||
return parsed.filter((value): value is string => typeof value === "string" && value.length > 0);
|
||||
}
|
||||
|
||||
export function loadPatternListFromEnv(
|
||||
envKey: string,
|
||||
env: Record<string, string | undefined> = process.env,
|
||||
): string[] | null {
|
||||
const filePath = env[envKey]?.trim();
|
||||
if (!filePath) {
|
||||
return null;
|
||||
}
|
||||
return loadPatternListFile(filePath, envKey);
|
||||
}
|
||||
Reference in New Issue
Block a user