Skip to content

Commit

Permalink
Update dist
Browse files Browse the repository at this point in the history
  • Loading branch information
thani-sh committed Sep 21, 2016
1 parent 53df979 commit 9bba63f
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 113 deletions.
3 changes: 2 additions & 1 deletion dist/client/manager/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var _preview2 = _interopRequireDefault(_preview);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/* global location */
/* eslint class-methods-use-this: 0 */

var ReactProvider = function (_Provider) {
(0, _inherits3.default)(ReactProvider, _Provider);
Expand All @@ -70,7 +71,7 @@ var ReactProvider = function (_Provider) {
_this.channel = (0, _storybookChannelPagebus2.default)({ key: _this.dataId });
_storybookAddons2.default.setChannel(_this.channel);
_this.database = _storybookAddons2.default.getDatabase();
if (!_this.database) {
if (!_this.database && process.env.STORYBOOK_ENABLE_DB) {
var bundled = process.env.NODE_ENV === 'production';
if (bundled) {
_this.database = (0, _storybookDatabaseLocal2.default)({ url: 'addon-db.json', bundled: bundled });
Expand Down
9 changes: 7 additions & 2 deletions dist/client/preview/story_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de

var cnt = 0;

function getId() {
cnt += 1;
return cnt;
}

var StoryStore = function () {
function StoryStore() {
(0, _classCallCheck3.default)(this, StoryStore);
Expand All @@ -33,14 +38,14 @@ var StoryStore = function () {
if (!this._data[kind]) {
this._data[kind] = {
kind: kind,
index: cnt++,
index: getId(),
stories: {}
};
}

this._data[kind].stories[name] = {
name: name,
index: cnt++,
index: getId(),
fn: fn
};
}
Expand Down
39 changes: 21 additions & 18 deletions dist/server/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,32 @@ _commander2.default.version(_package2.default.version).option('-s, --static-dir
configDir: 'STORYBOOK_CONFIG_DIR'
});

// Build the webpack configuration using the `baseConfig`
// custom `.babelrc` file and `webpack.config.js` files
var configDir = _commander2.default.configDir || './.storybook';
var config = (0, _config2.default)('PRODUCTION', _webpackConfig2.default, configDir);

var publicPath = config.output.publicPath;

var outputDir = _commander2.default.outputDir || './storybook-static';
config.output.path = outputDir;

// create output directory (and the static dir) if not exists
_shelljs2.default.rm('-rf', outputDir);
_shelljs2.default.mkdir('-p', _path2.default.resolve(outputDir));
_shelljs2.default.cp(_path2.default.resolve(__dirname, 'public/favicon.ico'), outputDir);

// The addon database service is disabled by default for now
// It should be enabled with the --enable-db for dev server
if (_commander2.default.enableDb) {
// NOTE enables database on client
process.env.STORYBOOK_ENABLE_DB = 1;
var dbPath = _commander2.default.dbPath || _path2.default.resolve(configDir, 'addon-db.json');
// create addon-db.json file if it's missing to avoid the 404 error
if (!_fs2.default.existsSync(dbPath)) {
_fs2.default.writeFileSync(dbPath, '{}');
}
_shelljs2.default.cp(dbPath, outputDir);
}

// Build the webpack configuration using the `baseConfig`
// custom `.babelrc` file and `webpack.config.js` files
// NOTE changes to env should be done before calling `getBaseConfig`
var config = (0, _config2.default)('PRODUCTION', (0, _webpackConfig2.default)(), configDir);
config.output.path = outputDir;

// copy all static files
if (_commander2.default.staticDir) {
Expand All @@ -86,19 +99,9 @@ if (_commander2.default.staticDir) {
});
}

// The addon database service is disabled by default for now
// It should be enabled with the --enable-db for dev server
if (_commander2.default.enableDb) {
var dbPath = _commander2.default.dbPath || _path2.default.resolve(configDir, 'addon-db.json');
// create addon-db.json file if it's missing to avoid the 404 error
if (!_fs2.default.existsSync(dbPath)) {
_fs2.default.writeFileSync(dbPath, '{}');
}
_shelljs2.default.cp(dbPath, outputDir);
}

// Write both the storybook UI and IFRAME HTML files to destination path.
var headHtml = (0, _utils.getHeadHtml)(configDir);
var publicPath = config.output.publicPath;
_fs2.default.writeFileSync(_path2.default.resolve(outputDir, 'index.html'), (0, _index2.default)(publicPath));
_fs2.default.writeFileSync(_path2.default.resolve(outputDir, 'iframe.html'), (0, _iframe2.default)(headHtml, publicPath));

Expand Down
66 changes: 34 additions & 32 deletions dist/server/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,39 @@ Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function () {
var config = {
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']
},
output: {
path: _path2.default.join(__dirname, 'dist'),
filename: 'static/[name].bundle.js',
publicPath: '/'
},
plugins: [new _webpack2.default.DefinePlugin((0, _utils.loadEnv)()), new _utils.OccurenceOrderPlugin(), new _webpack2.default.HotModuleReplacementPlugin(), new _caseSensitivePathsWebpackPlugin2.default(), new _WatchMissingNodeModulesPlugin2.default(_utils.nodeModulesPaths)],
module: {
loaders: [{
test: /\.jsx?$/,
loader: require.resolve('babel-loader'),
query: _babel2.default,
include: _utils.includePaths,
exclude: _utils.excludePaths
}]
},
resolve: {
alias: {
// This is to add addon support for NPM2
'@kadira/storybook-addons': require.resolve('@kadira/storybook-addons')
}
}
};

return config;
};

var _path = require('path');

var _path2 = _interopRequireDefault(_path);
Expand All @@ -26,35 +59,4 @@ var _babel = require('./babel.js');

var _babel2 = _interopRequireDefault(_babel);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var config = {
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']
},
output: {
path: _path2.default.join(__dirname, 'dist'),
filename: 'static/[name].bundle.js',
publicPath: '/'
},
plugins: [new _webpack2.default.DefinePlugin((0, _utils.loadEnv)()), new _utils.OccurenceOrderPlugin(), new _webpack2.default.HotModuleReplacementPlugin(), new _caseSensitivePathsWebpackPlugin2.default(), new _WatchMissingNodeModulesPlugin2.default(_utils.nodeModulesPaths)],
module: {
loaders: [{
test: /\.jsx?$/,
loader: require.resolve('babel-loader'),
query: _babel2.default,
include: _utils.includePaths,
exclude: _utils.excludePaths
}]
},
resolve: {
alias: {
// This is to add addon support for NPM2
'@kadira/storybook-addons': require.resolve('@kadira/storybook-addons')
}
}
};

exports.default = config;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
116 changes: 59 additions & 57 deletions dist/server/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,64 @@ Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function () {
var entries = {
preview: [require.resolve('./polyfills')],
manager: [require.resolve('./polyfills'), _path2.default.resolve(__dirname, '../../client/manager')]
};

var config = {
bail: true,
devtool: '#cheap-module-source-map',
entry: entries,
output: {
filename: 'static/[name].bundle.js',
// Here we set the publicPath to ''.
// This allows us to deploy storybook into subpaths like GitHub pages.
// This works with css and image loaders too.
// This is working for storybook since, we don't use pushState urls and
// relative URLs works always.
publicPath: ''
},
plugins: [new _webpack2.default.DefinePlugin((0, _utils.loadEnv)({ production: true })), new _webpack2.default.optimize.DedupePlugin(), new _webpack2.default.optimize.UglifyJsPlugin({
compress: {
screw_ie8: true,
warnings: false
},
mangle: {
screw_ie8: true
},
output: {
comments: false,
screw_ie8: true
}
})],
module: {
loaders: [{
test: /\.jsx?$/,
loader: require.resolve('babel-loader'),
query: _babelProd2.default,
include: _utils.includePaths,
exclude: _utils.excludePaths
}]
},
resolve: {
alias: {
// This is to add addon support for NPM2
'@kadira/storybook-addons': require.resolve('@kadira/storybook-addons')
}
}
};

// Webpack 2 doesn't have a OccurenceOrderPlugin plugin in the production mode.
// But webpack 1 has it. That's why we do this.
if (_utils.OccurenceOrderPlugin) {
config.plugins.unshift(new _utils.OccurenceOrderPlugin());
}

return config;
};

var _path = require('path');

var _path2 = _interopRequireDefault(_path);
Expand All @@ -18,60 +76,4 @@ var _babelProd = require('./babel.prod.js');

var _babelProd2 = _interopRequireDefault(_babelProd);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var entries = {
preview: [require.resolve('./polyfills')],
manager: [require.resolve('./polyfills'), _path2.default.resolve(__dirname, '../../client/manager')]
};

var config = {
bail: true,
devtool: '#cheap-module-source-map',
entry: entries,
output: {
filename: 'static/[name].bundle.js',
// Here we set the publicPath to ''.
// This allows us to deploy storybook into subpaths like GitHub pages.
// This works with css and image loaders too.
// This is working for storybook since, we don't use pushState urls and
// relative URLs works always.
publicPath: ''
},
plugins: [new _webpack2.default.DefinePlugin((0, _utils.loadEnv)({ production: true })), new _webpack2.default.optimize.DedupePlugin(), new _webpack2.default.optimize.UglifyJsPlugin({
compress: {
screw_ie8: true,
warnings: false
},
mangle: {
screw_ie8: true
},
output: {
comments: false,
screw_ie8: true
}
})],
module: {
loaders: [{
test: /\.jsx?$/,
loader: require.resolve('babel-loader'),
query: _babelProd2.default,
include: _utils.includePaths,
exclude: _utils.excludePaths
}]
},
resolve: {
alias: {
// This is to add addon support for NPM2
'@kadira/storybook-addons': require.resolve('@kadira/storybook-addons')
}
}
};

// Webpack 2 doesn't have a OccurenceOrderPlugin plugin in the production mode.
// But webpack 1 has it. That's why we do this.
if (_utils.OccurenceOrderPlugin) {
config.plugins.unshift(new _utils.OccurenceOrderPlugin());
}

exports.default = config;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12 changes: 11 additions & 1 deletion dist/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ var _express = require('express');

var _express2 = _interopRequireDefault(_express);

var _serveFavicon = require('serve-favicon');

var _serveFavicon2 = _interopRequireDefault(_serveFavicon);

var _commander = require('commander');

var _commander2 = _interopRequireDefault(_commander);
Expand Down Expand Up @@ -67,6 +71,7 @@ if (_commander2.default.host) {
}

var app = (0, _express2.default)();
app.use((0, _serveFavicon2.default)(_path2.default.resolve(__dirname, 'public/favicon.ico')));

if (_commander2.default.staticDir) {
_commander2.default.staticDir = (0, _utils.parseList)(_commander2.default.staticDir);
Expand All @@ -84,15 +89,20 @@ if (_commander2.default.staticDir) {
// Build the webpack configuration using the `baseConfig`
// custom `.babelrc` file and `webpack.config.js` files
var configDir = _commander2.default.configDir || './.storybook';
app.use((0, _middleware4.default)(configDir));

// The addon database service is disabled by default for now
// It should be enabled with the --enable-db for dev server
if (_commander2.default.enableDb) {
// NOTE enables database on client
process.env.STORYBOOK_ENABLE_DB = 1;
var dbPath = _commander2.default.dbPath || _path2.default.resolve(configDir, 'addon-db.json');
app.use('/db', (0, _middleware2.default)(dbPath));
}

// NOTE changes to env should be done before calling `getBaseConfig`
// `getBaseConfig` function which is called inside the middleware
app.use((0, _middleware4.default)(configDir));

app.listen.apply(app, listenAddr.concat([function (error) {
if (error) {
throw error;
Expand Down
4 changes: 2 additions & 2 deletions dist/server/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
});

exports.default = function (configDir) {
// Build the webpack configuration using the `baseConfig`
// Build the webpack configuration using the `getBaseConfig`
// custom `.babelrc` file and `webpack.config.js` files
var config = (0, _config2.default)('DEVELOPMENT', _webpack4.default, configDir);
var config = (0, _config2.default)('DEVELOPMENT', (0, _webpack4.default)(), configDir);

// remove the leading '/'
var publicPath = config.output.publicPath;
Expand Down

0 comments on commit 9bba63f

Please sign in to comment.