Skip to content

Commit

Permalink
chore: add build step to generate react docgen metadata (#4662)
Browse files Browse the repository at this point in the history
* chore: add build step to generate react docgen metadata

* fix: ci check
  • Loading branch information
vpicone authored and emyarod committed Nov 15, 2019
1 parent 3994637 commit 662c3a8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
"/dist/",
"/es/",
"/lib/",
"/build/",
"e2e",
"examples",
"/umd/"
Expand Down
3 changes: 3 additions & 0 deletions packages/react/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Storybook
storybook-static

# Generated metadata
react-docgen.json
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"scripts": {
"build": "yarn clean && node scripts/build.js",
"build-storybook": "build-storybook",
"clean": "rimraf es lib umd storybook-static",
"clean": "rimraf es lib umd storybook-static build react-docgen.json",
"prepublish": "yarn build",
"start": "yarn storybook",
"storybook": "rimraf node_modules/.cache/storybook && start-storybook -p 9000"
Expand Down
12 changes: 12 additions & 0 deletions packages/react/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const { execSync } = require('child_process');
const { inInstall } = require('in-publish');
const path = require('path');
const fs = require('fs');
const mapValues = require('lodash/mapValues');

if (inInstall()) {
process.exit(0);
Expand Down Expand Up @@ -32,6 +34,16 @@ try {
exec(`${babelPath} src -q -d lib --ignore "${ignoreGlobs}"`, {
BABEL_ENV: 'cjs',
});

// Create docgen metadata
exec(`${babelPath} src -q -d build/docgen --ignore "${ignoreGlobs}"`, {
BABEL_ENV: 'docgen',
});
fs.writeFileSync(
'react-docgen.json',
JSON.stringify(mapValues(require(`../build/docgen`), '__docgenInfo'))
);

exec(
`${rollupPath} -c scripts/rollup.config.js -o umd/carbon-components-react.js`,
{
Expand Down
12 changes: 12 additions & 0 deletions packages/react/scripts/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

const BABEL_ENV = process.env.BABEL_ENV;

const docgenConfig = {
plugins: [
[
'babel-plugin-react-docgen',
{
removeMethods: true,
},
],
],
};

module.exports = () => ({
presets: [
[
Expand All @@ -14,4 +25,5 @@ module.exports = () => ({
},
],
],
...(BABEL_ENV === 'docgen' && docgenConfig),
});

0 comments on commit 662c3a8

Please sign in to comment.