diff --git a/packages/cli/src/containers/PreviewContainer/serveStoryApi.spec.ts b/packages/cli/src/containers/PreviewContainer/serveStoryApi.spec.ts index eb636822..88cbae69 100644 --- a/packages/cli/src/containers/PreviewContainer/serveStoryApi.spec.ts +++ b/packages/cli/src/containers/PreviewContainer/serveStoryApi.spec.ts @@ -25,6 +25,17 @@ test('get components API output', () => { }; const storiesMetadata = { + file2: { + fileName: 'file2', + title: 'FILE TWO', + filePath: '/some/path/some/feli.ts', + storyItems: [ + { + exportName: 'story3', + storyName: 'story drei', + }, + ], + }, file1: { fileName: 'file1', title: 'FILE ONE', @@ -40,17 +51,6 @@ test('get components API output', () => { }, ], }, - file2: { - fileName: 'file2', - title: 'FILE TWO', - filePath: '/some/path/some/feli.ts', - storyItems: [ - { - exportName: 'story3', - storyName: 'story drei', - }, - ], - }, }; const result = serveStoriesApi({ diff --git a/packages/cli/src/containers/PreviewContainer/serveStoryApi.ts b/packages/cli/src/containers/PreviewContainer/serveStoryApi.ts index b2c6bdfe..547ac7b3 100644 --- a/packages/cli/src/containers/PreviewContainer/serveStoryApi.ts +++ b/packages/cli/src/containers/PreviewContainer/serveStoryApi.ts @@ -1,3 +1,4 @@ +import { StoryCollectionMetadata } from '../../steps/analyze'; import { SetupApiOptions } from './setupApi'; export function serveStoriesApi({ storiesMetadata, getFiles, getAssets }: SetupApiOptions) { @@ -5,13 +6,27 @@ export function serveStoriesApi({ storiesMetadata, getFiles, getAssets }: SetupA return { files: getFiles().map(({ url, name }) => ({ name, url })), - stories: Object.entries(storiesMetadata).map(([filePath, meta]) => { - return { - files: assets[meta.fileName], - storyItems: meta.storyItems, - filePath, - title: meta.title, - }; - }), + stories: Object.entries(storiesMetadata) + .sort(sortStory) + .map(([filePath, meta]) => { + return { + files: assets[meta.fileName], + storyItems: meta.storyItems, + filePath, + title: meta.title, + }; + }), }; } + +function sortStory(a: [string, StoryCollectionMetadata], b: [string, StoryCollectionMetadata]) { + if (a[1].title < b[1].title) { + return -1; + } + + if (a[1].title > b[1].title) { + return 1; + } + + return 0; +} diff --git a/tsconfig.settings.json b/tsconfig.settings.json index 82b32aef..ac8bd95c 100644 --- a/tsconfig.settings.json +++ b/tsconfig.settings.json @@ -18,6 +18,7 @@ "strictNullChecks": true, "suppressImplicitAnyIndexErrors": true, "noUnusedLocals": true, + "jsx": "react", "lib": ["es6", "es2016", "es2017", "es2018", "es2019", "DOM"] } }