Skip to content

Commit

Permalink
Merge pull request #30056 from storybookjs/yann/add-task-suggestions
Browse files Browse the repository at this point in the history
Build: Add text suggestions for incorrect task names
  • Loading branch information
valentinpalkovic authored Dec 15, 2024
2 parents 4192dde + dc5ba88 commit b6a1547
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions scripts/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { testRunnerBuild } from './tasks/test-runner-build';
import { testRunnerDev } from './tasks/test-runner-dev';
import { vitestTests } from './tasks/vitest-test';
import { CODE_DIRECTORY, JUNIT_DIRECTORY, SANDBOX_DIRECTORY } from './utils/constants';
import { findMostMatchText } from './utils/diff';
import type { OptionValues } from './utils/options';
import { createOptions, getCommand, getOptionsOrPrompt } from './utils/options';

Expand Down Expand Up @@ -351,6 +352,19 @@ async function run() {
const { junit, startFrom, ...optionValues } = allOptionValues;
const taskKey = optionValues.task;

if (!(taskKey in tasks)) {
const matchText = findMostMatchText(Object.keys(tasks), taskKey);

if (matchText) {
console.log(
`${picocolors.red('Error')}: ${picocolors.cyan(
taskKey
)} is not a valid task name, Did you mean ${picocolors.cyan(matchText)}?`
);
}
process.exit(1);
}

const finalTask = tasks[taskKey];
const { template: templateKey } = optionValues;
const template = TEMPLATES[templateKey];
Expand Down

0 comments on commit b6a1547

Please sign in to comment.