Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Implemented internally that order of scenarios can be controlled
Browse files Browse the repository at this point in the history
  • Loading branch information
kurone-kito committed Apr 9, 2019
1 parent 339a439 commit fcdf222
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
7 changes: 0 additions & 7 deletions .storybook/config.js

This file was deleted.

23 changes: 23 additions & 0 deletions .storybook/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { configure } from '@storybook/react';

/**
* Generate a comparison function for string arrays.
* @param prioritizes List of regular expressions for preferred.
*
* If more than one was described, the first one takes precedence.
*/
const createComparer = (...prioritizes: RegExp[]) => (a: string, b: string) => {
const matches = prioritizes.map(reg => ({ a: reg.test(a), b: reg.test(b) }));
const prior = matches.reduce(
(acc, { a: hitA, b: hitB }) => acc || +(hitA !== hitB) * (hitA ? -1 : 1),
0
);
return prior || a.localeCompare(b);
};

// automatically import all files ending in *.stories.js(x), *.stories.ts(x)
configure(() => {
const req = require.context('~/stories', true, /.stories.[jt]sx?$/);
const files = req.keys().sort(createComparer());
files.forEach(filename => req(filename).default());
}, module);

0 comments on commit fcdf222

Please sign in to comment.