Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support read-only db with build-storybook #417

Merged
merged 2 commits into from
Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion dist/client/manager/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion dist/server/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <dir-names>', '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 <dir-names>', '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]', 'File where to store 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.
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion src/client/manager/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/server/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ program
.option('-s, --static-dir <dir-names>', '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]', 'File where to store addon database JSON file')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be description need to be changed to "where load from" or something similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, updated it. Now it simply says path to db 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
Expand Down Expand Up @@ -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));
Expand Down