|
| 1 | +#!/usr/bin/env node |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +// opencode-sdlc-wizard CLI entry point. |
| 5 | +// |
| 6 | +// Wraps the bundled `install.sh` so users can install via: |
| 7 | +// npx opencode-sdlc-wizard init |
| 8 | +// instead of the longer |
| 9 | +// git clone https://github.com/BaseInfinity/opencode-sdlc-wizard /tmp/... |
| 10 | +// bash /tmp/.../install.sh |
| 11 | +// |
| 12 | +// Subcommands: |
| 13 | +// init [options] Install the wizard into a target directory |
| 14 | +// |
| 15 | +// Init options pass through to install.sh: |
| 16 | +// --target-dir PATH Default: cwd |
| 17 | +// --force Overwrite existing customizations (default: keep) |
| 18 | +// --dry-run Preview changes without writing |
| 19 | +// |
| 20 | +// Top-level flags: |
| 21 | +// --help, -h Show this help |
| 22 | +// --version, -v Show version |
| 23 | + |
| 24 | +const fs = require('node:fs'); |
| 25 | +const path = require('node:path'); |
| 26 | +const { spawnSync } = require('node:child_process'); |
| 27 | + |
| 28 | +const repoRoot = path.resolve(__dirname, '..', '..'); |
| 29 | +const pkg = JSON.parse(fs.readFileSync(path.join(repoRoot, 'package.json'), 'utf8')); |
| 30 | +const installScript = path.join(repoRoot, 'install.sh'); |
| 31 | + |
| 32 | +const args = process.argv.slice(2); |
| 33 | + |
| 34 | +function printHelp() { |
| 35 | + process.stdout.write(`opencode-sdlc-wizard v${pkg.version} |
| 36 | +
|
| 37 | +Usage: |
| 38 | + npx opencode-sdlc-wizard init [options] Install wizard into a target directory |
| 39 | + npx opencode-sdlc-wizard --help Show this help |
| 40 | + npx opencode-sdlc-wizard --version Show version |
| 41 | +
|
| 42 | +init options (passed through to install.sh): |
| 43 | + --target-dir PATH Directory to install into (default: cwd) |
| 44 | + --force Overwrite existing customizations |
| 45 | + --dry-run Preview changes; do not write |
| 46 | +
|
| 47 | +After install: |
| 48 | + - AGENTS.md auto-loads on next OpenCode session |
| 49 | + - .opencode/plugins/sdlc-wizard.js subscribes to OpenCode events and |
| 50 | + fires the bash hooks at .opencode/hooks/ |
| 51 | + - Run 'bash .opencode/scripts/detect-backends.sh' to see available |
| 52 | + backends, then 'bash .opencode/scripts/configure-backend.sh |
| 53 | + --tier <t> --provider <p> --model <m>' to pin one in opencode.json |
| 54 | +
|
| 55 | +See https://github.com/BaseInfinity/opencode-sdlc-wizard for full docs. |
| 56 | +`); |
| 57 | +} |
| 58 | + |
| 59 | +if (args.includes('--help') || args.includes('-h')) { |
| 60 | + printHelp(); |
| 61 | + process.exit(0); |
| 62 | +} |
| 63 | + |
| 64 | +if (args.includes('--version') || args.includes('-v')) { |
| 65 | + process.stdout.write(pkg.version + '\n'); |
| 66 | + process.exit(0); |
| 67 | +} |
| 68 | + |
| 69 | +const subcommand = args.find((a) => !a.startsWith('-')); |
| 70 | + |
| 71 | +if (!subcommand) { |
| 72 | + printHelp(); |
| 73 | + process.exit(0); |
| 74 | +} |
| 75 | + |
| 76 | +if (subcommand !== 'init') { |
| 77 | + process.stderr.write(`Unknown subcommand: ${subcommand}\n\n`); |
| 78 | + printHelp(); |
| 79 | + process.exit(2); |
| 80 | +} |
| 81 | + |
| 82 | +// Forward everything except the leading 'init' to install.sh. install.sh's own |
| 83 | +// flag parser handles --target-dir, --force, --dry-run, --help passthrough. |
| 84 | +const installArgs = args.filter((a, i) => !(a === 'init' && args.indexOf('init') === i)); |
| 85 | + |
| 86 | +// Dry-run: install.sh has no --dry-run flag itself yet, so we honor it at the |
| 87 | +// wrapper layer by previewing what install.sh would do without actually |
| 88 | +// running it. We approximate by listing the bundle files (REQUIRED_SOURCES) |
| 89 | +// against the target. Full integration with install.sh's own dry-run would |
| 90 | +// require teaching install.sh the flag — deferred to the next iteration. |
| 91 | +if (installArgs.includes('--dry-run')) { |
| 92 | + // Find target dir from --target-dir or default to cwd |
| 93 | + let target = process.cwd(); |
| 94 | + for (let i = 0; i < installArgs.length; i++) { |
| 95 | + if (installArgs[i] === '--target-dir' && installArgs[i + 1]) { |
| 96 | + target = installArgs[i + 1]; |
| 97 | + break; |
| 98 | + } |
| 99 | + if (installArgs[i].startsWith('--target-dir=')) { |
| 100 | + target = installArgs[i].slice('--target-dir='.length); |
| 101 | + break; |
| 102 | + } |
| 103 | + } |
| 104 | + const required = [ |
| 105 | + 'AGENTS.md', |
| 106 | + 'PRIVACY.md', |
| 107 | + '.opencode/plugins/sdlc-wizard.js', |
| 108 | + '.opencode/hooks/_find-sdlc-root.sh', |
| 109 | + '.opencode/hooks/sdlc-prompt-check.sh', |
| 110 | + '.opencode/hooks/tdd-pretool-check.sh', |
| 111 | + '.opencode/hooks/instructions-loaded-check.sh', |
| 112 | + '.opencode/hooks/model-effort-check.sh', |
| 113 | + '.opencode/hooks/precompact-seam-check.sh', |
| 114 | + '.opencode/scripts/detect-backends.sh', |
| 115 | + '.opencode/scripts/configure-backend.sh', |
| 116 | + '.opencode/skills/sdlc/SKILL.md', |
| 117 | + '.opencode/skills/setup-wizard/SKILL.md', |
| 118 | + '.opencode/skills/update-wizard/SKILL.md', |
| 119 | + '.opencode/skills/feedback/SKILL.md', |
| 120 | + ]; |
| 121 | + process.stdout.write(`Dry run — install would create the following in ${target}:\n\n`); |
| 122 | + for (const f of required) { |
| 123 | + const dest = path.join(target, f); |
| 124 | + const status = fs.existsSync(dest) ? 'EXISTS' : 'CREATE'; |
| 125 | + process.stdout.write(` ${status} ${f}\n`); |
| 126 | + } |
| 127 | + process.stdout.write('\nNo files written. Re-run without --dry-run to apply.\n'); |
| 128 | + process.exit(0); |
| 129 | +} |
| 130 | + |
| 131 | +// Real run: invoke install.sh |
| 132 | +const result = spawnSync('bash', [installScript, ...installArgs], { |
| 133 | + stdio: 'inherit', |
| 134 | + cwd: process.cwd(), |
| 135 | +}); |
| 136 | + |
| 137 | +if (result.error) { |
| 138 | + process.stderr.write(`Failed to run install.sh: ${result.error.message}\n`); |
| 139 | + process.exit(1); |
| 140 | +} |
| 141 | + |
| 142 | +process.exit(result.status || 0); |
0 commit comments