From 89632bbbaf0efd46eefc5f11b58fbf1163be9713 Mon Sep 17 00:00:00 2001 From: Brian Mann Date: Sun, 3 Sep 2017 23:40:12 -0400 Subject: [PATCH] cli: move titleize to be reusable --- cli/index.js | 2 +- cli/lib/tasks/install.js | 21 +++++---------------- cli/lib/util.js | 12 ++++++++++++ 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/cli/index.js b/cli/index.js index 3d9da7857a..e79eb8112e 100644 --- a/cli/index.js +++ b/cli/index.js @@ -18,7 +18,7 @@ switch (args.exec) { debug('verifying Cypress') require('./lib/tasks/verify') - .verify({ force: args.force }) // always force verification + .verify({ force: true }) // always force verification .catch(util.logErrorExit1) break diff --git a/cli/lib/tasks/install.js b/cli/lib/tasks/install.js index 8ababe0519..e2cc32b3a4 100644 --- a/cli/lib/tasks/install.js +++ b/cli/lib/tasks/install.js @@ -69,17 +69,6 @@ const downloadAndUnzip = (version) => { logger.log(chalk.yellow(`Installing Cypress ${chalk.gray(`(version: ${version})`)}`)) logger.log() - const titleize = (...args) => { - // 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(...args) - } - const progessify = (title, task) => { // return higher order function return (percentComplete, remaining) => { @@ -88,13 +77,13 @@ const downloadAndUnzip = (version) => { // pluralize seconds remaining remaining = chalk.gray(`${remaining}s`) - task.title = titleize(title, percentComplete, remaining) + task.title = util.titleize(title, percentComplete, remaining) } } const tasks = new Listr([ { - title: titleize('Downloading Cypress'), + title: util.titleize('Downloading Cypress'), task: (ctx, task) => { // as our download progresses indicate the status options.onProgress = progessify('Downloading Cypress', task) @@ -107,7 +96,7 @@ const downloadAndUnzip = (version) => { }, }, { - title: titleize('Unzipping Cypress'), + title: util.titleize('Unzipping Cypress'), task: (ctx, task) => { // as our unzip progresses indicate the status options.downloadDestination = ctx.downloadDestination @@ -117,7 +106,7 @@ const downloadAndUnzip = (version) => { }, }, { - title: titleize('Finishing Installation'), + title: util.titleize('Finishing Installation'), task: (ctx, task) => { const { downloadDestination } = options @@ -127,7 +116,7 @@ const downloadAndUnzip = (version) => { .then(() => { const dir = info.getPathToUserExecutableDir() - task.title = titleize('Finishing Installation', chalk.gray(dir)) + task.title = util.titleize('Finishing Installation', chalk.gray(dir)) return info.writeInstalledVersion(version) }) diff --git a/cli/lib/util.js b/cli/lib/util.js index 8c826c88d5..f34141d2e3 100644 --- a/cli/lib/util.js +++ b/cli/lib/util.js @@ -1,5 +1,6 @@ const _ = require('lodash') const path = require('path') +const chalk = require('chalk') const isInstalledGlobally = require('is-installed-globally') const pkg = require(path.join(__dirname, '..', '..', 'package.json')) const logger = require('./logger') @@ -27,6 +28,17 @@ module.exports = { process.exit(1) }, + titleize (...args) { + // 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(...args) + }, + calculateEta (percent, elapsed) { // returns the number of seconds remaining