import { cp, mkdir, lstat, readFile } from "node:fs/promises"; import { fileURLToPath } from "node:url"; import path from "node:path"; const args = process.argv.slice(2); if (args.length !== 2 || args[0] !== "--project") throw Error("Usage: node scripts/install-skill.mjs --project "); const project = await import("node:fs/promises").then((fs) => fs.realpath(path.resolve(args[1])), ); const source = fileURLToPath( new URL("../dist/skills/anidev-design-system/", import.meta.url), ); await readFile(path.join(source, "SKILL.md")); let parent = project; for (const name of [".agents", "skills"]) { parent = path.join(parent, name); const stat = await lstat(parent).catch((e) => { if (e.code !== "ENOENT") throw e; }); if (stat?.isSymbolicLink() || (stat && !stat.isDirectory())) throw Error("Skill install path must be a real directory"); await mkdir(parent, { recursive: true }); } const target = path.join(parent, "anidev-design-system"); const exists = await lstat(target).catch((e) => { if (e.code !== "ENOENT") throw e; }); if (exists) throw Error( `Skill already exists; compare versions before replacing: ${target}`, ); await cp(source, target, { recursive: true, force: false, errorOnExist: true }); console.log(`Installed project skill: ${target}`);