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

[core] Don't bail out early if docs:api fails #21726

Merged
merged 2 commits into from
Jul 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
73 changes: 34 additions & 39 deletions docs/scripts/buildApi.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
import * as babel from '@babel/core';
import traverse from '@babel/traverse';
import { mkdir, readFileSync, writeFileSync } from 'fs';
import { mkdirSync, readFileSync, writeFileSync } from 'fs';
import { getLineFeed } from './helpers';
import { rewriteUrlForNextExport } from 'next/dist/next-server/lib/router/rewrite-url-for-export';
import path from 'path';
Expand All @@ -23,20 +23,6 @@ import createGenerateClassName from '../../packages/material-ui-styles/src/creat

const generateClassName = createGenerateClassName();

function ensureExists(pat, mask, cb) {
mkdir(pat, mask, (err) => {
if (err) {
if (err.code === 'EEXIST') {
cb(null); // ignore the error if the folder already exists
} else {
cb(err); // something else went wrong
}
} else {
cb(null); // successfully created folder
}
});
}

const inheritedComponentRegexp = /\/\/ @inheritedComponent (.*)/;

/**
Expand Down Expand Up @@ -308,19 +294,13 @@ async function buildDocs(options) {
throw err;
}

ensureExists(outputDirectory, 0o744, (err) => {
if (err) {
console.log('Error creating directory', outputDirectory);
return;
}

writeFileSync(
path.resolve(outputDirectory, `${kebabCase(reactAPI.name)}.md`),
markdown.replace(/\r?\n/g, reactAPI.EOL),
);
writeFileSync(
path.resolve(outputDirectory, `${kebabCase(reactAPI.name)}.js`),
`import React from 'react';
writeFileSync(
path.resolve(outputDirectory, `${kebabCase(reactAPI.name)}.md`),
markdown.replace(/\r?\n/g, reactAPI.EOL),
);
writeFileSync(
path.resolve(outputDirectory, `${kebabCase(reactAPI.name)}.js`),
`import React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
import { prepareMarkdown } from 'docs/src/modules/utils/parseMarkdown';

Expand All @@ -336,10 +316,9 @@ Page.getInitialProps = () => {
return { demos, docs };
};
`.replace(/\r?\n/g, reactAPI.EOL),
);
);

console.log('Built markdown docs for', reactAPI.name);
});
console.log('Built markdown docs for', reactAPI.name);

await annotateComponentDefinition(componentObject, reactAPI);
}
Expand All @@ -352,6 +331,8 @@ function run(argv) {
const outputDirectory = path.resolve(argv.outputDirectory);
const grep = argv.grep == null ? null : new RegExp(argv.grep);

mkdirSync(outputDirectory, { mode: 0o777, recursive: true });

const theme = createMuiTheme();

const pagesMarkdown = findPagesMarkdown()
Expand All @@ -374,14 +355,28 @@ function run(argv) {
return grep.test(component.filename);
});

components.forEach((component) => {
buildDocs({ component, outputDirectory, pagesMarkdown, theme, workspaceRoot }).catch(
(error) => {
console.warn(`error building docs for ${component.filename}`);
console.error(error);
process.exit(1);
},
);
const componentBuilds = components.map((component) => {
// use Promise.allSettled once we switch to node 12
return buildDocs({ component, outputDirectory, pagesMarkdown, theme, workspaceRoot })
.then((value) => {
return { status: 'fulfilled', value };
})
.catch((error) => {
error.message = `with component ${component.filename}: ${error.message}`;

return { status: 'rejected', reason: error };
});
});

Promise.all(componentBuilds).then((builds) => {
const fails = builds.filter(({ status }) => status === 'rejected');

fails.forEach((build) => {
console.error(build.reason);
});
if (fails.length > 0) {
process.exit(1);
}
});
}

Expand Down