Skip to content

Commit 041a1c0

Browse files
committed
feat: add action params for custom tools
1 parent f3bd03b commit 041a1c0

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

src/index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ function logHelpMessage(
105105
extraTools?: ExtraTool[],
106106
) {
107107
const extraToolNames = extraTools?.map((tool) => tool.value) ?? [];
108-
const toolsList = [...BUILTIN_TOOLS, ...extraToolNames].join(
109-
', ',
110-
);
108+
const toolsList = [...BUILTIN_TOOLS, ...extraToolNames].join(', ');
111109

112110
logger.log(`
113111
Usage: create-${name} [dir] [options]
@@ -222,7 +220,11 @@ type ExtraTool = {
222220
/**
223221
* The action to perform when the tool is selected.
224222
*/
225-
action?: () => unknown;
223+
action?: (context: {
224+
templateName: string;
225+
distFolder: string;
226+
addAgentsMdSearchDirs: (dir: string) => void;
227+
}) => unknown;
226228
/**
227229
* The custom command to run when the tool is selected.
228230
*/
@@ -368,7 +370,12 @@ export async function create({
368370
);
369371
if (matchedTool) {
370372
if (matchedTool.action) {
371-
await matchedTool.action();
373+
await matchedTool.action({
374+
templateName,
375+
distFolder,
376+
addAgentsMdSearchDirs: (dir: string) =>
377+
agentsMdSearchDirs.push(dir),
378+
});
372379
}
373380
if (matchedTool.command) {
374381
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)