Skip to content

Commit

Permalink
Enable database with a flag
Browse files Browse the repository at this point in the history
  • Loading branch information
thani-sh committed Sep 1, 2016
1 parent fb2e404 commit 014fc27
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
11 changes: 8 additions & 3 deletions dist/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de

var logger = console;

_commander2.default.version(_package2.default.version).option('-p, --port [number]', 'Port to run Storybook (Required)', parseInt).option('-h, --host [string]', 'Host to run Storybook').option('-s, --static-dir <dir-names>', 'Directory where to load static files from', _utils.parseList).option('-c, --config-dir [dir-name]', 'Directory where to load Storybook configurations from').option('--dont-track', 'Do not send anonymous usage stats.').parse(process.argv);
_commander2.default.version(_package2.default.version).option('-p, --port [number]', 'Port to run Storybook (Required)', parseInt).option('-h, --host [string]', 'Host to run Storybook').option('-s, --static-dir <dir-names>', 'Directory where to load static files from', _utils.parseList).option('-c, --config-dir [dir-name]', 'Directory where to load Storybook configurations from').option('-d, --db-path [db-file]', 'File where to store addon database JSON file').option('--enable-db', 'Enable the (experimental) addon database service on dev-server').option('--dont-track', 'Do not send anonymous usage stats.').parse(process.argv);

// The key is the field created in `program` variable for
// each command line argument. Value is the env variable.
Expand Down Expand Up @@ -83,9 +83,14 @@ 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';
var dbPath = _path2.default.resolve(configDir, 'datastore.json');
app.use((0, _middleware2.default)(configDir));
app.use('/db', (0, _middleware4.default)(dbPath));

// 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';
app.use('/db', (0, _middleware4.default)(dbPath));
}

app.listen.apply(app, listenAddr.concat([function (error) {
if (error) {
Expand Down
11 changes: 9 additions & 2 deletions src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ program
.option('-h, --host [string]', 'Host to run Storybook')
.option('-s, --static-dir <dir-names>', 'Directory where to load static files from', parseList)
.option('-c, --config-dir [dir-name]', 'Directory where to load Storybook configurations from')
.option('-d, --db-path [db-file]', 'File where to store addon database JSON file')
.option('--enable-db', 'Enable the (experimental) addon database service on dev-server')
.option('--dont-track', 'Do not send anonymous usage stats.')
.parse(process.argv);

Expand Down Expand Up @@ -65,9 +67,14 @@ if (program.staticDir) {
// Build the webpack configuration using the `baseConfig`
// custom `.babelrc` file and `webpack.config.js` files
const configDir = program.configDir || './.storybook';
const dbPath = path.resolve(configDir, 'datastore.json');
app.use(storybook(configDir));
app.use('/db', datastore(dbPath));

// 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';
app.use('/db', datastore(dbPath));
}

app.listen(...listenAddr, function (error) {
if (error) {
Expand Down

0 comments on commit 014fc27

Please sign in to comment.