Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
Merge pull request #20 from kadirahq/use-yarn
Browse files Browse the repository at this point in the history
Use yarn!
  • Loading branch information
arunoda authored Oct 12, 2016
2 parents ff0f2ce + af3ed49 commit 8716c37
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 18 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,25 @@ That's all you've to do.

---

## Yarn support

getstorybook also supports yarn. If you are using yarn, this is how to use it:

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

`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.
35 changes: 22 additions & 13 deletions bin/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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 installNpmDeps = require('../lib/helpers').installNpmDeps;
var installDeps = require('../lib/helpers').installDeps;
var chalk = require('chalk');
var logger = console;

Expand All @@ -18,12 +18,21 @@ var pkg = require('../package.json');
program
.version(pkg.version)
.option('-f --force', 'Forcely add storybook')
.option('-Y --use-yarn', 'Use yarn 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 npmOptions = {
useYarn: useYarn
};

var runStorybookCommand = useYarn? 'yarn run storybook' : 'npm run storybook';

// Update notify code.
updateNotifier({
pkg: pkg,
Expand Down Expand Up @@ -55,11 +64,11 @@ switch (projectType) {
require('../generators/REACT_SCRIPTS');
done();

installNpmDeps();
installDeps(npmOptions);

logger.log('\nTo run your storybook, type:\n');
codeLog([
'npm run storybook'
runStorybookCommand
]);
logger.log('\nFor more information visit:', chalk.cyan('http://getstorybook.io'));
break;
Expand All @@ -69,11 +78,11 @@ switch (projectType) {
require('../generators/REACT');
done();

installNpmDeps();
installDeps(npmOptions);

logger.log('\nTo run your storybook, type:\n');
codeLog([
'npm run storybook'
runStorybookCommand
]);
logger.log('\nFor more information visit:', chalk.cyan('http://getstorybook.io'));
break;
Expand All @@ -83,11 +92,11 @@ switch (projectType) {
require('../generators/REACT_NATIVE');
done();

installNpmDeps();
installDeps(npmOptions);

logger.log('\nTo run your storybook, type:\n');
codeLog([
'npm run storybook'
runStorybookCommand
]);
logger.log('\nFor more information visit:', chalk.cyan('http://getstorybook.io'));
break;
Expand All @@ -97,11 +106,11 @@ switch (projectType) {
require('../generators/METEOR');
done();

installNpmDeps();
installDeps(npmOptions);

logger.log('\nTo run your storybook, type:\n');
codeLog([
'npm run storybook'
runStorybookCommand
]);
logger.log('\nFor more information visit:', chalk.cyan('http://getstorybook.io'));
break;
Expand All @@ -111,11 +120,11 @@ switch (projectType) {
require('../generators/WEBPACK_REACT');
done();

installNpmDeps();
installDeps(npmOptions);

logger.log('\nTo run your storybook, type:\n');
codeLog([
'npm run storybook'
runStorybookCommand
]);
logger.log('\nFor more information visit:', chalk.cyan('http://getstorybook.io'));
break;
Expand All @@ -125,11 +134,11 @@ switch (projectType) {
require('../generators/REACT');
done();

installNpmDeps();
installDeps(npmOptions);

logger.log('\nTo run your storybook, type:\n');
codeLog([
'npm run storybook'
runStorybookCommand
]);
logger.log('\nFor more information visit:', chalk.cyan('http://getstorybook.io'));
break;
Expand Down
18 changes: 13 additions & 5 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,22 @@ exports.codeLog = function codeLog(codeLines, leftPadAmount) {
logger.log(finalResult);
};

exports.installNpmDeps = function () {
var done = exports.commandLog('Preparing to install NPM dependencies');
exports.installDeps = function (options) {
var done = exports.commandLog('Preparing to install dependencies');
done();
console.log();

var result = spawnSync('npm', ['install'], { stdio: 'inherit' });
done = exports.commandLog('Installing NPM dependencies');
var result;
if (options.useYarn) {
result = spawnSync('yarn', { stdio: 'inherit' });
} else {
result = spawnSync('npm', ['install'], { stdio: 'inherit' });
}

console.log();
done = exports.commandLog('Installing dependencies');
if (result.status !== 0) {
done('An error occured while running `npm install`.');
done('An error occured while installing dependencies`.');
process.exit(1);
}
done();
Expand Down

0 comments on commit 8716c37

Please sign in to comment.