Skip to content

Commit

Permalink
Merge pull request #24 from storybooks/simplified-yarn-support
Browse files Browse the repository at this point in the history
Use a non-hacky way to detect yarn.
  • Loading branch information
arunoda authored Dec 18, 2016
2 parents 75a3f03 + a8641b7 commit 9ff2267
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
20 changes: 6 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,17 @@ That's all you've to do.

---

## Yarn support
## [Yarn](https://github.com/yarnpkg/yarn) support

getstorybook also supports yarn. If you are using yarn, this is how to use it:
`getstorybook` also supports yarn.
If you have installed yarn in your system, it'll detect it and use `yarn` instead of `npm`.

If you don't want to use `npm` always you can use the `--use-npm` option like this:

```
yarn global add getstorybook
getstorybook --use-yarn
getstorybook --use-npm
```

`getstorybook` will identify it's installed with yarn and it'll use yarn to install deps.

> This is the way, if you wanna use yarn for all of your storybook projects.

If that's not the case, you can do this:

```
npm i -g getstorybook
getstorybook --use-yarn
```

For more information, refer [React Storybook](https://github.com/kadirahq/react-storybook) documentation.
7 changes: 4 additions & 3 deletions bin/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,29 @@

var updateNotifier = require('update-notifier');
var program = require('commander');
var chalk = require('chalk');
var detect = require('../lib/detect');
var hasYarn = require('../lib/has_yarn')
var types = require('../lib/project_types');
var commandLog = require('../lib/helpers').commandLog;
var codeLog = require('../lib/helpers').codeLog;
var paddedLog = require('../lib/helpers').paddedLog;
var installDeps = require('../lib/helpers').installDeps;
var chalk = require('chalk');
var logger = console;

var pkg = require('../package.json');

program
.version(pkg.version)
.option('-f --force', 'Forcely add storybook')
.option('-Y --use-yarn', 'Use yarn to install deps')
.option('-N --use-npm', 'Use npm to install deps')
.parse(process.argv);

var welcomeMessage =
'getstorybook - the simplest way to add a storybook to your project.';
logger.log(chalk.inverse('\n ' + welcomeMessage + ' \n'));

var useYarn = Boolean(program.useYarn) || /\.yarn-cache/.test(__dirname);
var useYarn = Boolean(program.useNpm !== true) && hasYarn()

var npmOptions = {
useYarn: useYarn
Expand Down
6 changes: 6 additions & 0 deletions lib/has_yarn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var spawnSync = require('spawn-sync');

module.exports = function hasYarn() {
var result = spawnSync('yarn', ['--version'], { silent: true });
return result.status === 0;
}

0 comments on commit 9ff2267

Please sign in to comment.