import fs from "node:fs/promises"; import path from "node:path"; import { fileURLToPath } from "node:url"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const rootDir = path.resolve(__dirname, ".."); const configPath = path.join(rootDir, "skills.json"); async function main() { const raw = await fs.readFile(configPath, "utf-8"); const config = JSON.parse(raw); console.log(`[sync-skills] Found ${Object.keys(config.skills).length} skill definitions`); for (const [name, def] of Object.entries(config.skills)) { const { version, url, destination } = def; const targetUrl = url.replace("{version}", version); const destPath = path.join(rootDir, destination); console.log(`[sync-skills] Syncing ${name} (${version}) from ${targetUrl}...`); const res = await fetch(targetUrl); if (!res.ok) { throw new Error(`Failed to fetch ${targetUrl}: HTTP ${res.status} ${res.statusText}`); } const content = await res.text(); if (!content.trim()) { throw new Error(`Fetched empty content for ${name}`); } await fs.mkdir(path.dirname(destPath), { recursive: true }); await fs.writeFile(destPath, content, "utf-8"); console.log(`[sync-skills] ✓ Updated ${destination} (${content.length} bytes)`); } console.log("[sync-skills] All skills synced successfully."); } main().catch((err) => { console.error("[sync-skills] Error:", err.message); process.exit(1); });