-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathplopfile.cjs
More file actions
128 lines (117 loc) · 4.78 KB
/
plopfile.cjs
File metadata and controls
128 lines (117 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/**
* Plop generator for creating new MCP tools.
*
* Usage:
* Interactive mode (requires TTY):
* npx plop create-tool
*
* Non-interactive mode (for CI, scripts, or non-TTY environments):
* npx plop create-tool "api-based" "ToolName"
* npx plop create-tool "local" "ToolName"
*
* Examples:
* npx plop create-tool "api-based" "Search"
* npx plop create-tool "local" "Validator"
*
* Tool types:
* - api-based: Makes API calls to Mapbox services
* - local: Local processing only, no API calls
*
* This generates:
* - src/tools/search-tool/SearchTool.ts
* - src/tools/search-tool/SearchTool.schema.ts
* - src/tools/search-tool/SearchTool.test.ts
* - Updates src/index.ts
* - Updates README.md
*/
module.exports = function (plop) {
// Register handlebars helpers
plop.setHelper('eq', function (a, b) {
return a === b;
});
plop.setGenerator('create-tool', {
description: 'Generate a TypeScript tool class and its test',
prompts: [
{
type: 'list',
name: 'toolType',
message: 'What type of tool do you want to create?',
choices: [
{
name: 'Mapbox tool (makes API calls to Mapbox services)',
value: 'api-based'
},
{
name: 'Local tool (local processing, no API calls)',
value: 'local'
}
]
},
{
type: 'input',
name: 'name',
message: 'Tool name without suffix using PascalCase e.g. Search:',
},
],
actions: function(data) {
const actions = [];
// Choose template based on tool type
const toolTemplate = data.toolType === 'api-based' ? 'plop-templates/mapbox-api-tool.hbs' : 'plop-templates/local-tool.hbs';
const testTemplate = data.toolType === 'api-based' ? 'plop-templates/mapbox-api-tool.test.hbs' : 'plop-templates/local-tool.test.hbs';
// Generate input schema
actions.push({
type: 'add',
path: 'src/tools/{{kebabCase name}}-tool/{{pascalCase name}}Tool.input.schema.ts',
templateFile: 'plop-templates/tool.input.schema.hbs',
data: { toolType: data.toolType }, // Pass toolType to template
});
// Generate output schema
actions.push({
type: 'add',
path: 'src/tools/{{kebabCase name}}-tool/{{pascalCase name}}Tool.output.schema.ts',
templateFile: 'plop-templates/tool.output.schema.hbs',
});
// Generate tool class
actions.push({
type: 'add',
path: 'src/tools/{{kebabCase name}}-tool/{{pascalCase name}}Tool.ts',
templateFile: toolTemplate,
});
// Generate test file in separate test directory
actions.push({
type: 'add',
path: 'test/tools/{{kebabCase name}}-tool/{{pascalCase name}}Tool.test.ts',
templateFile: testTemplate,
});
actions.push({
type: 'append',
path: 'src/index.ts',
pattern: /(\/\/ INSERT NEW TOOL REGISTRATION HERE)/,
template: 'new {{pascalCase name}}Tool().installTo(server);',
});
actions.push({
type: 'append',
path: 'src/index.ts',
pattern: /(\/\/ INSERT NEW TOOL IMPORT HERE)/,
template: "import { {{pascalCase name}}Tool } from './tools/{{kebabCase name}}-tool/{{pascalCase name}}Tool.js';",
});
actions.push({
type: 'append',
path: 'README.md',
pattern: /(### Tools)/,
template: '\n\n#### {{titleCase name}} tool\n\nDescription goes here...',
});
console.log('\n🎉 Tool created successfully!');
console.log('\n📝 Next steps:');
console.log('1. Update the input schema in {{pascalCase name}}Tool.schema.ts');
console.log('2. Update the tool description in {{pascalCase name}}Tool.ts');
console.log('3. Implement the tool logic in the execute method');
console.log('4. Update the test cases with actual test data');
console.log('5. Update the snapshot test to include the new tool:');
console.log(' npm test -- src/tools/tool-naming-convention.test.ts --updateSnapshot');
console.log('6. Run all tests to ensure everything works:');
console.log(' npm test');
return actions;
},
});
};