BVB Source Codes

storybook Show helpers.js Source code

Return Download storybook: download helpers.js Source code - Download storybook Source code - Type:.js
  1. const path = require('path');
  2. const fs = require('fs');
  3. const chalk = require('chalk');
  4. const logger = console;
  5. const spawnSync = require('cross-spawn').sync;
  6.  
  7. exports.getPackageJson = function getPackageJson() {
  8.   const packageJsonPath = path.resolve('package.json');
  9.   if (!fs.existsSync(packageJsonPath)) {
  10.     return false;
  11.   }
  12.  
  13.   const jsonContent = fs.readFileSync(packageJsonPath, 'utf8');
  14.   return JSON.parse(jsonContent);
  15. };
  16.  
  17. exports.writePackageJson = function writePackageJson(packageJson) {
  18.   const content = `${JSON.stringify(packageJson, null, 2)}\n`;
  19.   const packageJsonPath = path.resolve('package.json');
  20.  
  21.   fs.writeFileSync(packageJsonPath, content, 'utf8');
  22. };
  23.  
  24. exports.commandLog = function commandLog(message) {
  25.   process.stdout.write(chalk.cyan(' 鈥 ') + message);
  26.   const done = function(errorMessage, errorInfo) {
  27.     if (errorMessage) {
  28.       process.stdout.write(`. ${chalk.red('鉁?)}\n`);
  29.      logger.error(`\n     ${chalk.red(errorMessage)}`);
  30.  
  31.      if (!errorInfo) return;
  32.  
  33.      const newErrorInfo = errorInfo.split('\n').map(line => `     ${chalk.dim(line)}`).join('\n');
  34.      logger.error(`${newErrorInfo}\n`);
  35.      return;
  36.    }
  37.  
  38.    process.stdout.write(`. ${chalk.green('?)}\n`);
  39.   };
  40.  
  41.   return done;
  42. };
  43.  
  44. exports.paddedLog = function(message) {
  45.   const newMessage = message.split('\n').map(line => `    ${line}`).join('\n');
  46.  
  47.   logger.log(newMessage);
  48. };
  49.  
  50. exports.getChars = function getChars(char, amount) {
  51.   let line = '';
  52.   for (let lc = 0; lc < amount; lc++) {
  53.     line += char;
  54.   }
  55.  
  56.   return line;
  57. };
  58.  
  59. exports.codeLog = function codeLog(codeLines, leftPadAmount) {
  60.   let maxLength = 0;
  61.   const newLines = codeLines.map(line => {
  62.     maxLength = line.length > maxLength ? line.length : maxLength;
  63.     return line;
  64.   });
  65.  
  66.   const finalResult = newLines
  67.     .map(line => {
  68.       const rightPadAmount = maxLength - line.length;
  69.       let newLine = line + exports.getChars(' ', rightPadAmount);
  70.       newLine = exports.getChars(' ', leftPadAmount || 2) + chalk.inverse(` ${newLine} `);
  71.       return newLine;
  72.     })
  73.     .join('\n');
  74.  
  75.   logger.log(finalResult);
  76. };
  77.  
  78. exports.installDeps = function(options) {
  79.   let done = exports.commandLog('Preparing to install dependencies');
  80.   done();
  81.   console.log();
  82.  
  83.   let result;
  84.   if (options.useYarn) {
  85.     result = spawnSync('yarn', { stdio: 'inherit' });
  86.   } else {
  87.     result = spawnSync('npm', ['install'], { stdio: 'inherit' });
  88.   }
  89.  
  90.   console.log();
  91.   done = exports.commandLog('Installing dependencies');
  92.   if (result.status !== 0) {
  93.     done('An error occurred while installing dependencies.');
  94.     process.exit(1);
  95.   }
  96.   done();
  97. };
  98.  
downloadhelpers.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