diff --git a/lib/cli/bin/generate.js b/lib/cli/bin/generate.js index 7040af903a21..f8596afa8d9f 100644 --- a/lib/cli/bin/generate.js +++ b/lib/cli/bin/generate.js @@ -12,39 +12,38 @@ if (process.argv[1].includes('getstorybook')) { logger.log(chalk.yellow('The official command to install Storybook from now on is:\n')); codeLog(['storybook init']); logger.log(); - initiate({}, pkg); - process.exit(0); -} - -program - .command('init') - .description('Initialize Storybook into your project.') - .option('-f --force', 'Forcely add storybook') - .option('-s --skip-install', 'Skip installing deps') - .option('-N --use-npm', 'Use npm to install deps') - .option('-p --parser ', 'jscodeshift parser') - .option('-h --html', 'Add storybook for HTML') - .action(options => initiate(options, pkg)); - -program - .command('start') - .description('Start the local Storybook server') - .option('-N --use-npm', 'Use NPM to start the Storybook server') - .action(options => yarnSpawnSync(options, ['run', 'storybook'])); - -program - .command('build') - .description('Build the Storybook static application') - .option('-N --use-npm', 'Use NPM to build the Storybook server') - .action(options => yarnSpawnSync(options, ['build', 'storybook'])); - -program.command('*', { noHelp: true }).action(cmd => { - logger.error('Invalid command: %s.\nSee --help for a list of available commands.', cmd); - process.exit(1); -}); - -program.version(pkg.version).parse(process.argv); - -if (!program.args.length) { - program.help(); + initiate({}, pkg).then(() => process.exit(0)); +} else { + program + .command('init') + .description('Initialize Storybook into your project.') + .option('-f --force', 'Forcely add storybook') + .option('-s --skip-install', 'Skip installing deps') + .option('-N --use-npm', 'Use npm to install deps') + .option('-p --parser ', 'jscodeshift parser') + .option('-h --html', 'Add storybook for HTML') + .action(options => initiate(options, pkg)); + + program + .command('start') + .description('Start the local Storybook server') + .option('-N --use-npm', 'Use NPM to start the Storybook server') + .action(options => yarnSpawnSync(options, ['run', 'storybook'])); + + program + .command('build') + .description('Build the Storybook static application') + .option('-N --use-npm', 'Use NPM to build the Storybook server') + .action(options => yarnSpawnSync(options, ['build', 'storybook'])); + + program.command('*', { noHelp: true }).action(cmd => { + logger.error('Invalid command: %s.\nSee --help for a list of available commands.', cmd); + process.exit(1); + }); + + program.version(pkg.version).parse(process.argv); + + if (!program.args.length) { + program.help(); + } } diff --git a/lib/cli/lib/initiate.js b/lib/cli/lib/initiate.js index 5f019c21a96f..136a599e8646 100644 --- a/lib/cli/lib/initiate.js +++ b/lib/cli/lib/initiate.js @@ -185,7 +185,7 @@ export default function(options, pkg) { } }; - runGenerator().catch(ex => { + return runGenerator().catch(ex => { logger.error(`\n ${chalk.red(ex.stack)}`); process.exit(1); });