diff --git a/dist/client/manager/provider.js b/dist/client/manager/provider.js index 30f1b0d560ec..19ebc99ce694 100644 --- a/dist/client/manager/provider.js +++ b/dist/client/manager/provider.js @@ -69,7 +69,12 @@ var ReactProvider = function (_Provider) { _storybookAddons2.default.setChannel(_this.channel); _this.database = _storybookAddons2.default.getDatabase(); if (!_this.database) { - _this.database = (0, _storybookDatabaseLocal2.default)({ url: location.origin + '/db' }); + var bundled = process.env.NODE_ENV === 'production'; + if (bundled) { + _this.database = (0, _storybookDatabaseLocal2.default)({ url: 'addon-db.json', bundled: bundled }); + } else { + _this.database = (0, _storybookDatabaseLocal2.default)({ url: location.origin + '/db' }); + } _storybookAddons2.default.setDatabase(_this.database); } return _this; diff --git a/dist/server/build.js b/dist/server/build.js index 318ab0802072..941aa9811930 100644 --- a/dist/server/build.js +++ b/dist/server/build.js @@ -50,7 +50,7 @@ process.env.NODE_ENV = process.env.NODE_ENV || 'production'; // avoid ESLint errors var logger = console; -_commander2.default.version(_package2.default.version).option('-s, --static-dir ', 'Directory where to load static files from', _utils.parseList).option('-o, --output-dir [dir-name]', 'Directory where to store built files').option('-c, --config-dir [dir-name]', 'Directory where to load Storybook configurations from').parse(process.argv); +_commander2.default.version(_package2.default.version).option('-s, --static-dir ', 'Directory where to load static files from', _utils.parseList).option('-o, --output-dir [dir-name]', 'Directory where to store built files').option('-c, --config-dir [dir-name]', 'Directory where to load Storybook configurations from').option('-d, --db-path [db-file]', 'Path to the addon database JSON file').option('--enable-db', 'Enable the (experimental) addon database service on dev-server').parse(process.argv); // The key is the field created in `program` variable for // each command line argument. Value is the env variable. @@ -86,6 +86,13 @@ 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 || './.storybook/addon-db.json'; + _shelljs2.default.cp(dbPath, outputDir); +} + // Write both the storybook UI and IFRAME HTML files to destination path. var headHtml = (0, _utils.getHeadHtml)(configDir); _fs2.default.writeFileSync(_path2.default.resolve(outputDir, 'index.html'), (0, _index2.default)(publicPath)); diff --git a/package.json b/package.json index 9260dddab96a..ebd897e8fbad 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "@kadira/storybook-addon-links": "^1.0.0", "@kadira/storybook-addons": "^1.5.0", "@kadira/storybook-channel-pagebus": "^2.0.2", - "@kadira/storybook-database-local": "^1.1.0", + "@kadira/storybook-database-local": "^1.2.0", "@kadira/storybook-ui": "^3.4.0", "autoprefixer": "^6.3.7", "babel-core": "^6.11.4", diff --git a/src/client/manager/provider.js b/src/client/manager/provider.js index 7c750c7f788a..0b7f5812f5e2 100644 --- a/src/client/manager/provider.js +++ b/src/client/manager/provider.js @@ -15,7 +15,12 @@ export default class ReactProvider extends Provider { addons.setChannel(this.channel); this.database = addons.getDatabase(); if (!this.database) { - this.database = createDatabase({ url: `${location.origin}/db` }); + const bundled = process.env.NODE_ENV === 'production'; + if (bundled) { + this.database = createDatabase({ url: 'addon-db.json', bundled }); + } else { + this.database = createDatabase({ url: `${location.origin}/db` }); + } addons.setDatabase(this.database); } } diff --git a/src/server/build.js b/src/server/build.js index d23f54fc39ed..6a5a5e8defab 100644 --- a/src/server/build.js +++ b/src/server/build.js @@ -22,6 +22,8 @@ program .option('-s, --static-dir ', 'Directory where to load static files from', parseList) .option('-o, --output-dir [dir-name]', 'Directory where to store built files') .option('-c, --config-dir [dir-name]', 'Directory where to load Storybook configurations from') + .option('-d, --db-path [db-file]', 'Path to the addon database JSON file') + .option('--enable-db', 'Enable the (experimental) addon database service on dev-server') .parse(process.argv); // The key is the field created in `program` variable for @@ -58,6 +60,13 @@ if (program.staticDir) { }); } +// The addon database service is disabled by default for now +// It should be enabled with the --enable-db for dev server +if (program.enableDb) { + const dbPath = program.dbPath || './.storybook/addon-db.json'; + shelljs.cp(dbPath, outputDir); +} + // Write both the storybook UI and IFRAME HTML files to destination path. const headHtml = getHeadHtml(configDir); fs.writeFileSync(path.resolve(outputDir, 'index.html'), getIndexHtml(publicPath));