Skip to content

Commit

Permalink
Reduce complexity of setBuildCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhobbs committed Sep 12, 2024
1 parent bef1923 commit 238f528
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions node-src/tasks/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,26 @@ export const setSourceDir = async (ctx: Context) => {
}
};

// Storybook 8.0.0 deprecated --webpack-stats-json in favor of --stats-json.
const webpackStatsFlag = (version: string) => {
return semver.gte(semver.coerce(version), '8.0.0') ? '--stats-json' : '--webpack-stats-json';
};

export const setBuildCommand = async (ctx: Context) => {
const webpackStatsSupported =
ctx.storybook && ctx.storybook.version
? semver.gte(semver.coerce(ctx.storybook.version), '6.2.0')
: true;

const webpackStatsFlag =
webpackStatsSupported && semver.gte(semver.coerce(ctx.storybook.version), '8.0.0')
? '--stats-json'
: '--webpack-stats-json';

if (ctx.git.changedFiles && !webpackStatsSupported) {
ctx.log.warn('Storybook version 6.2.0 or later is required to use the --only-changed flag');
}

const buildCommandOptions = [
`--output-dir=${ctx.sourceDir}`,
ctx.git.changedFiles && webpackStatsSupported && `${webpackStatsFlag}=${ctx.sourceDir}`,
ctx.git.changedFiles &&
webpackStatsSupported &&
`${webpackStatsFlag(ctx.storybook.version)}=${ctx.sourceDir}`,
].filter(Boolean);

if (isE2EBuild(ctx.options)) {
Expand Down

0 comments on commit 238f528

Please sign in to comment.