3.5 KiB
3.5 KiB
description, argument-hint, model, allowed-tools
| description | argument-hint | model | allowed-tools | |
|---|---|---|---|---|
| Add TypeScript setup to a markdown-only plugin |
|
claude-sonnet-4-5-20250929 | Bash, Write, Edit, Read, Glob |
Upgrade Plugin to TypeScript
Add TypeScript setup to a markdown-only plugin, enabling CLI tools, utilities, and testable logic.
Instructions
You are a plugin maintenance specialist. Safely upgrade plugins to TypeScript while preserving existing content.
Input
The plugin name is provided as $1 (or $ARGUMENTS).
Validation
-
Verify plugin exists:
- Check
plugins/{name}directory exists - If not found, show error and list available plugins
- Check
-
Verify it's a markdown-only plugin:
- Check for absence of
tsconfig.json - If already TypeScript, inform user and exit
- Check for absence of
Files to Create
plugins/{name}/
├── tsconfig.json ✨ CREATE
└── src/ ✨ CREATE
├── index.ts ✨ CREATE
└── index.test.ts ✨ CREATE
Files to Modify
package.json - Replace stub scripts with full TypeScript scripts:
Before:
{
"scripts": {
"test": "echo 'No tests'",
"typecheck": "echo 'No typecheck'"
}
}
After:
{
"scripts": {
"test": "bun test --recursive",
"typecheck": "tsc --noEmit",
"format": "biome format --write .",
"format:check": "biome format .",
"lint": "biome lint .",
"check": "biome check --write ."
},
"devDependencies": {
"@types/bun": "latest"
}
}
Template Content
tsconfig.json:
{
"extends": "../../tsconfig.base.json",
"include": ["src/**/*.ts"],
"exclude": ["**/node_modules/**"]
}
src/index.ts - Use template from $PLUGIN_DIR/src/templates.ts:
- Export interface for plugin result type
- Export sample function with JSDoc
- Ready for user to add their logic
src/index.test.ts - Use template from $PLUGIN_DIR/src/templates.ts:
- Import from bun:test
- Basic test for sample function
- Ready for user to add more tests
Execution Steps
- Create tsconfig.json
- Create src/ directory
- Create src/index.ts with template
- Create src/index.test.ts with template
- Update package.json:
- Read current package.json
- Add full scripts
- Add devDependencies
- Write updated package.json
- Run bun install
- Run tests to verify
Files to Preserve
Do NOT touch these:
.claude-plugin/plugin.jsoncommands/directoryskills/directoryhooks/directorymcp-servers/directory.mcp.json
Post-Upgrade Steps
cd plugins/{name} && bun install && bun test
Output Summary
After upgrading:
Upgraded 'my-plugin' to TypeScript
Created:
- tsconfig.json
- src/index.ts
- src/index.test.ts
Modified:
- package.json (full scripts + devDependencies)
Next steps:
1. Edit src/index.ts to add your logic
2. Add tests to src/index.test.ts
3. Run 'bun test' to verify
To strip TypeScript later:
/plugin-template:strip my-plugin
Error Handling
- If plugin doesn't exist, list available plugins
- If already TypeScript, inform user (no action needed)
- If file creation fails, show error and cleanup steps
- If bun install fails, show manual steps
Example Usage
User: /plugin-template:upgrade my-plugin
Expected flow:
- Validate plugin exists and is markdown-only
- Create tsconfig.json
- Create src/index.ts and src/index.test.ts
- Update package.json with full scripts
- Run bun install
- Run bun test to verify
- Show summary with next steps