UNPKG

feds-cli

Version:

CLI for Front-end Dev Stack

80 lines (68 loc) 1.85 kB
const CPU_COUNT = require('os').cpus().length const HappyPack = require('happypack') const notifier = require('node-notifier') const chalk = require('chalk') const humanizeString = require('humanize-string') // This determines how many threads a HappyPack instance can spin up. // See the plugins section of the webpack configuration for more. const happyPackThreadPool = HappyPack.ThreadPool({ // eslint-disable-line new-cap size: CPU_COUNT >= 4 ? Math.round(CPU_COUNT / 2) : 2 }) // Generates a HappyPack plugin. // @see https://github.com/amireh/happypack/ function happyPackPlugin ({name, loaders}) { return new HappyPack({ id: name, verbose: false, threadPool: happyPackThreadPool, loaders }) } // :: [Any] -> [Any] function removeEmpty (x) { return x.filter(y => !!y) } // :: bool -> (Any, Any) -> Any function ifElse (condition) { return (then, or) => (condition ? then : or) } // :: ...Object -> Object function merge () { const funcArgs = Array.prototype.slice.call(arguments) // eslint-disable-line prefer-rest-params return Object.assign.apply( null, removeEmpty([{}].concat(funcArgs)) ) } function createNotification (options = {}) { const title = options.title ? `${chalk.inverse.bold(` ${humanizeString(options.title).toUpperCase()} `)}` : undefined notifier.notify({ title, message: options.message, open: options.open }) const level = options.level || 'info' const msg = `${chalk.bold('==>')} ${title} -> ${options.message}` switch (level) { case 'warn': console.log(chalk.red(msg)) break case 'error': console.log(chalk.bgRed.white(msg)) break case 'info': default: console.log(chalk.green(msg)) } } module.exports = { removeEmpty, ifElse, merge, happyPackPlugin, createNotification }