Skip to content

Commit

Permalink
fix migrate command that calls the changed runFixes fn
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelangen committed Feb 7, 2024
1 parent aeac067 commit 1c3aa9b
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions code/lib/cli/src/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { listCodemods, runCodemod } from '@storybook/codemod';
import { runFixes } from './automigrate';
import { bareMdxStoriesGlob } from './automigrate/fixes/bare-mdx-stories-glob';
import { JsPackageManagerFactory } from '@storybook/core-common';
import {
JsPackageManagerFactory,
getStorybookInfo,
getCoercedStorybookVersion,
} from '@storybook/core-common';
import { getStorybookVersionSpecifier } from './helpers';

const logger = console;
Expand All @@ -11,7 +15,33 @@ export async function migrate(migration: any, { glob, dryRun, list, rename, pars
listCodemods().forEach((key: any) => logger.log(key));
} else if (migration) {
if (migration === 'mdx-to-csf' && !dryRun) {
await runFixes({ fixes: [bareMdxStoriesGlob] });
const packageManager = JsPackageManagerFactory.getPackageManager();

const [packageJson, storybookVersion] = await Promise.all([
//
packageManager.retrievePackageJson(),
getCoercedStorybookVersion(packageManager),
]);
const { configDir: inferredConfigDir, mainConfig: mainConfigPath } =
getStorybookInfo(packageJson);
const configDir = inferredConfigDir || '.storybook';

// GUARDS
if (!storybookVersion) {
throw new Error('Could not determine Storybook version');
}

if (!mainConfigPath) {
throw new Error('Could not determine main config path');
}

await runFixes({
fixes: [bareMdxStoriesGlob],
configDir,
mainConfigPath,
packageManager,
storybookVersion,
});
await addStorybookBlocksPackage();
}
await runCodemod(migration, { glob, dryRun, logger, rename, parser });
Expand Down

0 comments on commit 1c3aa9b

Please sign in to comment.