Skip to content

Commit

Permalink
Merge pull request #21203 from storybookjs/norbert/init-not-run-all-c…
Browse files Browse the repository at this point in the history
…odemods

CLI: Only run useful automigrations on init
  • Loading branch information
ndelangen authored Feb 23, 2023
2 parents d05fde6 + 4413e87 commit 3d5d541
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion code/lib/cli/src/automigrate/fixes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { bareMdxStoriesGlob } from './bare-mdx-stories-glob';

export * from '../types';

export const fixes: Fix[] = [
export const allFixes: Fix[] = [
nodeJsRequirement,
cra5,
webpack5,
Expand All @@ -39,3 +39,5 @@ export const fixes: Fix[] = [
addReact,
missingBabelRc,
];

export const initFixes: Fix[] = [missingBabelRc, eslintPlugin];
7 changes: 5 additions & 2 deletions code/lib/cli/src/automigrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '../js-package-manager';

import type { Fix } from './fixes';
import { fixes as allFixes } from './fixes';
import { allFixes } from './fixes';
import { cleanLog } from './helpers/cleanLog';

const logger = console;
Expand Down Expand Up @@ -50,6 +50,7 @@ type FixId = string;
interface FixOptions {
fixId?: FixId;
list?: boolean;
fixes?: Fix[];
yes?: boolean;
dryRun?: boolean;
useNpm?: boolean;
Expand Down Expand Up @@ -89,6 +90,7 @@ const logAvailableMigrations = () => {

export const automigrate = async ({
fixId,
fixes: inputFixes,
dryRun,
yes,
useNpm,
Expand All @@ -109,7 +111,8 @@ export const automigrate = async ({
pkgMgr = 'npm';
}

const fixes = fixId ? allFixes.filter((f) => f.id === fixId) : allFixes;
const selectedFixes = inputFixes || allFixes;
const fixes = fixId ? selectedFixes.filter((f) => f.id === fixId) : selectedFixes;

if (fixId && fixes.length === 0) {
logger.info(`📭 No migrations found for ${chalk.magenta(fixId)}.`);
Expand Down
7 changes: 6 additions & 1 deletion code/lib/cli/src/initiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { JsPackageManagerFactory, useNpmWarning } from './js-package-manager';
import type { NpmOptions } from './NpmOptions';
import { automigrate } from './automigrate';
import type { CommandOptions } from './generators/types';
import { initFixes } from './automigrate/fixes';

const logger = console;

Expand Down Expand Up @@ -339,7 +340,11 @@ async function doInitiate(options: CommandOptions, pkg: PackageJson): Promise<vo
}

if (projectType !== ProjectType.REACT_NATIVE) {
await automigrate({ yes: options.yes || process.env.CI === 'true', packageManager: pkgMgr });
await automigrate({
yes: options.yes || process.env.CI === 'true',
packageManager: pkgMgr,
fixes: initFixes,
});
}

logger.log('\nFor more information visit:', chalk.cyan('https://storybook.js.org'));
Expand Down

0 comments on commit 3d5d541

Please sign in to comment.