From ed169e7b972910ec33ca261a6791e308f728dbb1 Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Wed, 12 Oct 2016 08:02:33 +0530 Subject: [PATCH] Add the initial support for yarn with flag. --- README.md | 9 +++++++++ bin/generate.js | 33 ++++++++++++++++++++------------- lib/helpers.js | 18 +++++++++++++----- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 7c60b69..56f1bf5 100644 --- a/README.md +++ b/README.md @@ -20,4 +20,13 @@ 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 +``` + For more information, refer [React Storybook](https://github.com/kadirahq/react-storybook) documentation. diff --git a/bin/generate.js b/bin/generate.js index cc9e924..aa70842 100755 --- a/bin/generate.js +++ b/bin/generate.js @@ -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; @@ -18,12 +18,19 @@ 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 npmOptions = { + useYarn: Boolean(program.useYarn) +}; + +var runStorybookCommand = program.useYarn? 'yarn run storybook' : 'npm run storybook'; + // Update notify code. updateNotifier({ pkg: pkg, @@ -55,11 +62,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; @@ -69,11 +76,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; @@ -83,11 +90,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; @@ -97,11 +104,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; @@ -111,11 +118,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; @@ -125,11 +132,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; diff --git a/lib/helpers.js b/lib/helpers.js index f827bc1..7e3eb6e 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -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();