From 6c86472f5757ab9bdf01137c70a589b8fd5241db Mon Sep 17 00:00:00 2001 From: Jarmo Isotalo Date: Wed, 17 May 2017 12:30:40 -0700 Subject: [PATCH] Try to make sure prettier doesn't make us waste time again (#551) * Try running prettier, if it modifies the code fail * Prettify --- .travis.yml | 5 ++- bin/domains/buy.js | 12 +++-- bin/now-alias.js | 28 +++++++++--- bin/now-billing-add.js | 24 ++++++---- bin/now-billing.js | 12 +++-- bin/now-certs.js | 53 ++++++++++++++++------ bin/now-dns.js | 33 ++++++++++---- bin/now-open.js | 8 +++- bin/now-remove.js | 18 +++++--- bin/now-scale.js | 12 +++-- bin/now-secrets.js | 41 ++++++++++++----- bin/now-upgrade.js | 12 +++-- bin/teams/add.js | 8 +++- lib/alias.js | 100 ++++++++++++++++++++++++++++++----------- lib/domains.js | 4 +- lib/login.js | 8 +++- lib/re-alias.js | 12 +++-- lib/scale-info.js | 4 +- lib/scale.js | 4 +- 19 files changed, 290 insertions(+), 108 deletions(-) diff --git a/.travis.yml b/.travis.yml index 71ec69c..56ff6cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,12 @@ { "language": "node_js", "node_js": [ - "6", "node" ], + "script": [ + "npm run test", + "./node_modules/.bin/prettier --single-quote --no-semi --write `find ./lib -name '*.js'` `find ./bin -name '*.js'` ; echo 'checking if prettier changed something' ; git diff-index --name-only HEAD ; git diff-index --quiet HEAD && echo 'ok' || (echo 'pretier modified contents, please run prettier locally and add changes. exitting...' && exit 1)" + ], "before_deploy": "npm run pack", "deploy": { "provider": "releases", diff --git a/bin/domains/buy.js b/bin/domains/buy.js index 799fc6d..69009d4 100644 --- a/bin/domains/buy.js +++ b/bin/domains/buy.js @@ -30,11 +30,15 @@ module.exports = async function({ domains, args, currentTeam, user }) { stopSpinner() if (!available) { - return error(`The domain ${nameParam} is ${italic('unavailable')}! ${elapsed()}`) + return error( + `The domain ${nameParam} is ${italic('unavailable')}! ${elapsed()}` + ) } info(`The domain ${nameParam} is ${italic('available')}! ${elapsed()}`) - const confirmation = await promptBool(`Buy now for ${bold(`$${price}`)} (${bold((currentTeam && currentTeam.slug) || user.username || user.email)})?`) + const confirmation = await promptBool( + `Buy now for ${bold(`$${price}`)} (${bold((currentTeam && currentTeam.slug) || user.username || user.email)})?` + ) eraseLines(1) if (!confirmation) { @@ -54,5 +58,7 @@ module.exports = async function({ domains, args, currentTeam, user }) { stopSpinner() success(`Domain purchased and created ${uid(domain.uid)} ${elapsed()}`) - info(`You may now use your domain as an alias to your deployments. Run ${cmd('now alias help')}`) + info( + `You may now use your domain as an alias to your deployments. Run ${cmd('now alias help')}` + ) } diff --git a/bin/now-alias.js b/bin/now-alias.js index 5595f14..21b64cc 100755 --- a/bin/now-alias.js +++ b/bin/now-alias.js @@ -181,7 +181,9 @@ async function run({ token, config: { currentTeam, user } }) { } break } else if (args.length !== 0) { - error(`Invalid number of arguments. Usage: ${chalk.cyan('`now alias ls`')}`) + error( + `Invalid number of arguments. Usage: ${chalk.cyan('`now alias ls`')}` + ) return exit(1) } @@ -203,7 +205,9 @@ async function run({ token, config: { currentTeam, user } }) { return Math.max(acc, (i.alias && i.alias.length) || 0) }, 0) + 8 const elapsed_ = ms(new Date() - start_) - console.log(`> ${aliases.length} alias${aliases.length === 1 ? '' : 'es'} found ${chalk.gray(`[${elapsed_}]`)} under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`) + console.log( + `> ${aliases.length} alias${aliases.length === 1 ? '' : 'es'} found ${chalk.gray(`[${elapsed_}]`)} under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}` + ) console.log() if (supportsColor) { @@ -248,7 +252,9 @@ async function run({ token, config: { currentTeam, user } }) { urlSpec += grayWidth } } else if (_alias.rules) { - _sourceUrl = chalk.gray(`[${_alias.rules.length} custom rule${_alias.rules.length > 1 ? 's' : ''}]`) + _sourceUrl = chalk.gray( + `[${_alias.rules.length} custom rule${_alias.rules.length > 1 ? 's' : ''}]` + ) if (supportsColor) { urlSpec += underlineWidth } @@ -278,7 +284,9 @@ async function run({ token, config: { currentTeam, user } }) { } if (args.length !== 1) { - error(`Invalid number of arguments. Usage: ${chalk.cyan('`now alias rm `')}`) + error( + `Invalid number of arguments. Usage: ${chalk.cyan('`now alias rm `')}` + ) return exit(1) } @@ -303,7 +311,9 @@ async function run({ token, config: { currentTeam, user } }) { const start = new Date() await alias.rm(_alias) const elapsed = ms(new Date() - start) - console.log(`${chalk.cyan('> Success!')} Alias ${chalk.bold(_alias.uid)} removed [${elapsed}]`) + console.log( + `${chalk.cyan('> Success!')} Alias ${chalk.bold(_alias.uid)} removed [${elapsed}]` + ) } catch (err) { error(err) exit(1) @@ -318,7 +328,9 @@ async function run({ token, config: { currentTeam, user } }) { break } if (args.length !== 2) { - error(`Invalid number of arguments. Usage: ${chalk.cyan('`now alias set `')}`) + error( + `Invalid number of arguments. Usage: ${chalk.cyan('`now alias set `')}` + ) return exit(1) } await alias.set( @@ -461,6 +473,8 @@ async function updatePathAlias(alias, aliasName, rules, domains) { err.userError = true throw err } else { - console.log(`${chalk.cyan('> Success!')} ${res.ruleCount} rules configured for ${chalk.underline(res.alias)} [${elapsed}]`) + console.log( + `${chalk.cyan('> Success!')} ${res.ruleCount} rules configured for ${chalk.underline(res.alias)} [${elapsed}]` + ) } } diff --git a/bin/now-billing-add.js b/bin/now-billing-add.js index 65c4d42..554559e 100644 --- a/bin/now-billing-add.js +++ b/bin/now-billing-add.js @@ -137,11 +137,13 @@ module.exports = function({ creditCards, currentTeam, user }) { } brand = chalk.cyan(`[${brand}]`) const masked = chalk.gray('#### '.repeat(3)) + result.split(' ')[3] - process.stdout - .write(`${chalk.cyan(tick)} ${piece.label}${masked} ${brand}\n`) + process.stdout.write( + `${chalk.cyan(tick)} ${piece.label}${masked} ${brand}\n` + ) } else if (key === 'ccv') { - process.stdout - .write(`${chalk.cyan(tick)} ${piece.label}${'*'.repeat(result.length)}\n`) + process.stdout.write( + `${chalk.cyan(tick)} ${piece.label}${'*'.repeat(result.length)}\n` + ) } else if (key === 'expDate') { let text = result.split(' / ') text = text[0] + chalk.gray(' / ') + text[1] @@ -159,11 +161,13 @@ module.exports = function({ creditCards, currentTeam, user }) { state.city.initialValue = addressInfo.city } stopSpinner() - process.stdout - .write(`${chalk.cyan(tick)} ${piece.label}${result}\n`) + process.stdout.write( + `${chalk.cyan(tick)} ${piece.label}${result}\n` + ) } else { - process.stdout - .write(`${chalk.cyan(tick)} ${piece.label}${result}\n`) + process.stdout.write( + `${chalk.cyan(tick)} ${piece.label}${result}\n` + ) } } catch (err) { if (err.message === 'USER_ABORT') { @@ -190,7 +194,9 @@ module.exports = function({ creditCards, currentTeam, user }) { address1: state.address1.value }) stopSpinner() - success(`${state.cardNumber.brand} ending in ${res.last4} was added to ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`) + success( + `${state.cardNumber.brand} ending in ${res.last4} was added to ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}` + ) } catch (err) { stopSpinner() const linesToClear = state.error ? 13 : 12 diff --git a/bin/now-billing.js b/bin/now-billing.js index 942d9dc..13b3c43 100644 --- a/bin/now-billing.js +++ b/bin/now-billing.js @@ -182,7 +182,9 @@ async function run({ token, config: { currentTeam, user } }) { .join('\n\n') const elapsed = ms(new Date() - start) - console.log(`> ${cards.cards.length} card${cards.cards.length === 1 ? '' : 's'} found under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)} ${chalk.gray(`[${elapsed}]`)}`) + console.log( + `> ${cards.cards.length} card${cards.cards.length === 1 ? '' : 's'} found under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)} ${chalk.gray(`[${elapsed}]`)}` + ) if (text) { console.log(`\n${text}\n`) } @@ -242,7 +244,9 @@ async function run({ token, config: { currentTeam, user } }) { const card = cards.cards.find(card => card.id === cardId) const elapsed = ms(new Date() - start) - success(`${card.brand} ending in ${card.last4} is now the default ${chalk.gray(`[${elapsed}]`)}`) + success( + `${card.brand} ending in ${card.last4} is now the default ${chalk.gray(`[${elapsed}]`)}` + ) } else { console.log('No changes made') } @@ -267,7 +271,9 @@ async function run({ token, config: { currentTeam, user } }) { } if (cards.cards.length === 0) { - error(`You have no credit cards to choose from to delete under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`) + error( + `You have no credit cards to choose from to delete under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}` + ) return exit(0) } diff --git a/bin/now-certs.js b/bin/now-certs.js index 4c04992..0fdd962 100755 --- a/bin/now-certs.js +++ b/bin/now-certs.js @@ -114,14 +114,18 @@ async function run({ token, config: { currentTeam, user } }) { if (subcommand === 'ls' || subcommand === 'list') { if (args.length !== 0) { - error(`Invalid number of arguments. Usage: ${chalk.cyan('`now certs ls`')}`) + error( + `Invalid number of arguments. Usage: ${chalk.cyan('`now certs ls`')}` + ) return exit(1) } const list = await certs.ls() const elapsed = ms(new Date() - start) - console.log(`> ${list.length} certificate${list.length === 1 ? '' : 's'} found ${chalk.gray(`[${elapsed}]`)} under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`) + console.log( + `> ${list.length} certificate${list.length === 1 ? '' : 's'} found ${chalk.gray(`[${elapsed}]`)} under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}` + ) if (list.length > 0) { const cur = Date.now() @@ -162,7 +166,9 @@ async function run({ token, config: { currentTeam, user } }) { } } else if (subcommand === 'create') { if (args.length !== 1) { - error(`Invalid number of arguments. Usage: ${chalk.cyan('`now certs create `')}`) + error( + `Invalid number of arguments. Usage: ${chalk.cyan('`now certs create `')}` + ) return exit(1) } const cn = args[0] @@ -171,7 +177,9 @@ async function run({ token, config: { currentTeam, user } }) { if (argv.crt || argv.key || argv.ca) { // Issue a custom certificate if (!argv.crt || !argv.key) { - error(`Missing required arguments for a custom certificate entry. Usage: ${chalk.cyan('`now certs create --crt DOMAIN.CRT --key DOMAIN.KEY [--ca CA.CRT] `')}`) + error( + `Missing required arguments for a custom certificate entry. Usage: ${chalk.cyan('`now certs create --crt DOMAIN.CRT --key DOMAIN.KEY [--ca CA.CRT] `')}` + ) return exit(1) } @@ -189,10 +197,14 @@ async function run({ token, config: { currentTeam, user } }) { return exit(1) } const elapsed = ms(new Date() - start) - console.log(`${chalk.cyan('> Success!')} Certificate entry ${chalk.bold(cn)} ${chalk.gray(`(${cert.uid})`)} created ${chalk.gray(`[${elapsed}]`)}`) + console.log( + `${chalk.cyan('> Success!')} Certificate entry ${chalk.bold(cn)} ${chalk.gray(`(${cert.uid})`)} created ${chalk.gray(`[${elapsed}]`)}` + ) } else if (subcommand === 'renew') { if (args.length !== 1) { - error(`Invalid number of arguments. Usage: ${chalk.cyan('`now certs renew `')}`) + error( + `Invalid number of arguments. Usage: ${chalk.cyan('`now certs renew `')}` + ) return exit(1) } @@ -212,10 +224,14 @@ async function run({ token, config: { currentTeam, user } }) { await certs.renew(cert.cn) const elapsed = ms(new Date() - start) - console.log(`${chalk.cyan('> Success!')} Certificate ${chalk.bold(cert.cn)} ${chalk.gray(`(${cert.uid})`)} renewed ${chalk.gray(`[${elapsed}]`)}`) + console.log( + `${chalk.cyan('> Success!')} Certificate ${chalk.bold(cert.cn)} ${chalk.gray(`(${cert.uid})`)} renewed ${chalk.gray(`[${elapsed}]`)}` + ) } else if (subcommand === 'replace') { if (!argv.crt || !argv.key) { - error(`Invalid number of arguments. Usage: ${chalk.cyan('`now certs replace --crt DOMAIN.CRT --key DOMAIN.KEY [--ca CA.CRT] `')}`) + error( + `Invalid number of arguments. Usage: ${chalk.cyan('`now certs replace --crt DOMAIN.CRT --key DOMAIN.KEY [--ca CA.CRT] `')}` + ) return exit(1) } @@ -238,10 +254,14 @@ async function run({ token, config: { currentTeam, user } }) { await certs.put(cert.cn, crt, key, ca) const elapsed = ms(new Date() - start) - console.log(`${chalk.cyan('> Success!')} Certificate ${chalk.bold(cert.cn)} ${chalk.gray(`(${cert.uid})`)} replaced ${chalk.gray(`[${elapsed}]`)}`) + console.log( + `${chalk.cyan('> Success!')} Certificate ${chalk.bold(cert.cn)} ${chalk.gray(`(${cert.uid})`)} replaced ${chalk.gray(`[${elapsed}]`)}` + ) } else if (subcommand === 'rm' || subcommand === 'remove') { if (args.length !== 1) { - error(`Invalid number of arguments. Usage: ${chalk.cyan('`now certs rm `')}`) + error( + `Invalid number of arguments. Usage: ${chalk.cyan('`now certs rm `')}` + ) return exit(1) } @@ -260,7 +280,9 @@ async function run({ token, config: { currentTeam, user } }) { await certs.delete(cert.cn) const elapsed = ms(new Date() - start) - console.log(`${chalk.cyan('> Success!')} Certificate ${chalk.bold(cert.cn)} ${chalk.gray(`(${cert.uid})`)} removed ${chalk.gray(`[${elapsed}]`)}`) + console.log( + `${chalk.cyan('> Success!')} Certificate ${chalk.bold(cert.cn)} ${chalk.gray(`(${cert.uid})`)} removed ${chalk.gray(`[${elapsed}]`)}` + ) } else { error( 'Please specify a valid subcommand: ls | create | renew | replace | rm' @@ -287,8 +309,9 @@ function readConfirmation(cert, msg) { process.stdout.write(`> ${msg}`) process.stdout.write(' ' + tbl + '\n') - process.stdout - .write(`${chalk.bold.red('> Are you sure?')} ${chalk.gray('[y/N] ')}`) + process.stdout.write( + `${chalk.bold.red('> Are you sure?')} ${chalk.gray('[y/N] ')}` + ) process.stdin .on('data', d => { @@ -310,7 +333,9 @@ async function getCertIdCn(certs, idOrCn, currentTeam, user) { })[0] if (!thecert) { - error(`No certificate found by id or cn "${idOrCn}" under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`) + error( + `No certificate found by id or cn "${idOrCn}" under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}` + ) return null } diff --git a/bin/now-dns.js b/bin/now-dns.js index 05417fa..e49d9aa 100755 --- a/bin/now-dns.js +++ b/bin/now-dns.js @@ -101,7 +101,9 @@ async function run({ token, config: { currentTeam, user } }) { if (subcommand === 'ls' || subcommand === 'list') { if (args.length > 1) { - error(`Invalid number of arguments. Usage: ${chalk.cyan('`now dns ls [domain]`')}`) + error( + `Invalid number of arguments. Usage: ${chalk.cyan('`now dns ls [domain]`')}` + ) return exit(1) } @@ -149,20 +151,28 @@ async function run({ token, config: { currentTeam, user } }) { text.push(`\n\n${chalk.bold(domain)}\n${indent(out, 2)}`) } }) - console.log(`> ${count} record${count === 1 ? '' : 's'} found ${chalk.gray(`[${elapsed}]`)} under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`) + console.log( + `> ${count} record${count === 1 ? '' : 's'} found ${chalk.gray(`[${elapsed}]`)} under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}` + ) console.log(text.join('')) } else if (subcommand === 'add') { const param = parseAddArgs(args) if (!param) { - error(`Invalid number of arguments. See: ${chalk.cyan('`now dns --help`')} for usage.`) + error( + `Invalid number of arguments. See: ${chalk.cyan('`now dns --help`')} for usage.` + ) return exit(1) } const record = await domainRecords.create(param.domain, param.data) const elapsed = ms(new Date() - start) - console.log(`${chalk.cyan('> Success!')} A new DNS record for domain ${chalk.bold(param.domain)} ${chalk.gray(`(${record.uid})`)} created ${chalk.gray(`[${elapsed}]`)} (${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)})`) + console.log( + `${chalk.cyan('> Success!')} A new DNS record for domain ${chalk.bold(param.domain)} ${chalk.gray(`(${record.uid})`)} created ${chalk.gray(`[${elapsed}]`)} (${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)})` + ) } else if (subcommand === 'rm' || subcommand === 'remove') { if (args.length !== 1) { - error(`Invalid number of arguments. Usage: ${chalk.cyan('`now dns rm `')}`) + error( + `Invalid number of arguments. Usage: ${chalk.cyan('`now dns rm `')}` + ) return exit(1) } @@ -183,7 +193,9 @@ async function run({ token, config: { currentTeam, user } }) { await domainRecords.delete(record.domain, record.id) const elapsed = ms(new Date() - start) - console.log(`${chalk.cyan('> Success!')} Record ${chalk.gray(`${record.id}`)} removed ${chalk.gray(`[${elapsed}]`)}`) + console.log( + `${chalk.cyan('> Success!')} Record ${chalk.gray(`${record.id}`)} removed ${chalk.gray(`[${elapsed}]`)}` + ) } else { error('Please specify a valid subcommand: ls | add | rm') help() @@ -268,7 +280,9 @@ function readConfirmation(record, msg) { [ [ record.id, - chalk.bold(`${record.name.length > 0 ? record.name + '.' : ''}${record.domain} ${record.type} ${record.value} ${record.mxPriority ? record.mxPriority : ''}`), + chalk.bold( + `${record.name.length > 0 ? record.name + '.' : ''}${record.domain} ${record.type} ${record.value} ${record.mxPriority ? record.mxPriority : ''}` + ), time ] ], @@ -278,8 +292,9 @@ function readConfirmation(record, msg) { process.stdout.write(`> ${msg}`) process.stdout.write(' ' + tbl + '\n') - process.stdout - .write(`${chalk.bold.red('> Are you sure?')} ${chalk.gray('[y/N] ')}`) + process.stdout.write( + `${chalk.bold.red('> Are you sure?')} ${chalk.gray('[y/N] ')}` + ) process.stdin .on('data', d => { diff --git a/bin/now-open.js b/bin/now-open.js index 18ca860..d31b0b9 100644 --- a/bin/now-open.js +++ b/bin/now-open.js @@ -112,7 +112,9 @@ async function open({ token, config: { currentTeam, user } }) { ) if (typeof currentProjectDeployments === 'undefined') { - console.log(`No deployments found for ${chalk.bold(pkg.name)} under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`) + console.log( + `No deployments found for ${chalk.bold(pkg.name)} under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}` + ) process.exit(0) } @@ -122,7 +124,9 @@ async function open({ token, config: { currentTeam, user } }) { try { const url = `https://${latestDeploy.url}` - console.log(`Opening the latest deployment for ${chalk.bold(pkg.name)}... under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`) + console.log( + `Opening the latest deployment for ${chalk.bold(pkg.name)}... under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}` + ) console.log(`Here's the URL: ${chalk.underline(url)}`) opn(url) diff --git a/bin/now-remove.js b/bin/now-remove.js index 2976d21..bb180fc 100755 --- a/bin/now-remove.js +++ b/bin/now-remove.js @@ -95,8 +95,9 @@ Promise.resolve().then(async () => { function readConfirmation(matches) { return new Promise(resolve => { - process.stdout - .write(`> The following deployment${matches.length === 1 ? '' : 's'} will be removed permanently:\n`) + process.stdout.write( + `> The following deployment${matches.length === 1 ? '' : 's'} will be removed permanently:\n` + ) const tbl = table( matches.map(depl => { @@ -117,8 +118,9 @@ function readConfirmation(matches) { } } - process.stdout - .write(`${chalk.bold.red('> Are you sure?')} ${chalk.gray('[y/N] ')}`) + process.stdout.write( + `${chalk.bold.red('> Are you sure?')} ${chalk.gray('[y/N] ')}` + ) process.stdin .on('data', d => { @@ -141,9 +143,11 @@ async function remove({ token, config: { currentTeam } }) { }) if (matches.length === 0) { - error(`Could not find any deployments matching ${ids - .map(id => chalk.bold(`"${id}"`)) - .join(', ')}. Run ${chalk.dim(`\`now ls\``)} to list.`) + error( + `Could not find any deployments matching ${ids + .map(id => chalk.bold(`"${id}"`)) + .join(', ')}. Run ${chalk.dim(`\`now ls\``)} to list.` + ) return process.exit(1) } diff --git a/bin/now-scale.js b/bin/now-scale.js index ec4c4c2..115f5f6 100755 --- a/bin/now-scale.js +++ b/bin/now-scale.js @@ -199,7 +199,9 @@ async function run({ token, config: { currentTeam } }) { } if ((match.state === 'FROZEN' || match.scale.current === 0) && min > 0) { - console.log(`> Deployment is currently in 0 replicas, preparing deployment for scaling...`) + console.log( + `> Deployment is currently in 0 replicas, preparing deployment for scaling...` + ) if (match.scale.max < 1) { await scale.setScale(match.uid, { min: 0, max: 1 }) } @@ -217,7 +219,9 @@ async function run({ token, config: { currentTeam } }) { const log = console.log log(`> ${chalk.cyan('Success!')} Configured scaling rules [${elapsed}]`) log() - log(`${chalk.bold(match.url)} (${chalk.gray(currentReplicas)} ${chalk.gray('current')})`) + log( + `${chalk.bold(match.url)} (${chalk.gray(currentReplicas)} ${chalk.gray('current')})` + ) log(printf('%6s %s', 'min', chalk.bold(newMin))) log(printf('%6s %s', 'max', chalk.bold(newMax))) log(printf('%6s %s', 'auto', chalk.bold(newMin === newMax ? '✖' : '✔'))) @@ -256,7 +260,9 @@ async function list(scale) { for (const app of sorted) { const depls = argv.all ? app[1] : app[1].slice(0, 5) - console.log(`${chalk.bold(app[0])} ${chalk.gray('(' + depls.length + ' of ' + app[1].length + ' total)')}`) + console.log( + `${chalk.bold(app[0])} ${chalk.gray('(' + depls.length + ' of ' + app[1].length + ' total)')}` + ) console.log() const urlSpec = `%-${urlLength}s` console.log( diff --git a/bin/now-secrets.js b/bin/now-secrets.js index 140dd11..08ad50d 100755 --- a/bin/now-secrets.js +++ b/bin/now-secrets.js @@ -111,14 +111,18 @@ async function run({ token, config: { currentTeam, user } }) { if (subcommand === 'ls' || subcommand === 'list') { if (args.length !== 0) { - error(`Invalid number of arguments. Usage: ${chalk.cyan('`now secret ls`')}`) + error( + `Invalid number of arguments. Usage: ${chalk.cyan('`now secret ls`')}` + ) return exit(1) } const list = await secrets.ls() const elapsed = ms(new Date() - start) - console.log(`> ${list.length} secret${list.length === 1 ? '' : 's'} found under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)} ${chalk.gray(`[${elapsed}]`)}`) + console.log( + `> ${list.length} secret${list.length === 1 ? '' : 's'} found under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)} ${chalk.gray(`[${elapsed}]`)}` + ) if (list.length > 0) { const cur = Date.now() @@ -150,7 +154,9 @@ async function run({ token, config: { currentTeam, user } }) { if (subcommand === 'rm' || subcommand === 'remove') { if (args.length !== 1) { - error(`Invalid number of arguments. Usage: ${chalk.cyan('`now secret rm `')}`) + error( + `Invalid number of arguments. Usage: ${chalk.cyan('`now secret rm `')}` + ) return exit(1) } const list = await secrets.ls() @@ -171,28 +177,38 @@ async function run({ token, config: { currentTeam, user } }) { const secret = await secrets.rm(args[0]) const elapsed = ms(new Date() - start) - console.log(`${chalk.cyan('> Success!')} Secret ${chalk.bold(secret.name)} ${chalk.gray(`(${secret.uid})`)} removed ${chalk.gray(`[${elapsed}]`)}`) + console.log( + `${chalk.cyan('> Success!')} Secret ${chalk.bold(secret.name)} ${chalk.gray(`(${secret.uid})`)} removed ${chalk.gray(`[${elapsed}]`)}` + ) return secrets.close() } if (subcommand === 'rename') { if (args.length !== 2) { - error(`Invalid number of arguments. Usage: ${chalk.cyan('`now secret rename `')}`) + error( + `Invalid number of arguments. Usage: ${chalk.cyan('`now secret rename `')}` + ) return exit(1) } const secret = await secrets.rename(args[0], args[1]) const elapsed = ms(new Date() - start) - console.log(`${chalk.cyan('> Success!')} Secret ${chalk.bold(secret.oldName)} ${chalk.gray(`(${secret.uid})`)} renamed to ${chalk.bold(args[1])} ${chalk.gray(`[${elapsed}]`)}`) + console.log( + `${chalk.cyan('> Success!')} Secret ${chalk.bold(secret.oldName)} ${chalk.gray(`(${secret.uid})`)} renamed to ${chalk.bold(args[1])} ${chalk.gray(`[${elapsed}]`)}` + ) return secrets.close() } if (subcommand === 'add' || subcommand === 'set') { if (args.length !== 2) { - error(`Invalid number of arguments. Usage: ${chalk.cyan('`now secret add `')}`) + error( + `Invalid number of arguments. Usage: ${chalk.cyan('`now secret add `')}` + ) if (args.length > 2) { const example = chalk.cyan(`$ now secret add ${args[0]}`) - console.log(`> If your secret has spaces, make sure to wrap it in quotes. Example: \n ${example} `) + console.log( + `> If your secret has spaces, make sure to wrap it in quotes. Example: \n ${example} ` + ) } return exit(1) @@ -210,7 +226,9 @@ async function run({ token, config: { currentTeam, user } }) { const secret = await secrets.add(name, value) const elapsed = ms(new Date() - start) - console.log(`${chalk.cyan('> Success!')} Secret ${chalk.bold(name.toLowerCase())} ${chalk.gray(`(${secret.uid})`)} added (${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}) ${chalk.gray(`[${elapsed}]`)}`) + console.log( + `${chalk.cyan('> Success!')} Secret ${chalk.bold(name.toLowerCase())} ${chalk.gray(`(${secret.uid})`)} added (${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}) ${chalk.gray(`[${elapsed}]`)}` + ) return secrets.close() } @@ -235,8 +253,9 @@ function readConfirmation(secret) { process.stdout.write('> The following secret will be removed permanently\n') process.stdout.write(' ' + tbl + '\n') - process.stdout - .write(`${chalk.bold.red('> Are you sure?')} ${chalk.gray('[y/N] ')}`) + process.stdout.write( + `${chalk.bold.red('> Are you sure?')} ${chalk.gray('[y/N] ')}` + ) process.stdin .on('data', d => { diff --git a/bin/now-upgrade.js b/bin/now-upgrade.js index 1c8d5f7..b4f05b7 100644 --- a/bin/now-upgrade.js +++ b/bin/now-upgrade.js @@ -211,7 +211,9 @@ async function run({ token, config: { currentTeam, user } }) { newPlan = await plans.set(planId) } catch (err) { if (err.code === 'customer_not_found' || err.code === 'source_not_found') { - error(`You have no payment methods available. Run ${cmd('now billing add')} to add one`) + error( + `You have no payment methods available. Run ${cmd('now billing add')} to add one` + ) } else { error(`An unknow error occured. Please try again later ${err.message}`) } @@ -220,9 +222,13 @@ async function run({ token, config: { currentTeam, user } }) { } if (currentPlan.until && newPlan.id !== 'oss') { - success(`The cancelation has been undone. You're back on the ${chalk.bold(`${newPlan.name} plan`)}`) + success( + `The cancelation has been undone. You're back on the ${chalk.bold(`${newPlan.name} plan`)}` + ) } else if (newPlan.until) { - success(`Your plan will be switched to ${chalk.bold(newPlan.name)} in ${chalk.bold(newPlan.until)}. Your card will not be charged again`) + success( + `Your plan will be switched to ${chalk.bold(newPlan.name)} in ${chalk.bold(newPlan.until)}. Your card will not be charged again` + ) } else { success(`You're now on the ${chalk.bold(`${newPlan.name} plan`)}`) } diff --git a/bin/teams/add.js b/bin/teams/add.js index 165d827..cf25050 100644 --- a/bin/teams/add.js +++ b/bin/teams/add.js @@ -25,7 +25,9 @@ function validateSlugKeypress(data, value) { function gracefulExit() { console.log() // Blank line - note(`Your team is now active for all ${cmd('now')} commands!\n Run ${cmd('now switch')} to change it in the future.`) + note( + `Your team is now active for all ${cmd('now')} commands!\n Run ${cmd('now switch')} to change it in the future.` + ) return exit() } @@ -38,7 +40,9 @@ module.exports = async function({ teams, token }) { let elapsed let stopSpinner - info(`Pick a team identifier for its url (e.g.: ${chalk.cyan('`zeit.co/acme`')})`) + info( + `Pick a team identifier for its url (e.g.: ${chalk.cyan('`zeit.co/acme`')})` + ) do { try { // eslint-disable-next-line no-await-in-loop diff --git a/lib/alias.js b/lib/alias.js index d16b4ea..ed925a4 100644 --- a/lib/alias.js +++ b/lib/alias.js @@ -176,7 +176,9 @@ module.exports = class Alias extends Now { const code = body.error.code if (code === 'cert_missing') { - console.log(`> Provisioning certificate for ${chalk.underline(chalk.bold(alias))}`) + console.log( + `> Provisioning certificate for ${chalk.underline(chalk.bold(alias))}` + ) try { await this.createCert(alias) @@ -192,7 +194,9 @@ module.exports = class Alias extends Now { } if (code === 'cert_expired') { - console.log(`> Renewing certificate for ${chalk.underline(chalk.bold(alias))}`) + console.log( + `> Renewing certificate for ${chalk.underline(chalk.bold(alias))}` + ) try { await this.createCert(alias, { renew: true }) @@ -252,7 +256,9 @@ module.exports = class Alias extends Now { console.log(err) } } else { - console.log(`Overwriting path alias with ${aliasDepl.rules.length} rule${aliasDepl.rules.length > 1 ? 's' : ''} to be a normal alias.`) + console.log( + `Overwriting path alias with ${aliasDepl.rules.length} rule${aliasDepl.rules.length > 1 ? 's' : ''} to be a normal alias.` + ) } } @@ -269,8 +275,12 @@ module.exports = class Alias extends Now { aliasedDeployment.scale.max > depl.scale.max) ) { shouldScaleDown = true - console.log(`> Alias ${alias} points to ${chalk.bold(aliasedDeployment.url)} (${chalk.bold(aliasedDeployment.scale.current + ' instances')})`) - console.log(`> Scaling ${depl.url} to ${chalk.bold(aliasedDeployment.scale.current + ' instances')} atomically`) + console.log( + `> Alias ${alias} points to ${chalk.bold(aliasedDeployment.url)} (${chalk.bold(aliasedDeployment.scale.current + ' instances')})` + ) + console.log( + `> Scaling ${depl.url} to ${chalk.bold(aliasedDeployment.scale.current + ' instances')} atomically` + ) if (depl.scale.max < 1) { if (this._debug) { @@ -289,7 +299,9 @@ module.exports = class Alias extends Now { } await this.unfreeze(depl) if (this._debug) { - console.log(`> Deployment is now unfrozen, scaling it to match current instance count`) + console.log( + `> Deployment is now unfrozen, scaling it to match current instance count` + ) } } // Scale it to current limit @@ -335,19 +347,25 @@ module.exports = class Alias extends Now { console.log(output) } } else { - console.log(`${chalk.cyan('> Success!')} Alias already exists ${chalk.dim(`(${uid})`)}.`) + console.log( + `${chalk.cyan('> Success!')} Alias already exists ${chalk.dim(`(${uid})`)}.` + ) } if (aliasedDeployment && shouldScaleDown) { const scaleDown = Date.now() await this.setScale(aliasedDeployment.uid, { min: 0, max: 1 }) - console.log(`> Scaled ${chalk.gray(aliasedDeployment.url)} down to 1 instance ${chalk.gray('[' + ms(Date.now() - scaleDown) + ']')}`) + console.log( + `> Scaled ${chalk.gray(aliasedDeployment.url)} down to 1 instance ${chalk.gray('[' + ms(Date.now() - scaleDown) + ']')}` + ) } } createAlias(depl, alias) { return this.retry(async (bail, attempt) => { if (this._debug) { - console.time(`> [debug] /now/deployments/${depl.uid}/aliases #${attempt}`) + console.time( + `> [debug] /now/deployments/${depl.uid}/aliases #${attempt}` + ) } const res = await this._fetch(`/now/deployments/${depl.uid}/aliases`, { @@ -357,7 +375,9 @@ module.exports = class Alias extends Now { const body = await res.json() if (this._debug) { - console.timeEnd(`> [debug] /now/deployments/${depl.uid}/aliases #${attempt}`) + console.timeEnd( + `> [debug] /now/deployments/${depl.uid}/aliases #${attempt}` + ) } // 409 conflict is returned if it already exists @@ -405,7 +425,9 @@ module.exports = class Alias extends Now { } if (code === 'cert_missing') { - console.log(`> Provisioning certificate for ${chalk.underline(chalk.bold(alias))}`) + console.log( + `> Provisioning certificate for ${chalk.underline(chalk.bold(alias))}` + ) try { await this.createCert(alias) @@ -421,7 +443,9 @@ module.exports = class Alias extends Now { } if (code === 'cert_expired') { - console.log(`> Renewing certificate for ${chalk.underline(chalk.bold(alias))}`) + console.log( + `> Renewing certificate for ${chalk.underline(chalk.bold(alias))}` + ) try { await this.createCert(alias, { renew: true }) @@ -523,8 +547,12 @@ module.exports = class Alias extends Now { if (canBePurchased) { const price = await pricePromise - info(`The domain ${aliasParam} is ${chalk.bold('available for purchase')}! ${elapsed()}`) - const confirmation = await promptBool(`Buy now for ${chalk.bold(`$${price}`)} (${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)})?`) + info( + `The domain ${aliasParam} is ${chalk.bold('available for purchase')}! ${elapsed()}` + ) + const confirmation = await promptBool( + `Buy now for ${chalk.bold(`$${price}`)} (${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)})?` + ) eraseLines(1) if (!confirmation) { info('Aborted') @@ -563,12 +591,16 @@ module.exports = class Alias extends Now { error( 'The nameservers are pending propagation. Please try again shortly' ) - info(`The ${tld} servers might take some extra time to reflect changes`) + info( + `The ${tld} servers might take some extra time to reflect changes` + ) gracefulExit() } } - console.log(`> Verifying the DNS settings for ${chalk.bold(chalk.underline(alias))} (see ${chalk.underline('https://zeit.world')} for help)`) + console.log( + `> Verifying the DNS settings for ${chalk.bold(chalk.underline(alias))} (see ${chalk.underline('https://zeit.world')} for help)` + ) const _domain = publicSuffixList.parse(alias).domain const _domainInfo = await this.getDomain(_domain) @@ -585,9 +617,13 @@ module.exports = class Alias extends Now { if (this._debug) { if (domainInfo) { - console.log(`> [debug] Found domain ${domain} with verified:${domainInfo.verified}`) + console.log( + `> [debug] Found domain ${domain} with verified:${domainInfo.verified}` + ) } else { - console.log(`> [debug] Found domain ${domain} and nameservers ${nameservers}`) + console.log( + `> [debug] Found domain ${domain} and nameservers ${nameservers}` + ) } } @@ -605,7 +641,9 @@ module.exports = class Alias extends Now { e.userError = true throw e } - console.log(`${chalk.cyan('> Success!')} Domain ${chalk.bold(chalk.underline(domain))} verified`) + console.log( + `${chalk.cyan('> Success!')} Domain ${chalk.bold(chalk.underline(domain))} verified` + ) } } @@ -620,7 +658,9 @@ module.exports = class Alias extends Now { // configuration (if we can!) try { if (usingZeitWorld) { - console.log(`> Detected ${chalk.bold(chalk.underline('zeit.world'))} nameservers! Configuring records.`) + console.log( + `> Detected ${chalk.bold(chalk.underline('zeit.world'))} nameservers! Configuring records.` + ) const record = alias.substr(0, alias.length - domain.length) // Lean up trailing and leading dots @@ -650,10 +690,14 @@ module.exports = class Alias extends Now { throw e } } else { - console.log(`> Resolved IP: ${err.ip ? `${chalk.underline(err.ip)} (unknown)` : chalk.dim('none')}`) - console.log(`> Nameservers: ${nameservers && nameservers.length ? nameservers - .map(ns => chalk.underline(ns)) - .join(', ') : chalk.dim('none')}`) + console.log( + `> Resolved IP: ${err.ip ? `${chalk.underline(err.ip)} (unknown)` : chalk.dim('none')}` + ) + console.log( + `> Nameservers: ${nameservers && nameservers.length ? nameservers + .map(ns => chalk.underline(ns)) + .join(', ') : chalk.dim('none')}` + ) throw err } } catch (e) { @@ -670,7 +714,9 @@ module.exports = class Alias extends Now { if (!usingZeitWorld && !skipDNSVerification) { if (this._debug) { - console.log(`> [debug] Trying to register a non-ZeitWorld domain ${domain} for the current user`) + console.log( + `> [debug] Trying to register a non-ZeitWorld domain ${domain} for the current user` + ) } const { uid, verified, created } = await this.setupDomain(domain, { @@ -683,7 +729,9 @@ module.exports = class Alias extends Now { e.userError = true throw e } - console.log(`${chalk.cyan('> Success!')} Domain ${chalk.bold(chalk.underline(domain))} ${chalk.dim(`(${uid})`)} added`) + console.log( + `${chalk.cyan('> Success!')} Domain ${chalk.bold(chalk.underline(domain))} ${chalk.dim(`(${uid})`)} added` + ) } console.log(`> Verification ${chalk.bold('OK')}!`) diff --git a/lib/domains.js b/lib/domains.js index 5e89295..7b447b0 100644 --- a/lib/domains.js +++ b/lib/domains.js @@ -73,7 +73,9 @@ module.exports = class Domains extends Now { } if (this._debug) { - console.log(`> [debug] Supplied domain "${domain}" has non-zeit nameservers`) + console.log( + `> [debug] Supplied domain "${domain}" has non-zeit nameservers` + ) } const err3 = new Error(DNS_VERIFICATION_ERROR) diff --git a/lib/login.js b/lib/login.js index 454a1ce..46e1063 100644 --- a/lib/login.js +++ b/lib/login.js @@ -74,10 +74,14 @@ async function register(url, { retryEmail = false } = {}) { } const { token, securityCode } = await getVerificationData(url, email) - console.log(`> Please follow the link sent to ${chalk.bold(email)} to log in.`) + console.log( + `> Please follow the link sent to ${chalk.bold(email)} to log in.` + ) if (securityCode) { - console.log(`> Verify that the provided security code in the email matches ${chalk.cyan(chalk.bold(securityCode))}.`) + console.log( + `> Verify that the provided security code in the email matches ${chalk.cyan(chalk.bold(securityCode))}.` + ) } process.stdout.write('\n') diff --git a/lib/re-alias.js b/lib/re-alias.js index 60909ea..0bac408 100644 --- a/lib/re-alias.js +++ b/lib/re-alias.js @@ -22,7 +22,9 @@ exports.assignAlias = async ( ) => { const aliases = new NowAlias({ apiUrl, token, debug, currentTeam }) const domains = new NowDomains({ apiUrl, token, debug, currentTeam }) - console.log(`> Assigning alias ${chalk.bold.underline(autoAlias)} to deployment...`) + console.log( + `> Assigning alias ${chalk.bold.underline(autoAlias)} to deployment...` + ) // Assign alias await aliases.set( @@ -54,7 +56,9 @@ exports.reAlias = async ( } if (!fs.existsSync(configFiles.pkg) && !fs.existsSync(configFiles.nowJSON)) { - error(`Couldn't find a now.json or package.json file with an alias list in it`) + error( + `Couldn't find a now.json or package.json file with an alias list in it` + ) return } @@ -86,7 +90,9 @@ exports.reAlias = async ( } else if (Array.isArray(value)) { pointers = pointers.concat(nowConfig.alias) } else { - error(`Property ${chalk.grey('aliases')} is not a valid array or string`) + error( + `Property ${chalk.grey('aliases')} is not a valid array or string` + ) return exit(1) } } diff --git a/lib/scale-info.js b/lib/scale-info.js index f96c03b..371b4d0 100644 --- a/lib/scale-info.js +++ b/lib/scale-info.js @@ -52,7 +52,9 @@ module.exports = async function(now, url) { if (barcurr === targetReplicaCount) { linelog.clear() - linelog(`> Scaled to ${chalk.bold(String(targetReplicaCount) + (targetReplicaCount === 1 ? ' instance' : ' instances'))}: ${chalk.gray('[' + ms(Date.now() - startTime) + ']')}\n`) + linelog( + `> Scaled to ${chalk.bold(String(targetReplicaCount) + (targetReplicaCount === 1 ? ' instance' : ' instances'))}: ${chalk.gray('[' + ms(Date.now() - startTime) + ']')}\n` + ) return res } } diff --git a/lib/scale.js b/lib/scale.js index 5976922..ba577f0 100644 --- a/lib/scale.js +++ b/lib/scale.js @@ -13,7 +13,9 @@ module.exports = class Scale extends Now { }) if (this._debug) { - console.timeEnd(`> [debug] #${attempt} GET /deployments/${id}/instances`) + console.timeEnd( + `> [debug] #${attempt} GET /deployments/${id}/instances` + ) } if (res.status === 403) {