mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-12 18:29:53 -05:00
cli: move titleize to be reusable
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user