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

Configure start/build using env variables #413

Merged
merged 2 commits into from
Aug 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions dist/server/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ 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);

// The key is the field created in `program` variable for
// each command line argument. Value is the env variable.
(0, _utils.getEnvConfig)(_commander2.default, {
staticDir: 'STORYBOOK_STATIC_DIR',
outputDir: 'STORYBOOK_OUTPUT_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';
Expand Down
10 changes: 10 additions & 0 deletions dist/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ 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);

// The key is the field created in `program` variable for
// each command line argument. Value is the env variable.
(0, _utils.getEnvConfig)(_commander2.default, {
port: 'STORYBOOK_PORT',
host: 'STORYBOOK_HOST',
staticDir: 'STORYBOOK_STATIC_DIR',
configDir: 'STORYBOOK_CONFIG_DIR',
dontTrack: 'STORYBOOK_DO_NOT_TRACK'
});

if (_commander2.default.dontTrack) {
(0, _track_usage.dontTrack)();
}
Expand Down
16 changes: 16 additions & 0 deletions dist/server/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
Object.defineProperty(exports, "__esModule", {
value: true
});

var _keys = require('babel-runtime/core-js/object/keys');

var _keys2 = _interopRequireDefault(_keys);

exports.parseList = parseList;
exports.getHeadHtml = getHeadHtml;
exports.getEnvConfig = getEnvConfig;

var _path = require('path');

Expand All @@ -28,4 +34,14 @@ function getHeadHtml(configDirPath) {
}

return headHtml;
}

function getEnvConfig(program, configEnv) {
(0, _keys2.default)(configEnv).forEach(function (fieldName) {
var envVarName = configEnv[fieldName];
var envVarValue = process.env[envVarName];
if (envVarValue) {
program[fieldName] = envVarValue; // eslint-disable-line no-param-reassign
}
});
}
10 changes: 9 additions & 1 deletion src/server/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import baseConfig from './config/webpack.config.prod';
import loadConfig from './config';
import getIndexHtml from './index.html';
import getIframeHtml from './iframe.html';
import { getHeadHtml, parseList } from './utils';
import { getHeadHtml, parseList, getEnvConfig } from './utils';

// avoid ESLint errors
const logger = console;
Expand All @@ -24,6 +24,14 @@ program
.option('-c, --config-dir [dir-name]', 'Directory where to load Storybook configurations from')
.parse(process.argv);

// The key is the field created in `program` variable for
// each command line argument. Value is the env variable.
getEnvConfig(program, {
staticDir: 'STORYBOOK_STATIC_DIR',
outputDir: 'STORYBOOK_OUTPUT_DIR',
configDir: 'STORYBOOK_CONFIG_DIR',
});

// Build the webpack configuration using the `baseConfig`
// custom `.babelrc` file and `webpack.config.js` files
const configDir = program.configDir || './.storybook';
Expand Down
11 changes: 10 additions & 1 deletion src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import path from 'path';
import fs from 'fs';
import storybook from './middleware';
import packageJson from '../../package.json';
import { parseList } from './utils';
import { parseList, getEnvConfig } from './utils';
import { track, dontTrack } from './track_usage';

const logger = console;
Expand All @@ -20,6 +20,15 @@ program
.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.
getEnvConfig(program, {
port: 'STORYBOOK_PORT',
host: 'STORYBOOK_HOST',
staticDir: 'STORYBOOK_STATIC_DIR',
configDir: 'STORYBOOK_CONFIG_DIR',
dontTrack: 'STORYBOOK_DO_NOT_TRACK',
});

if (program.dontTrack) {
dontTrack();
Expand Down
10 changes: 10 additions & 0 deletions src/server/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ export function getHeadHtml(configDirPath) {

return headHtml;
}

export function getEnvConfig(program, configEnv) {
Object.keys(configEnv).forEach(fieldName => {
const envVarName = configEnv[fieldName];
const envVarValue = process.env[envVarName];
if (envVarValue) {
program[fieldName] = envVarValue; // eslint-disable-line no-param-reassign
}
});
}