diff --git a/README.md b/README.md index cd40c7641..b54eda1f0 100644 --- a/README.md +++ b/README.md @@ -357,6 +357,8 @@ Options: -f, --flat Flatten output filename. [boolean] [default: false] -i, --include Including stories name rule. [array] [default: []] -e, --exclude Excluding stories name rule. [array] [default: []] + --matchNocase 'include' and 'exclude' comparisons to be non case sensitive. + [boolean] [default: false] --delay Waiting time [msec] before screenshot for each story. [number] [default: 0] -V, --viewport Viewport. [array] [default: ["800x600"]] --disableCssAnimation Disable CSS animation and transition. [boolean] [default: true] diff --git a/packages/storycap/src/node/cli.ts b/packages/storycap/src/node/cli.ts index 75d65533a..54de52938 100644 --- a/packages/storycap/src/node/cli.ts +++ b/packages/storycap/src/node/cli.ts @@ -22,6 +22,11 @@ function createOptions(): MainOptions { .option('flat', { boolean: true, alias: 'f', default: false, description: 'Flatten output filename.' }) .option('include', { array: true, alias: 'i', default: [], description: 'Including stories name rule.' }) .option('exclude', { array: true, alias: 'e', default: [], description: 'Excluding stories name rule.' }) + .option('matchNocase', { + boolean: true, + default: false, + description: "'include' and 'exclude' comparisons to be non case sensitive.", + }) .option('delay', { number: true, default: 0, description: 'Waiting time [msec] before screenshot for each story.' }) .option('viewport', { array: true, alias: 'V', default: ['800x600'], description: 'Viewport.' }) .option('disableCssAnimation', { @@ -115,6 +120,7 @@ function createOptions(): MainOptions { flat, include, exclude, + matchNocase, delay, viewport, parallel, @@ -175,6 +181,7 @@ function createOptions(): MainOptions { flat, include, exclude, + matchNocase, delay, viewports: viewport, parallel, diff --git a/packages/storycap/src/node/main.ts b/packages/storycap/src/node/main.ts index ae6e748fb..60da42031 100644 --- a/packages/storycap/src/node/main.ts +++ b/packages/storycap/src/node/main.ts @@ -1,4 +1,4 @@ -import { isMatch } from 'nanomatch'; +import { isMatch, MatchOptions } from 'nanomatch'; import { StorybookConnection, StoriesBrowser, Story, sleep, ChromiumNotFoundError } from 'storycrawler'; import { CapturingBrowser } from './capturing-browser'; import { MainOptions, RunMode } from './types'; @@ -28,10 +28,19 @@ async function bootCapturingBrowserAsWorkers(connection: StorybookConnection, op return { workers: browsers, closeWorkers: () => Promise.all(browsers.map(b => b.close.bind(b))) }; } -function filterStories(flatStories: Story[], include: string[], exclude: string[]): Story[] { +function filterStories( + flatStories: Story[], + include: string[], + exclude: string[], + matchOptions: MatchOptions, +): Story[] { const conbined = flatStories.map(s => ({ ...s, name: s.kind + '/' + s.story })); - const included = include.length ? conbined.filter(s => include.some(rule => isMatch(s.name, rule))) : conbined; - const excluded = exclude.length ? included.filter(s => !exclude.some(rule => isMatch(s.name, rule))) : included; + const included = include.length + ? conbined.filter(s => include.some(rule => isMatch(s.name, rule, matchOptions))) + : conbined; + const excluded = exclude.length + ? included.filter(s => !exclude.some(rule => isMatch(s.name, rule, matchOptions))) + : included; return excluded; } @@ -60,7 +69,9 @@ export async function main(mainOptions: MainOptions) { const mode = await detectRunMode(storiesBrowser, mainOptions); storiesBrowser.close(); - const stories = filterStories(allStories, mainOptions.include, mainOptions.exclude); + const stories = filterStories(allStories, mainOptions.include, mainOptions.exclude, { + nocase: mainOptions.matchNocase, + }); if (stories.length === 0) { logger.warn('There is no matched story. Check your include/exclude options.'); diff --git a/packages/storycap/src/node/types.ts b/packages/storycap/src/node/types.ts index d712c907c..7464b27e2 100644 --- a/packages/storycap/src/node/types.ts +++ b/packages/storycap/src/node/types.ts @@ -38,6 +38,7 @@ export interface MainOptions extends BaseBrowserOptions { flat: boolean; include: string[]; exclude: string[]; + matchNocase: boolean; disableCssAnimation: boolean; disableWaitAssets: boolean; trace: boolean;