|
| 1 | +#!/usr/bin/env node |
| 2 | +import { cpSync, existsSync, mkdirSync, rmSync } from 'node:fs'; |
| 3 | +import { dirname, join } from 'node:path'; |
| 4 | +import { homedir } from 'node:os'; |
| 5 | +import { fileURLToPath } from 'node:url'; |
| 6 | + |
| 7 | +const skillName = 'gpt-image-2-style-library'; |
| 8 | +const command = process.argv[2] || 'install'; |
| 9 | +const allowedCommands = new Set(['install', 'sync']); |
| 10 | + |
| 11 | +if (!allowedCommands.has(command)) { |
| 12 | + console.error(`Usage: gpt-image-2-style-library install`); |
| 13 | + process.exit(1); |
| 14 | +} |
| 15 | + |
| 16 | +const packageRoot = dirname(dirname(fileURLToPath(import.meta.url))); |
| 17 | +const codexHome = process.env.CODEX_HOME || join(homedir(), '.codex'); |
| 18 | +const targetRoot = join(codexHome, 'skills'); |
| 19 | +const target = join(targetRoot, skillName); |
| 20 | +const entries = ['SKILL.md', 'agents', 'references']; |
| 21 | + |
| 22 | +for (const entry of entries) { |
| 23 | + const source = join(packageRoot, entry); |
| 24 | + if (!existsSync(source)) { |
| 25 | + throw new Error(`Missing package entry: ${entry}`); |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +mkdirSync(targetRoot, { recursive: true }); |
| 30 | +rmSync(target, { recursive: true, force: true }); |
| 31 | +mkdirSync(target, { recursive: true }); |
| 32 | + |
| 33 | +for (const entry of entries) { |
| 34 | + cpSync(join(packageRoot, entry), join(target, entry), { recursive: true }); |
| 35 | +} |
| 36 | + |
| 37 | +console.log(`Installed ${skillName} to ${target}`); |
0 commit comments