Skip to content

Commit 59c861f

Browse files
committed
feat(cli): add support for comma-separated tools option
1 parent b7afed8 commit 59c861f

6 files changed

Lines changed: 62 additions & 8 deletions

File tree

src/index.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,19 @@ function isEmptyDir(path: string) {
7474
return files.length === 0 || (files.length === 1 && files[0] === '.git');
7575
}
7676

77+
function parseToolsOption(tools: Argv['tools']) {
78+
if (typeof tools === 'undefined') {
79+
return null;
80+
}
81+
82+
const toolsArr = Array.isArray(tools) ? tools : [tools];
83+
84+
return toolsArr
85+
.flatMap((tool) => tool.split(','))
86+
.map((tool) => tool.trim())
87+
.filter(Boolean);
88+
}
89+
7790
export type Argv = {
7891
help?: boolean;
7992
dir?: string;
@@ -110,9 +123,10 @@ async function getTools(
110123
extraTools?: ExtraTool[],
111124
) {
112125
// Check if tools are specified via CLI options
113-
if (tools) {
114-
let toolsArr = Array.isArray(tools) ? tools : [tools];
115-
toolsArr = toolsArr.filter(
126+
const parsedTools = parseToolsOption(tools);
127+
128+
if (parsedTools !== null) {
129+
const toolsArr = parsedTools.filter(
116130
(tool) =>
117131
BUILTIN_TOOLS.includes(tool) ||
118132
extraTools?.some((extraTool) => extraTool.value === tool),
@@ -123,10 +137,6 @@ async function getTools(
123137
if (dir && template) {
124138
return [];
125139
}
126-
// skip tools selection when tools is empty string
127-
if (tools === '') {
128-
return [];
129-
}
130140

131141
const options = [
132142
{ value: 'biome', label: 'Add Biome for code linting and formatting' },

test/cli.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import { fileURLToPath } from 'node:url';
4+
import { expect, test } from '@rstest/core';
5+
import { create } from '../src';
6+
7+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
8+
const fixturesDir = path.join(__dirname, 'fixtures', 'agents-md');
9+
const testDir = path.join(fixturesDir, 'test-temp-output');
10+
11+
test('should accept comma separated tools option', async () => {
12+
const projectDir = path.join(testDir, 'comma-separated-tools');
13+
14+
await create({
15+
name: 'test',
16+
root: fixturesDir,
17+
templates: ['vanilla'],
18+
getTemplateName: async () => 'vanilla',
19+
argv: [
20+
'node',
21+
'test',
22+
'--dir',
23+
projectDir,
24+
'--template',
25+
'vanilla',
26+
'--tools',
27+
'eslint,prettier',
28+
],
29+
});
30+
31+
expect(fs.existsSync(path.join(projectDir, 'eslint.config.mjs'))).toBe(true);
32+
expect(fs.existsSync(path.join(projectDir, '.prettierrc'))).toBe(true);
33+
});

test/fixtures/cli/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "test-fixtures-basic",
3+
"version": "1.0.0"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "test-common",
3+
"version": "1.0.0"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "test-vanilla",
3+
"version": "1.0.0"
4+
}

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"compilerOptions": {
33
"outDir": "./dist",
4-
"baseUrl": "./",
54
"target": "ES2020",
65
"lib": ["DOM", "ESNext"],
76
"module": "Node16",

0 commit comments

Comments
 (0)