mirror of https://github.com/lukechilds/docs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
120 lines
3.4 KiB
120 lines
3.4 KiB
'use strict';
|
|
|
|
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
|
|
|
var _ = require('lodash');
|
|
var R = require('ramda');
|
|
var path = require('path');
|
|
var _isCi = require('is-ci');
|
|
var chalk = require('chalk');
|
|
var _supportsColor = require('supports-color');
|
|
var _isInstalledGlobally = require('is-installed-globally');
|
|
var pkg = require(path.join(__dirname, '..', 'package.json'));
|
|
var logger = require('./logger');
|
|
|
|
var joinWithEq = function joinWithEq(x, y) {
|
|
return x + '=' + y;
|
|
};
|
|
|
|
// converts an object (single level) into
|
|
// key1=value1,key2=value2,...
|
|
var objectToString = function objectToString(obj) {
|
|
return R.zipWith(joinWithEq, R.keys(obj), R.values(obj)).join(',');
|
|
};
|
|
|
|
var normalizeObject = function normalizeObject(env) {
|
|
return _.isPlainObject(env) ? objectToString(env) : env;
|
|
};
|
|
|
|
var normalizeArray = function normalizeArray(arr) {
|
|
return _.isArray(arr) ? arr.join(',') : arr;
|
|
};
|
|
|
|
function normalizeModuleOptions() {
|
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
|
|
return R.evolve({
|
|
env: normalizeObject,
|
|
config: normalizeObject,
|
|
reporterOptions: normalizeObject,
|
|
spec: normalizeArray
|
|
})(options);
|
|
}
|
|
|
|
function stdoutLineMatches(expectedLine, stdout) {
|
|
var lines = stdout.split('\n').map(R.trim);
|
|
var lineMatches = R.equals(expectedLine);
|
|
return lines.some(lineMatches);
|
|
}
|
|
|
|
var util = {
|
|
normalizeModuleOptions: normalizeModuleOptions,
|
|
|
|
isCi: function isCi() {
|
|
return _isCi;
|
|
},
|
|
supportsColor: function supportsColor() {
|
|
// we only care about stderr supporting color
|
|
// since thats what our DEBUG logs use
|
|
return Boolean(_supportsColor.stderr);
|
|
},
|
|
cwd: function cwd() {
|
|
return process.cwd();
|
|
},
|
|
pkgVersion: function pkgVersion() {
|
|
return pkg.version;
|
|
},
|
|
exit: function exit(code) {
|
|
process.exit(code);
|
|
},
|
|
logErrorExit1: function logErrorExit1(err) {
|
|
logger.error(err.message);
|
|
|
|
process.exit(1);
|
|
},
|
|
titleize: function titleize() {
|
|
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
// prepend first arg with space
|
|
// and pad so that all messages line up
|
|
args[0] = _.padEnd(' ' + args[0], 24);
|
|
|
|
// get rid of any falsy values
|
|
args = _.compact(args);
|
|
|
|
return chalk.blue.apply(chalk, _toConsumableArray(args));
|
|
},
|
|
calculateEta: function calculateEta(percent, elapsed) {
|
|
// returns the number of seconds remaining
|
|
|
|
// if we're at 100 already just return 0
|
|
if (percent === 100) {
|
|
return 0;
|
|
}
|
|
|
|
// take the percentage and divide by one
|
|
// and multiple that against elapsed
|
|
// subtracting what's already elapsed
|
|
return elapsed * (1 / (percent / 100)) - elapsed;
|
|
},
|
|
secsRemaining: function secsRemaining(eta) {
|
|
// calculate the seconds reminaing with no decimal places
|
|
return (_.isFinite(eta) ? eta / 1000 : 0).toFixed(0);
|
|
},
|
|
setTaskTitle: function setTaskTitle(task, title, renderer) {
|
|
// only update the renderer title when not running in CI
|
|
if (renderer === 'default') {
|
|
task.title = title;
|
|
}
|
|
},
|
|
isInstalledGlobally: function isInstalledGlobally() {
|
|
return _isInstalledGlobally;
|
|
},
|
|
|
|
|
|
stdoutLineMatches: stdoutLineMatches
|
|
};
|
|
|
|
module.exports = util;
|