Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,16 @@ export type Argv = {

export const BUILTIN_TOOLS = ['eslint', 'prettier', 'biome'];

function logHelpMessage(name: string, templates: string[]) {
function logHelpMessage(
name: string,
templates: string[],
extraTools?: ExtraTool[],
) {
const extraToolNames = extraTools?.map((tool) => tool.value) ?? [];
const toolsList = ['biome', 'eslint', 'prettier', ...extraToolNames].join(
Comment thread
chenjiahan marked this conversation as resolved.
Outdated
', ',
);

logger.log(`
Usage: create-${name} [dir] [options]

Expand All @@ -108,7 +117,7 @@ function logHelpMessage(name: string, templates: string[]) {
-h, --help display help for command
-d, --dir <dir> create project in specified directory
-t, --template <tpl> specify the template to use
--tools <tool> select additional tools (biome, eslint, prettier)
--tools <tool> select additional tools (${toolsList})
--override override files in target directory
--packageName <name> specify the package name

Expand Down Expand Up @@ -270,7 +279,7 @@ export async function create({
const argv = parseArgv(processArgv);

if (argv.help) {
logHelpMessage(name, templates);
logHelpMessage(name, templates, extraTools);
return;
}

Expand Down
34 changes: 34 additions & 0 deletions test/help.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { expect, test } from '@rstest/core';
import { logger } from 'rslog';
import { create } from '../src';

test('help message includes extra tools', async () => {
const logs: string[] = [];
const originalLog = logger.log;

logger.override({
log: (message?: unknown) => {
logs.push(String(message ?? ''));
},
});

try {
await create({
name: 'test',
root: '.',
templates: ['vanilla'],
getTemplateName: async () => 'vanilla',
extraTools: [{ value: 'custom-tool', label: 'Custom Tool' }],
argv: ['node', 'test', '--help'],
});
} finally {
logger.override({
log: originalLog,
});
}

const logOutput = logs.join('\n');
expect(logOutput).toContain(
'--tools <tool> select additional tools (biome, eslint, prettier, custom-tool)',
);
});