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

Build: Create webpack stats target directory if needed and accept boolean flag #14690

Merged
merged 2 commits into from
Apr 22, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/core-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export interface CLIOptions {
docsDll?: boolean;
uiDll?: boolean;
debugWebpack?: boolean;
webpackStatsJson?: string;
webpackStatsJson?: string | boolean;
outputDir?: string;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/core-server/src/build-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ export async function buildDevStandalone(options: CLIOptions & LoadOptions & Bui
const managerStats = managerResult && managerResult.stats;

if (options.webpackStatsJson) {
await outputStats(options.webpackStatsJson, previewStats, managerStats);
const target = options.webpackStatsJson === true ? options.outputDir : options.webpackStatsJson;
await outputStats(target, previewStats, managerStats);
}

if (options.smokeTest) {
Expand Down
3 changes: 2 additions & 1 deletion lib/core-server/src/build-static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ export async function buildStaticStandalone(options: CLIOptions & LoadOptions &
const [managerStats, previewStats] = await Promise.all([manager, preview]);

if (options.webpackStatsJson) {
await outputStats(options.webpackStatsJson, previewStats, managerStats);
const target = options.webpackStatsJson === true ? options.outputDir : options.webpackStatsJson;
await outputStats(target, previewStats, managerStats);
}

logger.info(`=> Output directory: ${options.outputDir}`);
Expand Down
10 changes: 5 additions & 5 deletions lib/core-server/src/cli/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export async function getDevCli(packageJson: {

program
.version(packageJson.version)
.option('-p, --port [number]', 'Port to run Storybook', (str) => parseInt(str, 10))
.option('-h, --host [string]', 'Host to run Storybook')
.option('-p, --port <number>', 'Port to run Storybook', (str) => parseInt(str, 10))
.option('-h, --host <string>', 'Host to run Storybook')
.option('-s, --static-dir <dir-names>', 'Directory where to load static files from', parseList)
.option('-c, --config-dir [dir-name]', 'Directory where to load Storybook configurations from')
.option('-c, --config-dir <dir-name>', 'Directory where to load Storybook configurations from')
.option(
'--https',
'Serve Storybook over HTTPS. Note: You must provide your own certificate information.'
Expand All @@ -29,7 +29,7 @@ export async function getDevCli(packageJson: {
.option('--ssl-key <key>', 'Provide an SSL key. (Required with --https)')
.option('--smoke-test', 'Exit after successful start')
.option('--ci', "CI mode (skip interactive prompts, don't open browser)")
.option('--loglevel [level]', 'Control level of logging during build')
.option('--loglevel <level>', 'Control level of logging during build')
.option('--quiet', 'Suppress verbose build output')
.option('--no-version-updates', 'Suppress update check', true)
.option(
Expand All @@ -44,7 +44,7 @@ export async function getDevCli(packageJson: {
.option('--debug-webpack', 'Display final webpack configurations for debugging purposes')
.option('--webpack-stats-json [directory]', 'Write Webpack Stats JSON to disk')
.option(
'--preview-url [string]',
'--preview-url <string>',
'Disables the default storybook preview and lets your use your own'
)
.option('--docs', 'Build a documentation-only site using addon-docs')
Expand Down
8 changes: 4 additions & 4 deletions lib/core-server/src/cli/prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ export function getProdCli(packageJson: {
program
.version(packageJson.version)
.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('-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('-w, --watch', 'Enable watch mode')
.option('--quiet', 'Suppress verbose build output')
.option('--loglevel [level]', 'Control level of logging during build')
.option('--loglevel <level>', 'Control level of logging during build')
.option('--no-dll', 'Do not use dll reference (no-op)')
.option('--docs-dll', 'Use Docs dll reference (legacy)')
.option('--ui-dll', 'Use UI dll reference (legacy)')
.option('--debug-webpack', 'Display final webpack configurations for debugging purposes')
.option('--webpack-stats-json [directory]', 'Write Webpack Stats JSON to disk')
.option(
'--preview-url [string]',
'--preview-url <string>',
'Disables the default storybook preview and lets your use your own'
)
.option('--docs', 'Build a documentation-only site using addon-docs')
Expand Down
2 changes: 1 addition & 1 deletion lib/core-server/src/utils/output-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export async function outputStats(directory: string, previewStats?: any, manager

export const writeStats = async (directory: string, name: string, stats: Stats) => {
const filePath = path.join(directory, `${name}-stats.json`);
await fs.writeFile(filePath, JSON.stringify(stats.toJson(), null, 2), 'utf8');
await fs.outputFile(filePath, JSON.stringify(stats.toJson(), null, 2), 'utf8');
return filePath;
};