51 lines
2.0 KiB
TypeScript
51 lines
2.0 KiB
TypeScript
|
|
#!/usr/bin/env node
|
||
|
|
/**
|
||
|
|
* Generates `src/cli/src/config/opencode-extension.ts` which embeds the opencode
|
||
|
|
* plugin source (`open-mcpctl.tsx` + `projects.ts`) as string constants,
|
||
|
|
* mirroring how the pi and prime-agent extensions are embedded.
|
||
|
|
*
|
||
|
|
* Embedding matters: `mcpctl config opencode` must work from an installed
|
||
|
|
* binary that has no access to the source tree. The installed plugin files are
|
||
|
|
* this exact embedded source, so what the CLI ships is always what opencode
|
||
|
|
* runs.
|
||
|
|
*
|
||
|
|
* 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 opencodeExtDir = join(root, 'src', 'opencode-ext');
|
||
|
|
|
||
|
|
const MAIN = readFileSync(join(opencodeExtDir, 'open-mcpctl.tsx'), 'utf-8');
|
||
|
|
const PROJECTS = readFileSync(join(opencodeExtDir, 'projects.ts'), 'utf-8');
|
||
|
|
|
||
|
|
function embed(src) {
|
||
|
|
// JSON.stringify yields a quoted string literal we can inline directly.
|
||
|
|
return JSON.stringify(src);
|
||
|
|
}
|
||
|
|
|
||
|
|
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/open-mcpctl.tsx\` + \`src/opencode-ext/projects.ts\`.
|
||
|
|
*
|
||
|
|
* \`mcpctl config opencode\` writes these verbatim into
|
||
|
|
* ~/.config/opencode/plugin/ and registers \`open-mcpctl.tsx\` in opencode.json's
|
||
|
|
* plugin array, so an installed binary with no source tree can still provision
|
||
|
|
* a working opencode integration.
|
||
|
|
*/
|
||
|
|
export const OPENCODE_EXTENSION_FILENAMES = ['open-mcpctl.tsx', 'projects.ts'] as const;
|
||
|
|
|
||
|
|
export const OPENCODE_EXTENSION_FILES: Record<string, string> = {
|
||
|
|
'open-mcpctl.tsx': ${embed(MAIN)},
|
||
|
|
'projects.ts': ${embed(PROJECTS)},
|
||
|
|
};
|
||
|
|
`;
|
||
|
|
|
||
|
|
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');
|