Files
SkillCompiler/data/skills-bench/website/scripts/resolve-data-paths.ts
T
2026-09-04 14:58:42 +08:00

59 lines
1.8 KiBLFS
TypeScript

import fs from "fs";
import path from "path";
const GITHUB_RAW_BASE =
"https://raw.githubusercontent.com/benchflow-ai/skillsbench-trajectories/main";
/**
* Resolve the path to the tasks directory (for verifiers).
*/
export function resolveTasksDir(): string | null {
const candidates = [
path.join(__dirname, "..", "..", "tasks"),
path.join(__dirname, "..", "tasks"),
];
for (const candidate of candidates) {
if (fs.existsSync(candidate)) {
console.log(`[data] Using local tasks: ${candidate}`);
return candidate;
}
}
console.warn(`[data] Tasks directory not found in any expected location`);
return null;
}
/**
* Ensure output directory exists and write a JSON file.
*/
export function writeJsonOutput(outputPath: string, data: unknown): void {
const outputDir = path.dirname(outputPath);
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
fs.writeFileSync(outputPath, JSON.stringify(data, null, 2));
}
/**
* Fetch a pre-generated JSON file from `website-data/` in the trajectories repo
* (benchflow-ai/skillsbench-trajectories@main) — the canonical, single source
* for the results registry. Returns null on any HTTP/parse failure; callers
* decide whether that should abort the build.
*/
export async function fetchFromGitHub<T>(fileName: string): Promise<T | null> {
const url = `${GITHUB_RAW_BASE}/website-data/${fileName}`;
console.log(`[data] Fetching from GitHub: ${url}`);
try {
const res = await fetch(url);
if (!res.ok) {
console.warn(`[data] GitHub fetch failed: ${res.status} ${res.statusText}`);
return null;
}
return (await res.json()) as T;
} catch (err) {
console.warn(`[data] GitHub fetch error:`, (err as Error).message);
return null;
}
}