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

Fix storybook-build manager-head.html bug #1248

Merged
merged 3 commits into from
Jun 10, 2017
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
13 changes: 9 additions & 4 deletions app/react/src/server/build.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import getBaseConfig from './config/webpack.config.prod';
import loadConfig from './config';
import getIndexHtml from './index.html';
import getIframeHtml from './iframe.html';
import { getHeadHtml, parseList, getEnvConfig } from './utils';
import { getPreviewHeadHtml, getManagerHeadHtml, parseList, getEnvConfig } from './utils';

process.env.NODE_ENV = process.env.NODE_ENV || 'production';

Expand Down Expand Up @@ -87,9 +87,14 @@ webpack(config).run((err, stats) => {
publicPath: config.output.publicPath,
assets: stats.toJson().assetsByChunkName,
};
const headHtml = getHeadHtml(configDir);

// Write both the storybook UI and IFRAME HTML files to destination path.
fs.writeFileSync(path.resolve(outputDir, 'index.html'), getIndexHtml(data));
fs.writeFileSync(path.resolve(outputDir, 'iframe.html'), getIframeHtml({ ...data, headHtml }));
fs.writeFileSync(
path.resolve(outputDir, 'index.html'),
getIndexHtml({ ...data, headHtml: getManagerHeadHtml(configDir) })
);
fs.writeFileSync(
path.resolve(outputDir, 'iframe.html'),
getIframeHtml({ ...data, headHtml: getPreviewHeadHtml(configDir) })
);
});
4 changes: 1 addition & 3 deletions app/react/src/server/iframe.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ const urlsFromAssets = assets => {
return urls;
};

export default function(data) {
const { assets, headHtml, publicPath } = data;

export default function({ assets, publicPath, headHtml }) {
const urls = urlsFromAssets(assets);

const cssTags = urls.css
Expand Down
4 changes: 1 addition & 3 deletions app/react/src/server/index.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ const managerUrlsFromAssets = assets => {
};
};

export default function(data) {
const { assets, publicPath, headHtml } = data;

export default function({ assets, publicPath, headHtml }) {
const managerUrls = managerUrlsFromAssets(assets);

return `
Expand Down
4 changes: 2 additions & 2 deletions app/react/src/server/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import getBaseConfig from './config/webpack.config';
import loadConfig from './config';
import getIndexHtml from './index.html';
import getIframeHtml from './iframe.html';
import { getHeadHtml, getManagerHeadHtml, getMiddleware } from './utils';
import { getPreviewHeadHtml, getManagerHeadHtml, getMiddleware } from './utils';

let webpackResolve = () => {};
let webpackReject = () => {};
Expand Down Expand Up @@ -55,7 +55,7 @@ export default function(configDir) {
});

router.get('/iframe.html', (req, res) => {
const headHtml = getHeadHtml(configDir);
const headHtml = getPreviewHeadHtml(configDir);
res.send(getIframeHtml({ ...data, headHtml, publicPath }));
});

Expand Down
2 changes: 1 addition & 1 deletion app/react/src/server/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function parseList(str) {
return str.split(',');
}

export function getHeadHtml(configDirPath) {
export function getPreviewHeadHtml(configDirPath) {
const headHtmlPath = path.resolve(configDirPath, 'preview-head.html');
const fallbackHtmlPath = path.resolve(configDirPath, 'head.html');
let headHtml = '';
Expand Down
8 changes: 4 additions & 4 deletions app/react/src/server/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import mock from 'mock-fs';
import { getHeadHtml } from './utils';
import { getPreviewHeadHtml } from './utils';

const HEAD_HTML_CONTENTS = '<script>console.log("custom script!");</script>';

describe('server.getHeadHtml', () => {
describe('server.getPreviewHeadHtml', () => {
describe('when .storybook/head.html does not exist', () => {
beforeEach(() => {
mock({
Expand All @@ -16,7 +16,7 @@ describe('server.getHeadHtml', () => {
});

it('return an empty string', () => {
const result = getHeadHtml('./config');
const result = getPreviewHeadHtml('./config');
expect(result).toEqual('');
});
});
Expand All @@ -35,7 +35,7 @@ describe('server.getHeadHtml', () => {
});

it('return the contents of the file', () => {
const result = getHeadHtml('./config');
const result = getPreviewHeadHtml('./config');
expect(result).toEqual(HEAD_HTML_CONTENTS);
});
});
Expand Down