BVB Source Codes

storybook Show generate.js Source code

Return Download storybook: download generate.js Source code - Download storybook Source code - Type:.js
  1. #!/usr/bin/env node
  2.  
  3. const updateNotifier = require('update-notifier');
  4. const program = require('commander');
  5. const chalk = require('chalk');
  6. const detect = require('../lib/detect');
  7. const hasYarn = require('../lib/has_yarn');
  8. const types = require('../lib/project_types');
  9. const commandLog = require('../lib/helpers').commandLog;
  10. const codeLog = require('../lib/helpers').codeLog;
  11. const paddedLog = require('../lib/helpers').paddedLog;
  12. const installDeps = require('../lib/helpers').installDeps;
  13. const logger = console;
  14.  
  15. const pkg = require('../package.json');
  16.  
  17. program
  18.   .version(pkg.version)
  19.   .option('-f --force', 'Forcely add storybook')
  20.   .option('-N --use-npm', 'Use npm to install deps')
  21.   .parse(process.argv);
  22.  
  23. const welcomeMessage = 'getstorybook - the simplest way to add a storybook to your project.';
  24. logger.log(chalk.inverse(`\n ${welcomeMessage} \n`));
  25.  
  26. const useYarn = Boolean(program.useNpm !== true) && hasYarn();
  27.  
  28. const npmOptions = {
  29.   useYarn,
  30. };
  31.  
  32. const runStorybookCommand = useYarn ? 'yarn run storybook' : 'npm run storybook';
  33.  
  34. // Update notify code.
  35. updateNotifier({
  36.   pkg,
  37.   updateCheckInterval: 1000 * 60 * 60, // every hour (we could increase this later on.)
  38. }).notify();
  39.  
  40. let projectType;
  41.  
  42. const done = commandLog('Detecting project type');
  43. try {
  44.   projectType = detect({
  45.     force: program.force,
  46.   });
  47. } catch (ex) {
  48.   done(ex.message);
  49.   process.exit(1);
  50. }
  51. done();
  52.  
  53. const end = () => {
  54.   installDeps(npmOptions);
  55.  
  56.   logger.log('\nTo run your storybook, type:\n');
  57.   codeLog([runStorybookCommand]);
  58.   logger.log('\nFor more information visit:', chalk.cyan('https://storybook.js.org'));
  59.  
  60.   // Add a new line for the clear visibility.
  61.   logger.log();
  62. };
  63.  
  64. const CRNA_DISCUSSION =
  65.   'https://github.com/storybooks/storybook/blob/master/app/react-native/docs/manual-setup.md';
  66.  
  67. switch (projectType) {
  68.   case types.ALREADY_HAS_STORYBOOK:
  69.     logger.log();
  70.     paddedLog('There seems to be a storybook already available in this project.');
  71.     paddedLog('Apply following command to force:\n');
  72.     codeLog(['getstorybook -f']);
  73.  
  74.     // Add a new line for the clear visibility.
  75.     logger.log();
  76.     break;
  77.  
  78.   case types.UPDATE_PACKAGE_ORGANIZATIONS:
  79.     require('../generators/UPDATE_PACKAGE_ORGANIZATIONS')
  80.       .then(r => null) // commmandLog doesn't like to see output
  81.       .then(commandLog('Upgrading your project to the new storybook packages.'))
  82.       .then(end);
  83.     break;
  84.  
  85.   case types.REACT_SCRIPTS:
  86.     require('../generators/REACT_SCRIPTS')
  87.       .then(commandLog('Adding storybook support to your "Create React App" based project'))
  88.       .then(end);
  89.     break;
  90.  
  91.   case types.REACT:
  92.     require('../generators/REACT')
  93.       .then(commandLog('Adding storybook support to your "React" app'))
  94.       .then(end);
  95.     break;
  96.  
  97.   case types.REACT_NATIVE_SCRIPTS: {
  98.     const app = chalk.bold('"./App.js"');
  99.     require('../generators/REACT_NATIVE_SCRIPTS')
  100.       .then(commandLog('Adding storybook support to your "Create React Native App" app'))
  101.       .then(end)
  102.       .then(() => {
  103.         logger.log(chalk.red('NOTE: CRNA app installation is not 100% automated.'));
  104.         logger.log(`To quickly run storybook, replace contents of ${app} with:\n`);
  105.         codeLog(["export default from './storybook';"]); // eslint-disable-line
  106.         logger.log('\nFor a more complete discussion of options, see:\n');
  107.         logger.log(chalk.cyan(CRNA_DISCUSSION));
  108.         logger.log();
  109.       });
  110.     break;
  111.   }
  112.  
  113.   case types.REACT_NATIVE:
  114.     require('../generators/REACT_NATIVE')
  115.       .then(commandLog('Adding storybook support to your "React Native" app'))
  116.       .then(end);
  117.     break;
  118.  
  119.   case types.METEOR:
  120.     require('../generators/METEOR')
  121.       .then(commandLog('Adding storybook support to your "Meteor" app'))
  122.       .then(end);
  123.     break;
  124.  
  125.   case types.WEBPACK_REACT:
  126.     require('../generators/WEBPACK_REACT')
  127.       .then(commandLog('Adding storybook support to your "Webpack React" app'))
  128.       .then(end);
  129.     break;
  130.  
  131.   case types.REACT_PROJECT:
  132.     require('../generators/REACT')
  133.       .then(commandLog('Adding storybook support to your "React" library'))
  134.       .then(end);
  135.     break;
  136.  
  137.   default:
  138.     paddedLog(`Unsupported Project type. (code: ${projectType})`);
  139.     paddedLog('Visit https://storybook.js.org for more information.');
  140.  
  141.     // Add a new line for the clear visibility.
  142.     logger.log();
  143. }
  144.  
downloadgenerate.js Source code - Download storybook Source code
Related Source Codes/Software:
ionicons - The premium icon font for Ionic ... 2017-06-07
AsyncDisplayKit - Smooth asynchronous user interfaces for iOS apps. ... 2017-06-07
lottie-android - Render After Effects animations natively on Androi... 2017-06-07
parse-server - Parse-compatible API server module for Node/Expres... 2017-06-07
prettier - Prettier is an opinionated JavaScript formatter. ... 2017-06-08
inferno - An extremely fast, React-like JavaScript library f... 2017-06-08
guetzli - Perceptual JPEG encoder 2017-06-08
cs-video-courses - List of Computer Science courses with video lectur... 2017-06-08
interviews - Everything you need to know to get the job. 2017-06-08
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top