From 145af43446b4214ab8dc0afdc1c62b77f5a51c40 Mon Sep 17 00:00:00 2001 From: Madushan Nishantha Date: Fri, 21 Oct 2016 14:31:54 +0530 Subject: [PATCH 1/4] now generate docs for all components --- src/server/babel_config.js | 6 ++++++ src/server/config/docgen.js | 3 +++ src/server/config/webpack.config.js | 1 + src/server/config/webpack.config.prod.js | 1 + 4 files changed, 11 insertions(+) create mode 100644 src/server/config/docgen.js diff --git a/src/server/babel_config.js b/src/server/babel_config.js index 2b5f1dbb43f9..b7b1e5228508 100644 --- a/src/server/babel_config.js +++ b/src/server/babel_config.js @@ -65,6 +65,12 @@ export default function (configDir) { path.resolve(babelConfig.extends); } } + const config = babelConfig || defaultConfig; + config.plugins = config.plugins || []; + config.plugins.push([ + require.resolve('babel-plugin-react-docgen'), + { DOC_GEN_GLOBAL: 'STORYBOOK_REACT_CLASSES' }, + ]); return babelConfig || defaultConfig; } diff --git a/src/server/config/docgen.js b/src/server/config/docgen.js new file mode 100644 index 000000000000..ee4d9597bf2a --- /dev/null +++ b/src/server/config/docgen.js @@ -0,0 +1,3 @@ +/* globals window */ + +window.STORYBOOK_REACT_CLASSES = {}; diff --git a/src/server/config/webpack.config.js b/src/server/config/webpack.config.js index 9e61e13ed043..9ed9e88a765f 100644 --- a/src/server/config/webpack.config.js +++ b/src/server/config/webpack.config.js @@ -23,6 +23,7 @@ export default function () { preview: [ require.resolve('./polyfills'), require.resolve('./error_enhancements'), + require.resolve('./docgen'), `${require.resolve('webpack-hot-middleware/client')}?reload=true`, ], }, diff --git a/src/server/config/webpack.config.prod.js b/src/server/config/webpack.config.prod.js index 180c4d229f78..6ed2eac3bf73 100644 --- a/src/server/config/webpack.config.prod.js +++ b/src/server/config/webpack.config.prod.js @@ -13,6 +13,7 @@ export default function () { const entries = { preview: [ require.resolve('./polyfills'), + require.resolve('./docgen'), ], manager: [ require.resolve('./polyfills'), From 45c604533b69d5ea5a8879af1b9397224306b262 Mon Sep 17 00:00:00 2001 From: Madushan Nishantha Date: Fri, 21 Oct 2016 14:44:05 +0530 Subject: [PATCH 2/4] babel-plugin-react-docgen version bump --- package.json | 1 + src/server/babel_config.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 1aadb4d58aa7..c4bc879b5f39 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "autoprefixer": "^6.3.7", "babel-core": "^6.11.4", "babel-loader": "^6.2.4", + "babel-plugin-react-docgen": "^1.3.0", "babel-preset-react-app": "^0.2.1", "babel-runtime": "^6.9.2", "case-sensitive-paths-webpack-plugin": "^1.1.2", diff --git a/src/server/babel_config.js b/src/server/babel_config.js index b7b1e5228508..14aa72d6fd39 100644 --- a/src/server/babel_config.js +++ b/src/server/babel_config.js @@ -69,7 +69,7 @@ export default function (configDir) { config.plugins = config.plugins || []; config.plugins.push([ require.resolve('babel-plugin-react-docgen'), - { DOC_GEN_GLOBAL: 'STORYBOOK_REACT_CLASSES' }, + { DOC_GEN_COLLECTION_NAME: 'STORYBOOK_REACT_CLASSES' }, ]); return babelConfig || defaultConfig; From 3f9c6e2178269ebe0d9fc56696c68e82d176ea32 Mon Sep 17 00:00:00 2001 From: Madushan Nishantha Date: Fri, 21 Oct 2016 16:01:43 +0530 Subject: [PATCH 3/4] renamed docgen -> globals --- src/server/config/{docgen.js => globals.js} | 0 src/server/config/webpack.config.js | 2 +- src/server/config/webpack.config.prod.js | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename src/server/config/{docgen.js => globals.js} (100%) diff --git a/src/server/config/docgen.js b/src/server/config/globals.js similarity index 100% rename from src/server/config/docgen.js rename to src/server/config/globals.js diff --git a/src/server/config/webpack.config.js b/src/server/config/webpack.config.js index 9ed9e88a765f..206938fbcc26 100644 --- a/src/server/config/webpack.config.js +++ b/src/server/config/webpack.config.js @@ -23,7 +23,7 @@ export default function () { preview: [ require.resolve('./polyfills'), require.resolve('./error_enhancements'), - require.resolve('./docgen'), + require.resolve('./globals'), `${require.resolve('webpack-hot-middleware/client')}?reload=true`, ], }, diff --git a/src/server/config/webpack.config.prod.js b/src/server/config/webpack.config.prod.js index 6ed2eac3bf73..dd1db9db51e9 100644 --- a/src/server/config/webpack.config.prod.js +++ b/src/server/config/webpack.config.prod.js @@ -13,7 +13,7 @@ export default function () { const entries = { preview: [ require.resolve('./polyfills'), - require.resolve('./docgen'), + require.resolve('./globals'), ], manager: [ require.resolve('./polyfills'), From 953bf70d1cb9a9e0852b3be7bb6ed93d7506e163 Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Fri, 21 Oct 2016 21:23:36 +0530 Subject: [PATCH 4/4] Refactor the code to be much simpler. --- dist/server/config/webpack.config.js | 2 +- dist/server/config/webpack.config.prod.js | 2 +- dist/server/index.js | 6 +++--- src/server/babel_config.js | 9 +++++---- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/dist/server/config/webpack.config.js b/dist/server/config/webpack.config.js index bef88fa3b564..76384e6eb671 100644 --- a/dist/server/config/webpack.config.js +++ b/dist/server/config/webpack.config.js @@ -9,7 +9,7 @@ exports.default = function () { devtool: '#cheap-module-eval-source-map', entry: { manager: [require.resolve('./polyfills'), require.resolve('../../client/manager')], - preview: [require.resolve('./polyfills'), require.resolve('./error_enhancements'), require.resolve('webpack-hot-middleware/client') + '?reload=true'] + preview: [require.resolve('./polyfills'), require.resolve('./error_enhancements'), require.resolve('./globals'), require.resolve('webpack-hot-middleware/client') + '?reload=true'] }, output: { path: _path2.default.join(__dirname, 'dist'), diff --git a/dist/server/config/webpack.config.prod.js b/dist/server/config/webpack.config.prod.js index e72e3d9457b8..8a86f182c60d 100644 --- a/dist/server/config/webpack.config.prod.js +++ b/dist/server/config/webpack.config.prod.js @@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { exports.default = function () { var entries = { - preview: [require.resolve('./polyfills')], + preview: [require.resolve('./polyfills'), require.resolve('./globals')], manager: [require.resolve('./polyfills'), _path2.default.resolve(__dirname, '../../client/manager')] }; diff --git a/dist/server/index.js b/dist/server/index.js index 7b9e5a6c1a64..2b35c1eaaf8e 100755 --- a/dist/server/index.js +++ b/dist/server/index.js @@ -104,10 +104,10 @@ var configDir = _commander2.default.configDir || './.storybook'; // The repository info is sent to the storybook while running on // development mode so it'll be easier for tools to integrate. var exec = function exec(cmd) { - return _shelljs2.default.exec(cmd).stdout.trim(); + return _shelljs2.default.exec(cmd, { silent: true }).stdout.trim(); }; -process.env.STORYBOOK_GIT_ORIGIN = exec('git remote get-url origin'); -process.env.STORYBOOK_GIT_BRANCH = exec('git symbolic-ref HEAD --short'); +process.env.STORYBOOK_GIT_ORIGIN = process.env.STORYBOOK_GIT_ORIGIN || exec('git remote get-url origin'); +process.env.STORYBOOK_GIT_BRANCH = process.env.STORYBOOK_GIT_BRANCH || exec('git symbolic-ref HEAD --short'); // NOTE changes to env should be done before calling `getBaseConfig` // `getBaseConfig` function which is called inside the middleware diff --git a/src/server/babel_config.js b/src/server/babel_config.js index 14aa72d6fd39..6e3846144091 100644 --- a/src/server/babel_config.js +++ b/src/server/babel_config.js @@ -65,12 +65,13 @@ export default function (configDir) { path.resolve(babelConfig.extends); } } - const config = babelConfig || defaultConfig; - config.plugins = config.plugins || []; - config.plugins.push([ + + const finalConfig = babelConfig || defaultConfig; + finalConfig.plugins = finalConfig.plugins || []; + finalConfig.plugins.push([ require.resolve('babel-plugin-react-docgen'), { DOC_GEN_COLLECTION_NAME: 'STORYBOOK_REACT_CLASSES' }, ]); - return babelConfig || defaultConfig; + return finalConfig; }