#!/usr/bin/env node import { access, copyFile, mkdir } from 'node:fs/promises'; import path from 'node:path'; const cwd = process.cwd(); function parseArgs(argv) { const out = {}; for (let i = 0; i < argv.length; i += 1) { const token = argv[i]; if (!token.startsWith('--')) continue; const key = token.slice(2); const next = argv[i + 1]; if (!next || next.startsWith('--')) { out[key] = 'true'; continue; } out[key] = next; i += 1; } return out; } async function exists(filePath) { try { await access(filePath); return true; } catch { return false; } } async function main() { const args = parseArgs(process.argv.slice(2)); const configDir = path.resolve(cwd, 'config'); const source = path.resolve(configDir, 'github-app-routing.example.json'); const target = path.resolve(configDir, args.target || 'github-app-routing.local.json'); const force = args.force === 'true'; await mkdir(configDir, { recursive: true }); if (!force && (await exists(target))) { console.log(JSON.stringify({ ok: true, created: false, source, target, message: 'local routing config already exists' }, null, 2)); return; } await copyFile(source, target); console.log(JSON.stringify({ ok: true, created: true, source, target }, null, 2)); } main().catch((error) => { console.error(error instanceof Error ? error.message : String(error)); process.exit(1); });