Skip to content

Commit 41600a7

Browse files
authored
feat: add action params for custom tools (#91)
1 parent 94d7cb2 commit 41600a7

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,11 @@ type ExtraTool = {
221221
/**
222222
* The action to perform when the tool is selected.
223223
*/
224-
action?: () => unknown;
224+
action?: (context: {
225+
templateName: string;
226+
distFolder: string;
227+
addAgentsMdSearchDirs: (dir: string) => void;
228+
}) => unknown;
225229
/**
226230
* The custom command to run when the tool is selected.
227231
*/
@@ -374,7 +378,12 @@ export async function create({
374378
);
375379
if (matchedTool) {
376380
if (matchedTool.action) {
377-
await matchedTool.action();
381+
await matchedTool.action({
382+
templateName,
383+
distFolder,
384+
addAgentsMdSearchDirs: (dir: string) =>
385+
agentsMdSearchDirs.push(dir),
386+
});
378387
}
379388
if (matchedTool.command) {
380389
runCommand(matchedTool.command, distFolder);

test/custom-tools.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ test('should run extra tool action', async () => {
3535
{
3636
value: 'custom-action',
3737
label: 'Custom Action',
38-
action: () => {
38+
action: ({ templateName, distFolder }) => {
39+
expect(templateName).toBe('vanilla');
40+
expect(distFolder).toBe(projectDir);
3941
actionCalled = true;
4042
},
4143
},

0 commit comments

Comments
 (0)