Skip to content

Commit

Permalink
Merge branch 'kasper/install-blocks' into kasper/mdx-update-glob-in-c…
Browse files Browse the repository at this point in the history
…odemod

# Conflicts:
#	code/lib/cli/src/migrate.ts
  • Loading branch information
kasperpeulen committed Mar 30, 2023
2 parents 299293a + 6bcd662 commit 919d964
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions code/lib/cli/src/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import { listCodemods, runCodemod } from '@storybook/codemod';
import { runFixes } from './automigrate';
import { bareMdxStoriesGlob } from './automigrate/fixes/bare-mdx-stories-glob';
import { JsPackageManagerFactory } from './js-package-manager';
import { getStorybookVersionSpecifier } from './helpers';

export async function migrate(migration: any, { glob, dryRun, list, rename, logger, parser }: any) {
const logger = console;

export async function migrate(migration: any, { glob, dryRun, list, rename, parser }: any) {
if (list) {
listCodemods().forEach((key: any) => logger.log(key));
} else if (migration) {
if (migration === 'mdx-to-csf') {
if (migration === 'mdx-to-csf' && !dryRun) {
await runFixes({ fixes: [bareMdxStoriesGlob] });
await addStorybookBlocksPackage();
}
await runCodemod(migration, { glob, dryRun, logger, rename, parser });
} else {
throw new Error('Migrate: please specify a migration name or --list');
}
}

export async function addStorybookBlocksPackage() {
const packageManager = JsPackageManagerFactory.getPackageManager();
const packageJson = packageManager.retrievePackageJson();
const versionToInstall = getStorybookVersionSpecifier(packageManager.retrievePackageJson());
logger.info(`✅ Adding "@storybook/blocks" package`);
await packageManager.addDependencies({ installAsDevDependencies: true, packageJson }, [
`@storybook/blocks@${versionToInstall}`,
]);
}

0 comments on commit 919d964

Please sign in to comment.