-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21809 from storybookjs/kasper/mdx-update-glob-in-…
…codemod CLI: Update stories glob in mdx codemod and not in mdx automigration
- Loading branch information
Showing
3 changed files
with
90 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +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' && !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}`, | ||
]); | ||
} |