Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,14 @@ If you don't want to use `yarn` always you can use the `--use-npm` option like t
getstorybook --use-npm
```

* * *

## [Flow](https://flow.org/) support

It also supports flow files. By default, [jscodeshift](https://github.com/facebook/jscodeshift), the tool used to transform the source files, uses babel to read the files. To be able to transform any flow annotated file, you need to use the flow parser.

```sh
getstorybook --parser flow
```

For more information visit: [storybook.js.org](https://storybook.js.org)
3 changes: 2 additions & 1 deletion lib/cli/bin/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ program
.version(pkg.version)
.option('-f --force', 'Forcely add storybook')
.option('-N --use-npm', 'Use npm to install deps')
.option('-p --parser <babel | babylon | flow>', 'jscodeshift parser')
.parse(process.argv);

const welcomeMessage = 'getstorybook - the simplest way to add a storybook to your project.';
Expand Down Expand Up @@ -78,7 +79,7 @@ switch (projectType) {

case types.UPDATE_PACKAGE_ORGANIZATIONS:
// eslint-disable-next-line
require('../generators/UPDATE_PACKAGE_ORGANIZATIONS')
require('../generators/UPDATE_PACKAGE_ORGANIZATIONS')(program.parser)
.then(() => null) // commmandLog doesn't like to see output
.then(commandLog('Upgrading your project to the new storybook packages.'))
.then(end);
Expand Down
5 changes: 3 additions & 2 deletions lib/cli/generators/UPDATE_PACKAGE_ORGANIZATIONS/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function updatePackageJson() {
});
}

function updateSourceCode() {
function updateSourceCode(parser) {
const jscodeshiftPath = path.dirname(require.resolve('jscodeshift'));
const jscodeshiftCommand = path.join(jscodeshiftPath, 'bin', 'jscodeshift.sh');

Expand All @@ -43,8 +43,9 @@ function updateSourceCode() {
);

const args = ['-t', codemodPath, '--silent', '--ignore-pattern', '"node_modules|dist"', '.'];
if (parser) args.push('--parser', parser);

return spawn(jscodeshiftCommand, args, { stdio: 'inherit' });
}

module.exports = updatePackageJson().then(updateSourceCode);
module.exports = parser => updatePackageJson().then(() => updateSourceCode(parser));