Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Support TSX in storiesof-to-csf migration #11107

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/codemod/src/lib/utils.js
Expand Up @@ -13,3 +13,6 @@ export const sanitizeName = (name) => {
}
return key;
};

export const prettierParser = (parser) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe jscodeshiftToPrettierParser.
And use a map:

const parserMap = {
  'babylon': 'babel',
  'flow': 'flow',
  'ts': 'typescript',
  'tsx': 'typescript'
};

return parserMap[parser] || 'babel';

['tsx', 'ts'].includes(parser) ? 'typescript' : parser || 'babel';
4 changes: 2 additions & 2 deletions lib/codemod/src/transforms/storiesof-to-csf.js
@@ -1,7 +1,7 @@
import prettier from 'prettier';
import { logger } from '@storybook/node-logger';
import { storyNameFromExport } from '@storybook/csf';
import { sanitizeName } from '../lib/utils';
import { sanitizeName, prettierParser } from '../lib/utils';

/**
* Convert a legacy story API to component story format
Expand Down Expand Up @@ -261,7 +261,7 @@ export default function transformer(file, api, options) {
}

return prettier.format(source, {
parser: options.parser || 'babel',
parser: prettierParser(options.parser),
// FIXME: storybook defaults
printWidth: 100,
tabWidth: 2,
Expand Down