#!/usr/bin/env node /** * Generates `src/cli/src/config/opencode-extension.ts`, embedding the opencode * TUI plugin source as a string constant so `mcpctl config opencode` keeps * working from an installed binary with no source tree. * * Regenerate after editing the plugin source: * npx tsx scripts/generate-opencode-extension.ts */ import { readFileSync, writeFileSync, mkdirSync } from 'node:fs'; import { dirname, join } from 'node:path'; const scriptsDir = import.meta.dirname; const root = join(scriptsDir, '..'); const src = readFileSync(join(root, 'src', 'opencode-ext', 'mcpctl-opencode.tsx'), 'utf-8'); function embed(s: string) { // JSON.stringify yields a quoted string literal we can inline directly. return JSON.stringify(s); } const out = `/** * Embedded source of the mcpctl opencode plugin — DO NOT EDIT BY HAND. * Generated by \`npx tsx scripts/generate-opencode-extension.ts\` from * \`src/opencode-ext/mcpctl-opencode.tsx\`. * * \`mcpctl config opencode\` writes it verbatim into the opencode plugin dir and * registers it in opencode.json, so an installed binary with no source tree can * still provision a working opencode integration. */ export const OPENCODE_PLUGIN_FILENAME = 'mcpctl-switch.tsx' as const; export const OPENCODE_PLUGIN = ${embed(src)}; `; mkdirSync(dirname(join(root, 'src', 'cli', 'src', 'config')), { recursive: true }); writeFileSync(join(root, 'src', 'cli', 'src', 'config', 'opencode-extension.ts'), out); console.log('wrote src/cli/src/config/opencode-extension.ts');