From eaab26e6e4dcee2ae95fa3682e120a4a0deb803b Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Mon, 11 Nov 2019 11:11:38 +0100 Subject: [PATCH] FIX review comments, CHANGE to only support a single preview.* --- .../src/frameworks/configure.ts | 51 ++++++++++++++----- .../src/frameworks/vue/loader.ts | 3 +- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/addons/storyshots/storyshots-core/src/frameworks/configure.ts b/addons/storyshots/storyshots-core/src/frameworks/configure.ts index f6085ffe475..242f3b3056f 100644 --- a/addons/storyshots/storyshots-core/src/frameworks/configure.ts +++ b/addons/storyshots/storyshots-core/src/frameworks/configure.ts @@ -84,32 +84,57 @@ const loadStories = (loadable: string, framework: string, clientApi: ClientApi) }); }; +const getPreviewFile = (configDir: string): string | false => { + const preview = path.join(configDir, 'preview.js'); + const previewTS = path.join(configDir, 'preview.ts'); + const config = path.join(configDir, 'config.js'); + const configTS = path.join(configDir, 'config.ts'); + + if (isFile(previewTS)) { + return configTS; + } + if (isFile(preview)) { + return config; + } + if (isFile(configTS)) { + return configTS; + } + if (isFile(config)) { + return config; + } + + return false; +}; + +const getMainFile = (configDir: string): string | false => { + const main = path.join(configDir, 'main.js'); + + if (isFile(main)) { + return main; + } + + return false; +}; + function getConfigPathParts(input: string): Output { const configDir = path.resolve(input); if (fs.lstatSync(configDir).isDirectory()) { const output: Output = { files: [], stories: [] }; - const main = path.join(configDir, 'main.js'); - const preview = path.join(configDir, 'preview.js'); - const config = path.join(configDir, 'config.js'); - const configTS = path.join(configDir, 'config.ts'); - if (isFile(preview)) { + const preview = getPreviewFile(configDir); + const main = getMainFile(configDir); + + if (preview) { output.files.push(preview); } - if (isFile(main)) { + if (main) { const { stories = [] } = require.requireActual(main); const result = stories.reduce((acc: string[], i: string) => [...acc, ...glob.sync(i)], []); output.stories = result; } - if (isFile(config)) { - output.files.push(config); - } - if (isFile(configTS)) { - output.files.push(configTS); - } return output; } @@ -119,7 +144,7 @@ function getConfigPathParts(input: string): Output { function configure( options: { - storybook: any; + storybook: ClientApi; } & StoryshotsOptions ): void { const { configPath = '.storybook', config, storybook, framework } = options; diff --git a/addons/storyshots/storyshots-core/src/frameworks/vue/loader.ts b/addons/storyshots/storyshots-core/src/frameworks/vue/loader.ts index fa446b732de..2433026458a 100644 --- a/addons/storyshots/storyshots-core/src/frameworks/vue/loader.ts +++ b/addons/storyshots/storyshots-core/src/frameworks/vue/loader.ts @@ -16,10 +16,9 @@ function load(options: StoryshotsOptions) { global.STORYBOOK_ENV = 'vue'; mockVueToIncludeCompiler(); - const { configPath, config } = options; const storybook = require.requireActual('@storybook/vue'); - configure({ configPath, ...config, storybook }); + configure({ ...options, storybook }); return { framework: 'vue' as const,