mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-04 18:21:08 +08:00
CLI: sb migrate typescript support
This commit is contained in:
parent
fa87bb091d
commit
7be5727376
@ -22,7 +22,7 @@ if (process.argv[1].includes('getstorybook')) {
|
||||
.option('-f --force', 'Forcely add storybook')
|
||||
.option('-s --skip-install', 'Skip installing deps')
|
||||
.option('-N --use-npm', 'Use npm to install deps')
|
||||
.option('-p --parser <babel | babylon | flow>', 'jscodeshift parser')
|
||||
.option('-p --parser <babel | babylon | flow | ts | tsx>', 'jscodeshift parser')
|
||||
.option('-t --type <type>', 'Add Storybook for a specific project type')
|
||||
.option('-y --yes', 'Answer yes to all prompts')
|
||||
.action(options => initiate(options, pkg));
|
||||
@ -53,6 +53,7 @@ if (process.argv[1].includes('getstorybook')) {
|
||||
.description('Run a storybook codemod migration on your source files')
|
||||
.option('-l --list', 'List available migrations')
|
||||
.option('-g --glob <glob>', 'Glob for files upon which to apply the migration', '**/*.js')
|
||||
.option('-p --parser <babel | babylon | flow | ts | tsx>', 'jscodeshift parser')
|
||||
.option(
|
||||
'-n --dry-run',
|
||||
'Dry run: verify the migration exists and show the files to which it will be applied'
|
||||
@ -61,8 +62,8 @@ if (process.argv[1].includes('getstorybook')) {
|
||||
'-r --rename <from-to>',
|
||||
'Rename suffix of matching files after codemod has been applied, e.g. ".js:.ts"'
|
||||
)
|
||||
.action((migration, { configDir, glob, dryRun, list, rename }) => {
|
||||
migrate(migration, { configDir, glob, dryRun, list, rename, logger }).catch(err => {
|
||||
.action((migration, { configDir, glob, dryRun, list, rename, parser }) => {
|
||||
migrate(migration, { configDir, glob, dryRun, list, rename, parser, logger }).catch(err => {
|
||||
logger.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
@ -25,7 +25,7 @@ async function renameFile(file, from, to, { logger }) {
|
||||
return fs.rename(file, newFile);
|
||||
}
|
||||
|
||||
export async function runCodemod(codemod, { glob, logger, dryRun, rename, hasYarn }) {
|
||||
export async function runCodemod(codemod, { glob, logger, dryRun, rename, hasYarn, parser }) {
|
||||
const codemods = listCodemods();
|
||||
if (!codemods.includes(codemod)) {
|
||||
throw new Error(`Unknown codemod ${codemod}. Run --list for options.`);
|
||||
@ -43,9 +43,14 @@ export async function runCodemod(codemod, { glob, logger, dryRun, rename, hasYar
|
||||
logger.log(`=> Applying ${codemod}: ${files.length} files`);
|
||||
if (!dryRun) {
|
||||
const runner = hasYarn ? 'yarn' : 'npx';
|
||||
spawnSync(runner, ['jscodeshift', '-t', `${TRANSFORM_DIR}/${codemod}.js`, ...files], {
|
||||
stdio: 'inherit',
|
||||
});
|
||||
const parserArgs = parser ? ['--parser', parser] : [];
|
||||
spawnSync(
|
||||
runner,
|
||||
['jscodeshift', '-t', `${TRANSFORM_DIR}/${codemod}.js`, ...parserArgs, ...files],
|
||||
{
|
||||
stdio: 'inherit',
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (renameParts) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user