Skip to content

Commit

Permalink
Merge pull request #2666 from storybooks/fix-config-dir-detection
Browse files Browse the repository at this point in the history
Fix config dir detection
  • Loading branch information
Hypnosphi authored Jan 6, 2018
2 parents bab8e24 + aff8b65 commit 7e3b29c
Show file tree
Hide file tree
Showing 20 changed files with 57 additions and 58 deletions.
2 changes: 1 addition & 1 deletion app/angular/src/server/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ shelljs.cp(path.resolve(__dirname, 'public/favicon.ico'), 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`
const config = loadConfig('PRODUCTION', getBaseConfig(), configDir);
const config = loadConfig('PRODUCTION', getBaseConfig(configDir), configDir);
config.output.path = path.resolve(outputDir);

// copy all static files
Expand Down
2 changes: 0 additions & 2 deletions app/angular/src/server/config/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,3 @@ export function loadEnv(options = {}) {
'process.env': env,
};
}

export const getConfigDir = () => process.env.SBCONFIG_CONFIG_DIR || './.storybook';
15 changes: 4 additions & 11 deletions app/angular/src/server/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@ import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import WatchMissingNodeModulesPlugin from './WatchMissingNodeModulesPlugin';

import {
getConfigDir,
includePaths,
excludePaths,
nodeModulesPaths,
loadEnv,
nodePaths,
} from './utils';
import { includePaths, excludePaths, nodeModulesPaths, loadEnv, nodePaths } from './utils';
import babelLoaderConfig from './babel';
import { getPreviewHeadHtml, getManagerHeadHtml } from '../utils';
import { version } from '../../../package.json';

export default function() {
export default function(configDir) {
const config = {
devtool: 'cheap-module-source-map',
entry: {
Expand All @@ -37,7 +30,7 @@ export default function() {
filename: 'index.html',
chunks: ['manager'],
data: {
managerHead: getManagerHeadHtml(getConfigDir()),
managerHead: getManagerHeadHtml(configDir),
version,
},
template: require.resolve('../index.html.ejs'),
Expand All @@ -46,7 +39,7 @@ export default function() {
filename: 'iframe.html',
excludeChunks: ['manager'],
data: {
previewHead: getPreviewHeadHtml(getConfigDir()),
previewHead: getPreviewHeadHtml(configDir),
},
template: require.resolve('../iframe.html.ejs'),
}),
Expand Down
8 changes: 4 additions & 4 deletions app/angular/src/server/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import UglifyJsPlugin from 'uglifyjs-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';

import babelLoaderConfig from './babel.prod';
import { getConfigDir, includePaths, excludePaths, loadEnv, nodePaths } from './utils';
import { includePaths, excludePaths, loadEnv, nodePaths } from './utils';
import { getPreviewHeadHtml, getManagerHeadHtml } from '../utils';
import { version } from '../../../package.json';

export default function() {
export default function(configDir) {
const entries = {
preview: [require.resolve('./polyfills'), require.resolve('./globals')],
manager: [require.resolve('./polyfills'), path.resolve(__dirname, '../../client/manager')],
Expand All @@ -32,7 +32,7 @@ export default function() {
filename: 'index.html',
chunks: ['manager'],
data: {
managerHead: getManagerHeadHtml(getConfigDir()),
managerHead: getManagerHeadHtml(configDir),
version,
},
template: require.resolve('../index.html.ejs'),
Expand All @@ -41,7 +41,7 @@ export default function() {
filename: 'iframe.html',
excludeChunks: ['manager'],
data: {
previewHead: getPreviewHeadHtml(getConfigDir()),
previewHead: getPreviewHeadHtml(configDir),
},
template: require.resolve('../iframe.html.ejs'),
}),
Expand Down
2 changes: 1 addition & 1 deletion app/angular/src/server/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const webpackValid = new Promise((resolve, reject) => {
export default function(configDir) {
// Build the webpack configuration using the `getBaseConfig`
// custom `.babelrc` file and `webpack.config.js` files
const config = loadConfig('DEVELOPMENT', getBaseConfig(), configDir);
const config = loadConfig('DEVELOPMENT', getBaseConfig(configDir), configDir);
const middlewareFn = getMiddleware(configDir);

// remove the leading '/'
Expand Down
2 changes: 1 addition & 1 deletion app/react/src/server/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ shelljs.cp(path.resolve(__dirname, 'public/favicon.ico'), 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`
const config = loadConfig('PRODUCTION', getBaseConfig(), configDir);
const config = loadConfig('PRODUCTION', getBaseConfig(configDir), configDir);
config.output.path = path.resolve(outputDir);

// copy all static files
Expand Down
2 changes: 0 additions & 2 deletions app/react/src/server/config/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,3 @@ export function loadEnv(options = {}) {
'process.env': env,
};
}

export const getConfigDir = () => process.env.SBCONFIG_CONFIG_DIR || './.storybook';
15 changes: 4 additions & 11 deletions app/react/src/server/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,12 @@ import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import WatchMissingNodeModulesPlugin from './WatchMissingNodeModulesPlugin';

import {
getConfigDir,
includePaths,
excludePaths,
nodeModulesPaths,
loadEnv,
nodePaths,
} from './utils';
import { includePaths, excludePaths, nodeModulesPaths, loadEnv, nodePaths } from './utils';
import babelLoaderConfig from './babel';
import { getPreviewHeadHtml, getManagerHeadHtml } from '../utils';
import { version } from '../../../package.json';

export default function() {
export default function(configDir) {
const config = {
devtool: 'cheap-module-source-map',
entry: {
Expand All @@ -38,7 +31,7 @@ export default function() {
filename: 'index.html',
chunks: ['manager'],
data: {
managerHead: getManagerHeadHtml(getConfigDir()),
managerHead: getManagerHeadHtml(configDir),
version,
},
template: require.resolve('../index.html.ejs'),
Expand All @@ -47,7 +40,7 @@ export default function() {
filename: 'iframe.html',
excludeChunks: ['manager'],
data: {
previewHead: getPreviewHeadHtml(getConfigDir()),
previewHead: getPreviewHeadHtml(configDir),
},
template: require.resolve('../iframe.html.ejs'),
}),
Expand Down
8 changes: 4 additions & 4 deletions app/react/src/server/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import UglifyJsPlugin from 'uglifyjs-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';

import babelLoaderConfig from './babel.prod';
import { getConfigDir, includePaths, excludePaths, loadEnv, nodePaths } from './utils';
import { includePaths, excludePaths, loadEnv, nodePaths } from './utils';
import { getPreviewHeadHtml, getManagerHeadHtml } from '../utils';
import { version } from '../../../package.json';

export default function() {
export default function(configDir) {
const entries = {
preview: [require.resolve('./polyfills'), require.resolve('./globals')],
manager: [require.resolve('./polyfills'), path.resolve(__dirname, '../../client/manager')],
Expand All @@ -32,7 +32,7 @@ export default function() {
filename: 'index.html',
chunks: ['manager'],
data: {
managerHead: getManagerHeadHtml(getConfigDir()),
managerHead: getManagerHeadHtml(configDir),
version,
},
template: require.resolve('../index.html.ejs'),
Expand All @@ -41,7 +41,7 @@ export default function() {
filename: 'iframe.html',
excludeChunks: ['manager'],
data: {
previewHead: getPreviewHeadHtml(getConfigDir()),
previewHead: getPreviewHeadHtml(configDir),
},
template: require.resolve('../iframe.html.ejs'),
}),
Expand Down
2 changes: 1 addition & 1 deletion app/react/src/server/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const webpackValid = new Promise((resolve, reject) => {
export default function(configDir) {
// Build the webpack configuration using the `getBaseConfig`
// custom `.babelrc` file and `webpack.config.js` files
const config = loadConfig('DEVELOPMENT', getBaseConfig(), configDir);
const config = loadConfig('DEVELOPMENT', getBaseConfig(configDir), configDir);
const middlewareFn = getMiddleware(configDir);

// remove the leading '/'
Expand Down
2 changes: 1 addition & 1 deletion app/vue/src/server/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ shelljs.cp(path.resolve(__dirname, 'public/favicon.ico'), 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`
const config = loadConfig('PRODUCTION', getBaseConfig(), configDir);
const config = loadConfig('PRODUCTION', getBaseConfig(configDir), configDir);
config.output.path = path.resolve(outputDir);

// copy all static files
Expand Down
2 changes: 0 additions & 2 deletions app/vue/src/server/config/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,3 @@ export function loadEnv(options = {}) {
'process.env': env,
};
}

export const getConfigDir = () => process.env.SBCONFIG_CONFIG_DIR || './.storybook';
15 changes: 4 additions & 11 deletions app/vue/src/server/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@ import Dotenv from 'dotenv-webpack';
import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import WatchMissingNodeModulesPlugin from './WatchMissingNodeModulesPlugin';
import {
getConfigDir,
includePaths,
excludePaths,
nodeModulesPaths,
loadEnv,
nodePaths,
} from './utils';
import { includePaths, excludePaths, nodeModulesPaths, loadEnv, nodePaths } from './utils';
import { getPreviewHeadHtml, getManagerHeadHtml } from '../utils';
import babelLoaderConfig from './babel';
import { version } from '../../../package.json';

export default function() {
export default function(configDir) {
const config = {
devtool: 'cheap-module-source-map',
entry: {
Expand All @@ -37,7 +30,7 @@ export default function() {
filename: 'index.html',
chunks: ['manager'],
data: {
managerHead: getManagerHeadHtml(getConfigDir()),
managerHead: getManagerHeadHtml(configDir),
version,
},
template: require.resolve('../index.html.ejs'),
Expand All @@ -46,7 +39,7 @@ export default function() {
filename: 'iframe.html',
excludeChunks: ['manager'],
data: {
previewHead: getPreviewHeadHtml(getConfigDir()),
previewHead: getPreviewHeadHtml(configDir),
},
template: require.resolve('../iframe.html.ejs'),
}),
Expand Down
8 changes: 4 additions & 4 deletions app/vue/src/server/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import UglifyJsPlugin from 'uglifyjs-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';

import babelLoaderConfig from './babel.prod';
import { getConfigDir, includePaths, excludePaths, loadEnv, nodePaths } from './utils';
import { includePaths, excludePaths, loadEnv, nodePaths } from './utils';
import { getPreviewHeadHtml, getManagerHeadHtml } from '../utils';
import { version } from '../../../package.json';

export default function() {
export default function(configDir) {
const entries = {
preview: [require.resolve('./polyfills'), require.resolve('./globals')],
manager: [require.resolve('./polyfills'), path.resolve(__dirname, '../../client/manager')],
Expand All @@ -32,7 +32,7 @@ export default function() {
filename: 'index.html',
chunks: ['manager'],
data: {
managerHead: getManagerHeadHtml(getConfigDir()),
managerHead: getManagerHeadHtml(configDir),
version,
},
template: require.resolve('../index.html.ejs'),
Expand All @@ -41,7 +41,7 @@ export default function() {
filename: 'iframe.html',
excludeChunks: ['manager'],
data: {
previewHead: getPreviewHeadHtml(getConfigDir()),
previewHead: getPreviewHeadHtml(configDir),
},
template: require.resolve('../iframe.html.ejs'),
}),
Expand Down
2 changes: 1 addition & 1 deletion app/vue/src/server/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const webpackValid = new Promise((resolve, reject) => {
export default function(configDir) {
// Build the webpack configuration using the `getBaseConfig`
// custom `.babelrc` file and `webpack.config.js` files
const config = loadConfig('DEVELOPMENT', getBaseConfig(), configDir);
const config = loadConfig('DEVELOPMENT', getBaseConfig(configDir), configDir);
const middlewareFn = getMiddleware(configDir);

// remove the leading '/'
Expand Down
5 changes: 4 additions & 1 deletion examples/official-storybook/addons.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies, import/no-unresolved, import/extensions */

import '@storybook/addon-actions/register';
import '@storybook/addon-links/register';
import '@storybook/addon-events/register';
Expand All @@ -9,3 +8,7 @@ import '@storybook/addon-knobs/register';
import '@storybook/addon-backgrounds/register';
import '@storybook/addon-a11y/register';
import '@storybook/addon-jest/register';

import addHeadWarning from './head-warning';

addHeadWarning('Manager');
3 changes: 3 additions & 0 deletions examples/official-storybook/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import { configure } from '@storybook/react';
import { setOptions } from '@storybook/addon-options';
import 'react-chromatic/storybook-addon';
import addHeadWarning from './head-warning';

addHeadWarning('Preview');

setOptions({
hierarchySeparator: /\/|\./,
Expand Down
10 changes: 10 additions & 0 deletions examples/official-storybook/head-warning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { document } from 'global';

export default function addHeadWarning(bundle) {
const warning = document.createElement('h1');
warning.textContent = `${bundle} head not loaded`;
warning.className = `${bundle.toLowerCase()}-head-not-loaded`;
warning.style.color = 'red';

document.body.insertBefore(warning, document.body.firstChild);
}
5 changes: 5 additions & 0 deletions examples/official-storybook/manager-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<style>
.manager-head-not-loaded {
display: none;
}
</style>
5 changes: 5 additions & 0 deletions examples/official-storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<style>
.preview-head-not-loaded {
display: none;
}
</style>

0 comments on commit 7e3b29c

Please sign in to comment.