Some checks failed
CI/CD / lint (pull_request) Successful in 1m7s
CI/CD / test (pull_request) Successful in 1m22s
CI/CD / typecheck (pull_request) Successful in 2m49s
CI/CD / smoke (pull_request) Failing after 1m54s
CI/CD / build (pull_request) Successful in 2m16s
CI/CD / publish (pull_request) Has been skipped
39 lines
1.5 KiB
JavaScript
39 lines
1.5 KiB
JavaScript
#!/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');
|