FIX build-storybook for angular

This commit is contained in:
Norbert de Langen 2017-09-13 08:02:56 +02:00
parent 8e041e97b9
commit 72f75e3d92

View File

@ -1,5 +1,3 @@
#!/usr/bin/env node
import webpack from 'webpack';
import program from 'commander';
import path from 'path';
@ -9,9 +7,7 @@ import shelljs from 'shelljs';
import packageJson from '../../package.json';
import getBaseConfig from './config/webpack.config.prod';
import loadConfig from './config';
import getIndexHtml from './index.html';
import getIframeHtml from './iframe.html';
import { getPreviewHeadHtml, getManagerHeadHtml, parseList, getEnvConfig } from './utils';
import { parseList, getEnvConfig } from './utils';
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
@ -51,9 +47,10 @@ getEnvConfig(program, {
const configDir = program.configDir || './.storybook';
const outputDir = program.outputDir || './storybook-static';
// create output directory (and the static dir) if not exists
shelljs.rm('-rf', outputDir);
// create output directory if not exists
shelljs.mkdir('-p', path.resolve(outputDir));
// clear the static dir
shelljs.rm('-rf', path.resolve(outputDir, 'static'));
shelljs.cp(path.resolve(__dirname, 'public/favicon.ico'), outputDir);
// Build the webpack configuration using the `baseConfig`
@ -77,24 +74,12 @@ if (program.staticDir) {
// compile all resources with webpack and write them to the disk.
logger.log('Building storybook ...');
webpack(config).run((err, stats) => {
if (err) {
if (err || stats.hasErrors()) {
logger.error('Failed to build the storybook');
logger.error(err.message);
// eslint-disable-next-line no-unused-expressions
err && logger.error(err.message);
// eslint-disable-next-line no-unused-expressions
stats.hasErrors() && stats.toJson().errors.forEach(e => logger.error(e));
process.exit(1);
}
const data = {
publicPath: config.output.publicPath,
assets: stats.toJson().assetsByChunkName,
};
// Write both the storybook UI and IFRAME HTML files to destination path.
fs.writeFileSync(
path.resolve(outputDir, 'index.html'),
getIndexHtml({ ...data, headHtml: getManagerHeadHtml(configDir) })
);
fs.writeFileSync(
path.resolve(outputDir, 'iframe.html'),
getIframeHtml({ ...data, headHtml: getPreviewHeadHtml(configDir) })
);
});