Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMPROVE the build-storybooks script #9569

Merged
merged 2 commits into from
Jan 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions scripts/build-storybooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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'];
Expand Down Expand Up @@ -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) {
// the folder had no package.json, we'll ignore
}

return stats && stats.isFile() && hasBuildScript(packageJsonLocation);
});

await deployables.reduce(async (acc, d) => {
Expand Down Expand Up @@ -175,4 +180,7 @@ const run = async () => {
await handleExamples(list);
};

run();
run().catch(e => {
logger.error(e);
process.exit(1);
});