From d8aba87f2863dd37391cad2051c309c4b1707598 Mon Sep 17 00:00:00 2001 From: Matt Hinchliffe Date: Wed, 19 Jun 2019 11:49:06 +0100 Subject: [PATCH] Update npm package page creation story file check to include multiple file locations --- web/src/lib/create-npm-package-pages.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/web/src/lib/create-npm-package-pages.js b/web/src/lib/create-npm-package-pages.js index cd331da56..a2bfe926b 100644 --- a/web/src/lib/create-npm-package-pages.js +++ b/web/src/lib/create-npm-package-pages.js @@ -24,6 +24,15 @@ module.exports = async (actions, graphql) => { throw result.errors; } + function hasStorybookConfig(relPath) { + const locations = ['stories/index.js', 'storybook/index.js', 'storybook/index.jsx']; + + return locations.some((location) => { + const filePath = path.join(relPath, location); + return fs.existsSync(filePath); + }); + } + result.data.npmPackages.edges.map(({ node }) => { // Package manifest slug will be /package so remove it const pagePath = path.dirname(node.fields.slug); @@ -41,7 +50,7 @@ module.exports = async (actions, graphql) => { packageName: node.manifest.name, packageDescription: node.manifest.description, // Flag if Storybook demos are available for this package - storybook: fs.existsSync(path.join(relPath, 'stories', 'index.js')), + storybook: hasStorybookConfig(relPath), // Associate readme and story nodes via slug packagePath: path.join(pagePath, 'package'), readmePath: path.join(pagePath, 'readme')