From b81fb63566deb84ad6c11737af14e2537d65bb4c Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Tue, 21 Jan 2020 00:51:26 +0100 Subject: [PATCH 1/2] IMPROVE the build-storybooks script --- scripts/build-storybooks.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/build-storybooks.js b/scripts/build-storybooks.js index a2fe741672a6..fd0376e6b53d 100755 --- a/scripts/build-storybooks.js +++ b/scripts/build-storybooks.js @@ -119,9 +119,14 @@ const createContent = deployables => { const handleExamples = async files => { const deployables = files.filter(f => { const packageJsonLocation = p(['examples', f, 'package.json']); - const stats = statSync(packageJsonLocation); - - return stats.isFile() && hasBuildScript(packageJsonLocation); + let stats = null; + try { + stats = statSync(packageJsonLocation); + } catch (e) { + // + } + + return stats && stats.isFile() && hasBuildScript(packageJsonLocation); }); await deployables.reduce(async (acc, d) => { @@ -175,4 +180,7 @@ const run = async () => { await handleExamples(list); }; -run(); +run().catch(e => { + logger.error(e); + process.exit(1); +}); From 31ddf96f767abe669ee0ee2b4b18432e1ef30293 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Tue, 21 Jan 2020 10:04:43 +0100 Subject: [PATCH 2/2] Make build-ScriptDetection sync --- scripts/build-storybooks.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/build-storybooks.js b/scripts/build-storybooks.js index fd0376e6b53d..c266587d9e64 100755 --- a/scripts/build-storybooks.js +++ b/scripts/build-storybooks.js @@ -7,11 +7,11 @@ const { readFile: readFileRaw, writeFile: writeFileRaw, statSync, + readFileSync, } = require('fs'); const { join } = require('path'); const readdir = promisify(readdirRaw); -const readFile = promisify(readFileRaw); const writeFile = promisify(writeFileRaw); const p = l => join(__dirname, '..', ...l); @@ -35,8 +35,8 @@ const exec = async (command, args = [], options = {}) => }); }); -const hasBuildScript = async l => { - const text = await readFile(l, 'utf8'); +const hasBuildScript = l => { + const text = readFileSync(l, 'utf8'); const json = JSON.parse(text); return !!json.scripts['build-storybook']; @@ -123,7 +123,7 @@ const handleExamples = async files => { try { stats = statSync(packageJsonLocation); } catch (e) { - // + // the folder had no package.json, we'll ignore } return stats && stats.isFile() && hasBuildScript(packageJsonLocation);