Browse Source

Prettier stuff

master
Matheus Fernandes 8 years ago
parent
commit
8ebd5b91ec
No known key found for this signature in database GPG Key ID: DD07CA4EA7B65C4F
  1. 12
      bin/domains/buy.js
  2. 2
      bin/now-alias.js
  3. 24
      bin/now-billing-add.js
  4. 20
      bin/now-billing.js
  5. 61
      bin/now-certs.js
  6. 2
      bin/now-deploy.js
  7. 41
      bin/now-dns.js
  8. 33
      bin/now-domains.js
  9. 2
      bin/now-list.js
  10. 6
      bin/now-logout.js
  11. 8
      bin/now-logs.js
  12. 16
      bin/now-open.js
  13. 24
      bin/now-remove.js
  14. 28
      bin/now-scale.js
  15. 49
      bin/now-secrets.js
  16. 22
      bin/now-teams.js
  17. 20
      bin/now-upgrade.js
  18. 10
      bin/teams/add.js
  19. 11
      bin/teams/invite.js
  20. 4
      bin/teams/switch.js
  21. 2
      lib/cfg.js
  22. 4
      lib/domains.js
  23. 42
      lib/index.js
  24. 8
      lib/login.js
  25. 22
      lib/re-alias.js
  26. 4
      lib/scale-info.js
  27. 4
      lib/scale.js

12
bin/domains/buy.js

@ -30,15 +30,11 @@ module.exports = async function({ domains, args, currentTeam, user }) {
stopSpinner() stopSpinner()
if (!available) { if (!available) {
return error( return error(`The domain ${nameParam} is ${italic('unavailable')}! ${elapsed()}`)
`The domain ${nameParam} is ${italic('unavailable')}! ${elapsed()}`
)
} }
info(`The domain ${nameParam} is ${italic('available')}! ${elapsed()}`) info(`The domain ${nameParam} is ${italic('available')}! ${elapsed()}`)
const confirmation = await promptBool( const confirmation = await promptBool(`Buy now for ${bold(`$${price}`)} (${bold((currentTeam && currentTeam.slug) || user.username || user.email)})?`)
`Buy now for ${bold(`$${price}`)} (${bold((currentTeam && currentTeam.slug) || user.username || user.email)})?`
)
eraseLines(1) eraseLines(1)
if (!confirmation) { if (!confirmation) {
@ -58,7 +54,5 @@ module.exports = async function({ domains, args, currentTeam, user }) {
stopSpinner() stopSpinner()
success(`Domain purchased and created ${uid(domain.uid)} ${elapsed()}`) success(`Domain purchased and created ${uid(domain.uid)} ${elapsed()}`)
info( info(`You may now use your domain as an alias to your deployments. Run ${cmd('now alias help')}`)
`You may now use your domain as an alias to your deployments. Run ${cmd('now alias help')}`
)
} }

2
bin/now-alias.js

@ -110,7 +110,7 @@ if (argv.help) {
exit(0) exit(0)
} else { } else {
Promise.resolve().then(async () => { Promise.resolve().then(async () => {
const config = await cfg.read({token: argv.token}) const config = await cfg.read({ token: argv.token })
let token let token
try { try {

24
bin/now-billing-add.js

@ -137,13 +137,11 @@ module.exports = function({ creditCards, currentTeam, user }) {
} }
brand = chalk.cyan(`[${brand}]`) brand = chalk.cyan(`[${brand}]`)
const masked = chalk.gray('#### '.repeat(3)) + result.split(' ')[3] const masked = chalk.gray('#### '.repeat(3)) + result.split(' ')[3]
process.stdout.write( process.stdout
`${chalk.cyan(tick)} ${piece.label}${masked} ${brand}\n` .write(`${chalk.cyan(tick)} ${piece.label}${masked} ${brand}\n`)
)
} else if (key === 'ccv') { } else if (key === 'ccv') {
process.stdout.write( process.stdout
`${chalk.cyan(tick)} ${piece.label}${'*'.repeat(result.length)}\n` .write(`${chalk.cyan(tick)} ${piece.label}${'*'.repeat(result.length)}\n`)
)
} else if (key === 'expDate') { } else if (key === 'expDate') {
let text = result.split(' / ') let text = result.split(' / ')
text = text[0] + chalk.gray(' / ') + text[1] text = text[0] + chalk.gray(' / ') + text[1]
@ -161,13 +159,11 @@ module.exports = function({ creditCards, currentTeam, user }) {
state.city.initialValue = addressInfo.city state.city.initialValue = addressInfo.city
} }
stopSpinner() stopSpinner()
process.stdout.write( process.stdout
`${chalk.cyan(tick)} ${piece.label}${result}\n` .write(`${chalk.cyan(tick)} ${piece.label}${result}\n`)
)
} else { } else {
process.stdout.write( process.stdout
`${chalk.cyan(tick)} ${piece.label}${result}\n` .write(`${chalk.cyan(tick)} ${piece.label}${result}\n`)
)
} }
} catch (err) { } catch (err) {
if (err.message === 'USER_ABORT') { if (err.message === 'USER_ABORT') {
@ -194,9 +190,7 @@ module.exports = function({ creditCards, currentTeam, user }) {
address1: state.address1.value address1: state.address1.value
}) })
stopSpinner() stopSpinner()
success( success(`${state.cardNumber.brand} ending in ${res.last4} was added to ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`)
`${state.cardNumber.brand} ending in ${res.last4} was added to ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`
)
} catch (err) { } catch (err) {
stopSpinner() stopSpinner()
const linesToClear = state.error ? 13 : 12 const linesToClear = state.error ? 13 : 12

20
bin/now-billing.js

@ -33,8 +33,7 @@ const argv = minimist(process.argv.slice(2), {
const subcommand = argv._[0] const subcommand = argv._[0]
const help = () => { const help = () => {
console.log( console.log(`
`
${chalk.bold(`${logo} now billing`)} <ls | add | rm | set-default> ${chalk.bold(`${logo} now billing`)} <ls | add | rm | set-default>
${chalk.dim('Options:')} ${chalk.dim('Options:')}
@ -65,8 +64,7 @@ const help = () => {
${chalk.cyan(`$ now billing set-default <id>`)} ${chalk.cyan(`$ now billing set-default <id>`)}
${chalk.gray('–')} If the id is omitted, you can choose interactively ${chalk.gray('–')} If the id is omitted, you can choose interactively
` `)
)
} }
// Options // Options
@ -90,7 +88,7 @@ if (argv.help || !subcommand) {
exit(0) exit(0)
} else { } else {
Promise.resolve().then(async () => { Promise.resolve().then(async () => {
const config = await cfg.read({token: argv.token}) const config = await cfg.read({ token: argv.token })
let token let token
try { try {
@ -184,9 +182,7 @@ async function run({ token, config: { currentTeam, user } }) {
.join('\n\n') .join('\n\n')
const elapsed = ms(new Date() - start) const elapsed = ms(new Date() - start)
console.log( 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}]`)}`)
`> ${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) { if (text) {
console.log(`\n${text}\n`) console.log(`\n${text}\n`)
} }
@ -246,9 +242,7 @@ async function run({ token, config: { currentTeam, user } }) {
const card = cards.cards.find(card => card.id === cardId) const card = cards.cards.find(card => card.id === cardId)
const elapsed = ms(new Date() - start) const elapsed = ms(new Date() - start)
success( success(`${card.brand} ending in ${card.last4} is now the default ${chalk.gray(`[${elapsed}]`)}`)
`${card.brand} ending in ${card.last4} is now the default ${chalk.gray(`[${elapsed}]`)}`
)
} else { } else {
console.log('No changes made') console.log('No changes made')
} }
@ -273,9 +267,7 @@ async function run({ token, config: { currentTeam, user } }) {
} }
if (cards.cards.length === 0) { if (cards.cards.length === 0) {
error( error(`You have no credit cards to choose from to delete under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`)
`You have no credit cards to choose from to delete under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`
)
return exit(0) return exit(0)
} }

61
bin/now-certs.js

@ -31,8 +31,7 @@ const subcommand = argv._[0]
// Options // Options
const help = () => { const help = () => {
console.log( console.log(`
`
${chalk.bold(`${logo} now certs`)} <ls | create | renew | replace | rm> <cn> ${chalk.bold(`${logo} now certs`)} <ls | create | renew | replace | rm> <cn>
${chalk.dim('Note:')} ${chalk.dim('Note:')}
@ -66,8 +65,7 @@ const help = () => {
${chalk.gray('–')} Replacing an existing certificate with a user-supplied certificate: ${chalk.gray('–')} Replacing an existing certificate with a user-supplied certificate:
${chalk.cyan('$ now certs replace --crt domain.crt --key domain.key --ca ca_chain.crt domain.com')} ${chalk.cyan('$ now certs replace --crt domain.crt --key domain.key --ca ca_chain.crt domain.com')}
` `)
)
} }
// Options // Options
@ -83,7 +81,7 @@ if (argv.help || !subcommand) {
exit(0) exit(0)
} else { } else {
Promise.resolve().then(async () => { Promise.resolve().then(async () => {
const config = await cfg.read({token: argv.token}) const config = await cfg.read({ token: argv.token })
let token let token
try { try {
@ -116,18 +114,14 @@ async function run({ token, config: { currentTeam, user } }) {
if (subcommand === 'ls' || subcommand === 'list') { if (subcommand === 'ls' || subcommand === 'list') {
if (args.length !== 0) { if (args.length !== 0) {
error( error(`Invalid number of arguments. Usage: ${chalk.cyan('`now certs ls`')}`)
`Invalid number of arguments. Usage: ${chalk.cyan('`now certs ls`')}`
)
return exit(1) return exit(1)
} }
const list = await certs.ls() const list = await certs.ls()
const elapsed = ms(new Date() - start) const elapsed = ms(new Date() - start)
console.log( console.log(`> ${list.length} certificate${list.length === 1 ? '' : 's'} found ${chalk.gray(`[${elapsed}]`)} under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`)
`> ${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) { if (list.length > 0) {
const cur = Date.now() const cur = Date.now()
@ -168,9 +162,7 @@ async function run({ token, config: { currentTeam, user } }) {
} }
} else if (subcommand === 'create') { } else if (subcommand === 'create') {
if (args.length !== 1) { if (args.length !== 1) {
error( error(`Invalid number of arguments. Usage: ${chalk.cyan('`now certs create <cn>`')}`)
`Invalid number of arguments. Usage: ${chalk.cyan('`now certs create <cn>`')}`
)
return exit(1) return exit(1)
} }
const cn = args[0] const cn = args[0]
@ -179,9 +171,7 @@ async function run({ token, config: { currentTeam, user } }) {
if (argv.crt || argv.key || argv.ca) { if (argv.crt || argv.key || argv.ca) {
// Issue a custom certificate // Issue a custom certificate
if (!argv.crt || !argv.key) { if (!argv.crt || !argv.key) {
error( error(`Missing required arguments for a custom certificate entry. Usage: ${chalk.cyan('`now certs create --crt DOMAIN.CRT --key DOMAIN.KEY [--ca CA.CRT] <id | cn>`')}`)
`Missing required arguments for a custom certificate entry. Usage: ${chalk.cyan('`now certs create --crt DOMAIN.CRT --key DOMAIN.KEY [--ca CA.CRT] <id | cn>`')}`
)
return exit(1) return exit(1)
} }
@ -199,14 +189,10 @@ async function run({ token, config: { currentTeam, user } }) {
return exit(1) return exit(1)
} }
const elapsed = ms(new Date() - start) const elapsed = ms(new Date() - start)
console.log( console.log(`${chalk.cyan('> Success!')} Certificate entry ${chalk.bold(cn)} ${chalk.gray(`(${cert.uid})`)} created ${chalk.gray(`[${elapsed}]`)}`)
`${chalk.cyan('> Success!')} Certificate entry ${chalk.bold(cn)} ${chalk.gray(`(${cert.uid})`)} created ${chalk.gray(`[${elapsed}]`)}`
)
} else if (subcommand === 'renew') { } else if (subcommand === 'renew') {
if (args.length !== 1) { if (args.length !== 1) {
error( error(`Invalid number of arguments. Usage: ${chalk.cyan('`now certs renew <id | cn>`')}`)
`Invalid number of arguments. Usage: ${chalk.cyan('`now certs renew <id | cn>`')}`
)
return exit(1) return exit(1)
} }
@ -226,14 +212,10 @@ async function run({ token, config: { currentTeam, user } }) {
await certs.renew(cert.cn) await certs.renew(cert.cn)
const elapsed = ms(new Date() - start) const elapsed = ms(new Date() - start)
console.log( console.log(`${chalk.cyan('> Success!')} Certificate ${chalk.bold(cert.cn)} ${chalk.gray(`(${cert.uid})`)} renewed ${chalk.gray(`[${elapsed}]`)}`)
`${chalk.cyan('> Success!')} Certificate ${chalk.bold(cert.cn)} ${chalk.gray(`(${cert.uid})`)} renewed ${chalk.gray(`[${elapsed}]`)}`
)
} else if (subcommand === 'replace') { } else if (subcommand === 'replace') {
if (!argv.crt || !argv.key) { if (!argv.crt || !argv.key) {
error( error(`Invalid number of arguments. Usage: ${chalk.cyan('`now certs replace --crt DOMAIN.CRT --key DOMAIN.KEY [--ca CA.CRT] <id | cn>`')}`)
`Invalid number of arguments. Usage: ${chalk.cyan('`now certs replace --crt DOMAIN.CRT --key DOMAIN.KEY [--ca CA.CRT] <id | cn>`')}`
)
return exit(1) return exit(1)
} }
@ -256,14 +238,10 @@ async function run({ token, config: { currentTeam, user } }) {
await certs.put(cert.cn, crt, key, ca) await certs.put(cert.cn, crt, key, ca)
const elapsed = ms(new Date() - start) const elapsed = ms(new Date() - start)
console.log( console.log(`${chalk.cyan('> Success!')} Certificate ${chalk.bold(cert.cn)} ${chalk.gray(`(${cert.uid})`)} replaced ${chalk.gray(`[${elapsed}]`)}`)
`${chalk.cyan('> Success!')} Certificate ${chalk.bold(cert.cn)} ${chalk.gray(`(${cert.uid})`)} replaced ${chalk.gray(`[${elapsed}]`)}`
)
} else if (subcommand === 'rm' || subcommand === 'remove') { } else if (subcommand === 'rm' || subcommand === 'remove') {
if (args.length !== 1) { if (args.length !== 1) {
error( error(`Invalid number of arguments. Usage: ${chalk.cyan('`now certs rm <id | cn>`')}`)
`Invalid number of arguments. Usage: ${chalk.cyan('`now certs rm <id | cn>`')}`
)
return exit(1) return exit(1)
} }
@ -282,9 +260,7 @@ async function run({ token, config: { currentTeam, user } }) {
await certs.delete(cert.cn) await certs.delete(cert.cn)
const elapsed = ms(new Date() - start) const elapsed = ms(new Date() - start)
console.log( console.log(`${chalk.cyan('> Success!')} Certificate ${chalk.bold(cert.cn)} ${chalk.gray(`(${cert.uid})`)} removed ${chalk.gray(`[${elapsed}]`)}`)
`${chalk.cyan('> Success!')} Certificate ${chalk.bold(cert.cn)} ${chalk.gray(`(${cert.uid})`)} removed ${chalk.gray(`[${elapsed}]`)}`
)
} else { } else {
error( error(
'Please specify a valid subcommand: ls | create | renew | replace | rm' 'Please specify a valid subcommand: ls | create | renew | replace | rm'
@ -311,9 +287,8 @@ function readConfirmation(cert, msg) {
process.stdout.write(`> ${msg}`) process.stdout.write(`> ${msg}`)
process.stdout.write(' ' + tbl + '\n') process.stdout.write(' ' + tbl + '\n')
process.stdout.write( process.stdout
`${chalk.bold.red('> Are you sure?')} ${chalk.gray('[y/N] ')}` .write(`${chalk.bold.red('> Are you sure?')} ${chalk.gray('[y/N] ')}`)
)
process.stdin process.stdin
.on('data', d => { .on('data', d => {
@ -335,9 +310,7 @@ async function getCertIdCn(certs, idOrCn, currentTeam, user) {
})[0] })[0]
if (!thecert) { if (!thecert) {
error( error(`No certificate found by id or cn "${idOrCn}" under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`)
`No certificate found by id or cn "${idOrCn}" under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`
)
return null return null
} }

2
bin/now-deploy.js

@ -202,7 +202,7 @@ if (deploymentName || wantsPublic) {
let alwaysForwardNpm let alwaysForwardNpm
Promise.resolve().then(async () => { Promise.resolve().then(async () => {
let config = await cfg.read({token: argv.token}) let config = await cfg.read({ token: argv.token })
alwaysForwardNpm = config.forwardNpm alwaysForwardNpm = config.forwardNpm
if (argv.h || argv.help) { if (argv.h || argv.help) {

41
bin/now-dns.js

@ -31,8 +31,7 @@ const subcommand = argv._[0]
// Options // Options
const help = () => { const help = () => {
console.log( console.log(`
`
${chalk.bold(`${logo} now dns ls`)} [domain] ${chalk.bold(`${logo} now dns ls`)} [domain]
${chalk.bold(`${logo} now dns add`)} <domain> <name> <A | AAAA | ALIAS | CNAME | TXT> <value> ${chalk.bold(`${logo} now dns add`)} <domain> <name> <A | AAAA | ALIAS | CNAME | TXT> <value>
${chalk.bold(`${logo} now dns add`)} <domain> <name> MX <value> <mx_priority> ${chalk.bold(`${logo} now dns add`)} <domain> <name> MX <value> <mx_priority>
@ -61,8 +60,7 @@ const help = () => {
${chalk.cyan('$ now dns add <YOUR DOMAIN> @ MX <RECORD VALUE> <PRIORITY>')} ${chalk.cyan('$ now dns add <YOUR DOMAIN> @ MX <RECORD VALUE> <PRIORITY>')}
${chalk.cyan('$ now dns add zeit.rocks @ MX mail.zeit.rocks 10')} ${chalk.cyan('$ now dns add zeit.rocks @ MX mail.zeit.rocks 10')}
` `)
)
} }
// Options // Options
@ -77,7 +75,7 @@ if (argv.help || !subcommand) {
exit(0) exit(0)
} else { } else {
Promise.resolve().then(async () => { Promise.resolve().then(async () => {
const config = await cfg.read({token: argv.token}) const config = await cfg.read({ token: argv.token })
let token let token
try { try {
@ -103,9 +101,7 @@ async function run({ token, config: { currentTeam, user } }) {
if (subcommand === 'ls' || subcommand === 'list') { if (subcommand === 'ls' || subcommand === 'list') {
if (args.length > 1) { if (args.length > 1) {
error( error(`Invalid number of arguments. Usage: ${chalk.cyan('`now dns ls [domain]`')}`)
`Invalid number of arguments. Usage: ${chalk.cyan('`now dns ls [domain]`')}`
)
return exit(1) return exit(1)
} }
@ -148,28 +144,20 @@ async function run({ token, config: { currentTeam, user } }) {
text.push(`\n\n${chalk.bold(domain)}\n${indent(out, 2)}`) text.push(`\n\n${chalk.bold(domain)}\n${indent(out, 2)}`)
} }
}) })
console.log( console.log(`> ${count} record${count === 1 ? '' : 's'} found ${chalk.gray(`[${elapsed}]`)} under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`)
`> ${count} record${count === 1 ? '' : 's'} found ${chalk.gray(`[${elapsed}]`)} under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`
)
console.log(text.join('')) console.log(text.join(''))
} else if (subcommand === 'add') { } else if (subcommand === 'add') {
const param = parseAddArgs(args) const param = parseAddArgs(args)
if (!param) { if (!param) {
error( error(`Invalid number of arguments. See: ${chalk.cyan('`now dns --help`')} for usage.`)
`Invalid number of arguments. See: ${chalk.cyan('`now dns --help`')} for usage.`
)
return exit(1) return exit(1)
} }
const record = await domainRecords.create(param.domain, param.data) const record = await domainRecords.create(param.domain, param.data)
const elapsed = ms(new Date() - start) const elapsed = ms(new Date() - start)
console.log( 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)})`)
`${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') { } else if (subcommand === 'rm' || subcommand === 'remove') {
if (args.length !== 1) { if (args.length !== 1) {
error( error(`Invalid number of arguments. Usage: ${chalk.cyan('`now dns rm <id>`')}`)
`Invalid number of arguments. Usage: ${chalk.cyan('`now dns rm <id>`')}`
)
return exit(1) return exit(1)
} }
@ -190,9 +178,7 @@ async function run({ token, config: { currentTeam, user } }) {
await domainRecords.delete(record.domain, record.id) await domainRecords.delete(record.domain, record.id)
const elapsed = ms(new Date() - start) const elapsed = ms(new Date() - start)
console.log( console.log(`${chalk.cyan('> Success!')} Record ${chalk.gray(`${record.id}`)} removed ${chalk.gray(`[${elapsed}]`)}`)
`${chalk.cyan('> Success!')} Record ${chalk.gray(`${record.id}`)} removed ${chalk.gray(`[${elapsed}]`)}`
)
} else { } else {
error('Please specify a valid subcommand: ls | add | rm') error('Please specify a valid subcommand: ls | add | rm')
help() help()
@ -277,9 +263,7 @@ function readConfirmation(record, msg) {
[ [
[ [
record.id, record.id,
chalk.bold( chalk.bold(`${record.name.length > 0 ? record.name + '.' : ''}${record.domain} ${record.type} ${record.value} ${record.mxPriority ? record.mxPriority : ''}`),
`${record.name.length > 0 ? record.name + '.' : ''}${record.domain} ${record.type} ${record.value} ${record.mxPriority ? record.mxPriority : ''}`
),
time time
] ]
], ],
@ -289,9 +273,8 @@ function readConfirmation(record, msg) {
process.stdout.write(`> ${msg}`) process.stdout.write(`> ${msg}`)
process.stdout.write(' ' + tbl + '\n') process.stdout.write(' ' + tbl + '\n')
process.stdout.write( process.stdout
`${chalk.bold.red('> Are you sure?')} ${chalk.gray('[y/N] ')}` .write(`${chalk.bold.red('> Are you sure?')} ${chalk.gray('[y/N] ')}`)
)
process.stdin process.stdin
.on('data', d => { .on('data', d => {

33
bin/now-domains.js

@ -36,8 +36,7 @@ const subcommand = argv._[0]
// Options // Options
const help = () => { const help = () => {
console.log( console.log(`
`
${chalk.bold(`${logo} now domains`)} <ls | add | rm | buy> <domain> ${chalk.bold(`${logo} now domains`)} <ls | add | rm | buy> <domain>
${chalk.dim('Options:')} ${chalk.dim('Options:')}
@ -102,8 +101,7 @@ const help = () => {
${chalk.cyan('$ now domain add -e my-app.com')} ${chalk.cyan('$ now domain add -e my-app.com')}
and follow the verification instructions if requested. Finally, rerun the same command after completing the verification step. and follow the verification instructions if requested. Finally, rerun the same command after completing the verification step.
` `)
)
} }
// Options // Options
@ -119,7 +117,7 @@ if (argv.help || !subcommand) {
exit(0) exit(0)
} else { } else {
Promise.resolve().then(async () => { Promise.resolve().then(async () => {
const config = await cfg.read({token: argv.token}) const config = await cfg.read({ token: argv.token })
let token let token
try { try {
@ -183,9 +181,7 @@ async function run({ token, config: { currentTeam, user } }) {
) )
const elapsed_ = ms(new Date() - start_) const elapsed_ = ms(new Date() - start_)
console.log( console.log(`> ${domains.length} domain${domains.length === 1 ? '' : 's'} found under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)} ${chalk.gray(`[${elapsed_}]`)}`)
`> ${domains.length} domain${domains.length === 1 ? '' : 's'} found under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)} ${chalk.gray(`[${elapsed_}]`)}`
)
if (out) { if (out) {
console.log('\n' + out + '\n') console.log('\n' + out + '\n')
@ -232,9 +228,7 @@ async function run({ token, config: { currentTeam, user } }) {
const start = new Date() const start = new Date()
await domain.rm(_domain.name) await domain.rm(_domain.name)
const elapsed = ms(new Date() - start) const elapsed = ms(new Date() - start)
console.log( console.log(`${chalk.cyan('> Success!')} Domain ${chalk.bold(_domain.uid)} removed [${elapsed}]`)
`${chalk.cyan('> Success!')} Domain ${chalk.bold(_domain.uid)} removed [${elapsed}]`
)
} catch (err) { } catch (err) {
error(err) error(err)
exit(1) exit(1)
@ -257,17 +251,11 @@ async function run({ token, config: { currentTeam, user } }) {
) )
const elapsed = ms(new Date() - start) const elapsed = ms(new Date() - start)
if (created) { if (created) {
console.log( console.log(`${chalk.cyan('> Success!')} Domain ${chalk.bold(chalk.underline(name))} ${chalk.dim(`(${uid})`)} added [${elapsed}]`)
`${chalk.cyan('> Success!')} Domain ${chalk.bold(chalk.underline(name))} ${chalk.dim(`(${uid})`)} added [${elapsed}]`
)
} else if (verified) { } else if (verified) {
console.log( console.log(`${chalk.cyan('> Success!')} Domain ${chalk.bold(chalk.underline(name))} ${chalk.dim(`(${uid})`)} verified [${elapsed}]`)
`${chalk.cyan('> Success!')} Domain ${chalk.bold(chalk.underline(name))} ${chalk.dim(`(${uid})`)} verified [${elapsed}]`
)
} else if (code === 'not_modified') { } else if (code === 'not_modified') {
console.log( console.log(`${chalk.cyan('> Success!')} Domain ${chalk.bold(chalk.underline(name))} ${chalk.dim(`(${uid})`)} already exists [${elapsed}]`)
`${chalk.cyan('> Success!')} Domain ${chalk.bold(chalk.underline(name))} ${chalk.dim(`(${uid})`)} already exists [${elapsed}]`
)
} else { } else {
console.log( console.log(
'> Verification required: Please rerun this command after some time' '> Verification required: Please rerun this command after some time'
@ -312,9 +300,8 @@ async function readConfirmation(domain, _domain) {
) )
} }
process.stdout.write( process.stdout
` ${chalk.bold.red('> Are you sure?')} ${chalk.gray('[y/N] ')}` .write(` ${chalk.bold.red('> Are you sure?')} ${chalk.gray('[y/N] ')}`)
)
process.stdin process.stdin
.on('data', d => { .on('data', d => {

2
bin/now-list.js

@ -68,7 +68,7 @@ if (argv.config) {
} }
Promise.resolve().then(async () => { Promise.resolve().then(async () => {
const config = await cfg.read({token: argv.token}) const config = await cfg.read({ token: argv.token })
let token let token
try { try {

6
bin/now-logout.js

@ -20,8 +20,7 @@ const argv = minimist(process.argv.slice(2), {
}) })
const help = () => { const help = () => {
console.log( console.log(`
`
${chalk.bold(`${logo} now logout`)} ${chalk.bold(`${logo} now logout`)}
${chalk.dim('Options:')} ${chalk.dim('Options:')}
@ -34,8 +33,7 @@ const help = () => {
${chalk.gray('–')} Logout from the CLI: ${chalk.gray('–')} Logout from the CLI:
${chalk.cyan('$ now logout')} ${chalk.cyan('$ now logout')}
` `)
)
} }
if (argv.help) { if (argv.help) {

8
bin/now-logs.js

@ -29,8 +29,7 @@ const argv = minimist(process.argv.slice(2), {
let deploymentIdOrURL = argv._[0] let deploymentIdOrURL = argv._[0]
const help = () => { const help = () => {
console.log( console.log(`
`
${chalk.bold(`${logo} now logs`)} <deploymentId|url> ${chalk.bold(`${logo} now logs`)} <deploymentId|url>
${chalk.dim('Options:')} ${chalk.dim('Options:')}
@ -51,8 +50,7 @@ const help = () => {
${chalk.gray('–')} Print logs for the deployment ${chalk.dim('`deploymentId`')} ${chalk.gray('–')} Print logs for the deployment ${chalk.dim('`deploymentId`')}
${chalk.cyan('$ now logs deploymentId')} ${chalk.cyan('$ now logs deploymentId')}
` `)
)
} }
if (argv.help || !deploymentIdOrURL) { if (argv.help || !deploymentIdOrURL) {
@ -98,7 +96,7 @@ if (maybeURL(deploymentIdOrURL)) {
Promise.resolve() Promise.resolve()
.then(async () => { .then(async () => {
const config = await cfg.read({token: argv.token}) const config = await cfg.read({ token: argv.token })
let token let token
try { try {

16
bin/now-open.js

@ -25,8 +25,7 @@ const argv = minimist(process.argv.slice(2), {
}) })
const help = () => { const help = () => {
console.log( console.log(`
`
${chalk.bold(`${logo} now open`)} ${chalk.bold(`${logo} now open`)}
${chalk.dim('Options:')} ${chalk.dim('Options:')}
@ -42,8 +41,7 @@ const help = () => {
${chalk.cyan('$ now open')} ${chalk.cyan('$ now open')}
` `)
)
} }
if (argv.help) { if (argv.help) {
@ -62,7 +60,7 @@ if (argv.config) {
} }
Promise.resolve().then(async () => { Promise.resolve().then(async () => {
const config = await cfg.read({token: argv.token}) const config = await cfg.read({ token: argv.token })
let token let token
try { try {
@ -114,9 +112,7 @@ async function open({ token, config: { currentTeam, user } }) {
) )
if (typeof currentProjectDeployments === 'undefined') { if (typeof currentProjectDeployments === 'undefined') {
console.log( console.log(`No deployments found for ${chalk.bold(pkg.name)} under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`)
`No deployments found for ${chalk.bold(pkg.name)} under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`
)
process.exit(0) process.exit(0)
} }
@ -126,9 +122,7 @@ async function open({ token, config: { currentTeam, user } }) {
try { try {
const url = `https://${latestDeploy.url}` const url = `https://${latestDeploy.url}`
console.log( console.log(`Opening the latest deployment for ${chalk.bold(pkg.name)}... under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`)
`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)}`) console.log(`Here's the URL: ${chalk.underline(url)}`)
opn(url) opn(url)

24
bin/now-remove.js

@ -30,8 +30,7 @@ const ids = argv._
// Options // Options
const help = () => { const help = () => {
console.log( console.log(`
`
${chalk.bold(`${logo} now remove`)} deploymentId|deploymentName [...deploymentId|deploymentName] ${chalk.bold(`${logo} now remove`)} deploymentId|deploymentName [...deploymentId|deploymentName]
${chalk.dim('Options:')} ${chalk.dim('Options:')}
@ -57,8 +56,7 @@ const help = () => {
${chalk.cyan('$ now rm eyWt6zuSdeus uWHoA9RQ1d1o')} ${chalk.cyan('$ now rm eyWt6zuSdeus uWHoA9RQ1d1o')}
${chalk.dim('Alias:')} rm ${chalk.dim('Alias:')} rm
` `)
)
} }
if (argv.help || ids.length === 0) { if (argv.help || ids.length === 0) {
@ -77,7 +75,7 @@ if (argv.config) {
} }
Promise.resolve().then(async () => { Promise.resolve().then(async () => {
const config = await cfg.read({token: argv.token}) const config = await cfg.read({ token: argv.token })
let token let token
try { try {
@ -97,9 +95,8 @@ Promise.resolve().then(async () => {
function readConfirmation(matches) { function readConfirmation(matches) {
return new Promise(resolve => { return new Promise(resolve => {
process.stdout.write( process.stdout
`> The following deployment${matches.length === 1 ? '' : 's'} will be removed permanently:\n` .write(`> The following deployment${matches.length === 1 ? '' : 's'} will be removed permanently:\n`)
)
const tbl = table( const tbl = table(
matches.map(depl => { matches.map(depl => {
@ -120,9 +117,8 @@ function readConfirmation(matches) {
} }
} }
process.stdout.write( process.stdout
`${chalk.bold.red('> Are you sure?')} ${chalk.gray('[y/N] ')}` .write(`${chalk.bold.red('> Are you sure?')} ${chalk.gray('[y/N] ')}`)
)
process.stdin process.stdin
.on('data', d => { .on('data', d => {
@ -145,11 +141,9 @@ async function remove({ token, config: { currentTeam } }) {
}) })
if (matches.length === 0) { if (matches.length === 0) {
error( error(`Could not find any deployments matching ${ids
`Could not find any deployments matching ${ids
.map(id => chalk.bold(`"${id}"`)) .map(id => chalk.bold(`"${id}"`))
.join(', ')}. Run ${chalk.dim(`\`now ls\``)} to list.` .join(', ')}. Run ${chalk.dim(`\`now ls\``)} to list.`)
)
return process.exit(1) return process.exit(1)
} }

28
bin/now-scale.js

@ -17,7 +17,7 @@ const login = require('../lib/login')
const exit = require('../lib/utils/exit') const exit = require('../lib/utils/exit')
const logo = require('../lib/utils/output/logo') const logo = require('../lib/utils/output/logo')
const info = require('../lib/scale-info') const info = require('../lib/scale-info')
const sort = require('../lib/sort-deployments'); const sort = require('../lib/sort-deployments')
const argv = minimist(process.argv.slice(2), { const argv = minimist(process.argv.slice(2), {
string: ['config', 'token'], string: ['config', 'token'],
@ -31,8 +31,7 @@ const optionalScaleArg = argv._[2]
// Options // Options
const help = () => { const help = () => {
console.log( console.log(`
`
${chalk.bold(`${logo} now scale`)} ls ${chalk.bold(`${logo} now scale`)} ls
${chalk.bold(`${logo} now scale`)} <url> ${chalk.bold(`${logo} now scale`)} <url>
${chalk.bold(`${logo} now scale`)} <url> <min> [max] ${chalk.bold(`${logo} now scale`)} <url> <min> [max]
@ -64,8 +63,7 @@ const help = () => {
${chalk.gray('–')} Create an deployment that is always active and never "sleeps": ${chalk.gray('–')} Create an deployment that is always active and never "sleeps":
${chalk.cyan('$ now scale my-deployment-ntahoeato.now.sh 1')} ${chalk.cyan('$ now scale my-deployment-ntahoeato.now.sh 1')}
` `)
)
} }
// Options // Options
@ -81,7 +79,7 @@ if (argv.help) {
exit(0) exit(0)
} else { } else {
Promise.resolve().then(async () => { Promise.resolve().then(async () => {
const config = await cfg.read({token: argv.token}) const config = await cfg.read({ token: argv.token })
let token let token
try { try {
@ -197,9 +195,7 @@ async function run({ token, config: { currentTeam } }) {
} }
if ((match.state === 'FROZEN' || match.scale.current === 0) && min > 0) { if ((match.state === 'FROZEN' || match.scale.current === 0) && min > 0) {
console.log( console.log(`> Deployment is currently in 0 replicas, preparing deployment for scaling...`)
`> Deployment is currently in 0 replicas, preparing deployment for scaling...`
)
if (match.scale.max < 1) { if (match.scale.max < 1) {
await scale.setScale(match.uid, { min: 0, max: 1 }) await scale.setScale(match.uid, { min: 0, max: 1 })
} }
@ -217,9 +213,7 @@ async function run({ token, config: { currentTeam } }) {
const log = console.log const log = console.log
log(`> ${chalk.cyan('Success!')} Configured scaling rules [${elapsed}]`) log(`> ${chalk.cyan('Success!')} Configured scaling rules [${elapsed}]`)
log() log()
log( log(`${chalk.bold(match.url)} (${chalk.gray(currentReplicas)} ${chalk.gray('current')})`)
`${chalk.bold(match.url)} (${chalk.gray(currentReplicas)} ${chalk.gray('current')})`
)
log(printf('%6s %s', 'min', chalk.bold(newMin))) log(printf('%6s %s', 'min', chalk.bold(newMin)))
log(printf('%6s %s', 'max', chalk.bold(newMax))) log(printf('%6s %s', 'max', chalk.bold(newMax)))
log(printf('%6s %s', 'auto', chalk.bold(newMin === newMax ? '✖' : '✔'))) log(printf('%6s %s', 'auto', chalk.bold(newMin === newMax ? '✖' : '✔')))
@ -248,19 +242,17 @@ async function list(scale) {
apps.set(dep.name, deps.concat(dep)) apps.set(dep.name, deps.concat(dep))
} }
const sorted = await sort([...apps]); const sorted = await sort([...apps])
const timeNow = new Date(); const timeNow = new Date()
const urlLength = const urlLength =
deployments.reduce((acc, i) => { deployments.reduce((acc, i) => {
return Math.max(acc, (i.url && i.url.length) || 0) return Math.max(acc, (i.url && i.url.length) || 0)
}, 0) + 5 }, 0) + 5
for (const app of sorted) { for (const app of sorted) {
const depls = argv.all ? app[1] : app[1].slice(0, 5); const depls = argv.all ? app[1] : app[1].slice(0, 5)
console.log( console.log(`${chalk.bold(app[0])} ${chalk.gray('(' + depls.length + ' of ' + app[1].length + ' total)')}`)
`${chalk.bold(app[0])} ${chalk.gray('(' + depls.length + ' of ' + app[1].length + ' total)')}`
)
console.log() console.log()
const urlSpec = `%-${urlLength}s` const urlSpec = `%-${urlLength}s`
console.log( console.log(

49
bin/now-secrets.js

@ -31,8 +31,7 @@ const subcommand = argv._[0]
// Options // Options
const help = () => { const help = () => {
console.log( console.log(`
`
${chalk.bold(`${logo} now secrets`)} <ls | add | rename | rm> <secret> ${chalk.bold(`${logo} now secrets`)} <ls | add | rename | rm> <secret>
${chalk.dim('Options:')} ${chalk.dim('Options:')}
@ -70,8 +69,7 @@ const help = () => {
${chalk.gray('–')} Removes a secret: ${chalk.gray('–')} Removes a secret:
${chalk.cyan(`$ now secrets rm my-secret`)} ${chalk.cyan(`$ now secrets rm my-secret`)}
` `)
)
} }
// Options // Options
@ -87,7 +85,7 @@ if (argv.help || !subcommand) {
exit(0) exit(0)
} else { } else {
Promise.resolve().then(async () => { Promise.resolve().then(async () => {
const config = await cfg.read({token: argv.token}) const config = await cfg.read({ token: argv.token })
let token let token
try { try {
@ -113,18 +111,14 @@ async function run({ token, config: { currentTeam, user } }) {
if (subcommand === 'ls' || subcommand === 'list') { if (subcommand === 'ls' || subcommand === 'list') {
if (args.length !== 0) { if (args.length !== 0) {
error( error(`Invalid number of arguments. Usage: ${chalk.cyan('`now secret ls`')}`)
`Invalid number of arguments. Usage: ${chalk.cyan('`now secret ls`')}`
)
return exit(1) return exit(1)
} }
const list = await secrets.ls() const list = await secrets.ls()
const elapsed = ms(new Date() - start) const elapsed = ms(new Date() - start)
console.log( console.log(`> ${list.length} secret${list.length === 1 ? '' : 's'} found under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)} ${chalk.gray(`[${elapsed}]`)}`)
`> ${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) { if (list.length > 0) {
const cur = Date.now() const cur = Date.now()
@ -156,9 +150,7 @@ async function run({ token, config: { currentTeam, user } }) {
if (subcommand === 'rm' || subcommand === 'remove') { if (subcommand === 'rm' || subcommand === 'remove') {
if (args.length !== 1) { if (args.length !== 1) {
error( error(`Invalid number of arguments. Usage: ${chalk.cyan('`now secret rm <id | name>`')}`)
`Invalid number of arguments. Usage: ${chalk.cyan('`now secret rm <id | name>`')}`
)
return exit(1) return exit(1)
} }
const list = await secrets.ls() const list = await secrets.ls()
@ -179,38 +171,28 @@ async function run({ token, config: { currentTeam, user } }) {
const secret = await secrets.rm(args[0]) const secret = await secrets.rm(args[0])
const elapsed = ms(new Date() - start) const elapsed = ms(new Date() - start)
console.log( console.log(`${chalk.cyan('> Success!')} Secret ${chalk.bold(secret.name)} ${chalk.gray(`(${secret.uid})`)} removed ${chalk.gray(`[${elapsed}]`)}`)
`${chalk.cyan('> Success!')} Secret ${chalk.bold(secret.name)} ${chalk.gray(`(${secret.uid})`)} removed ${chalk.gray(`[${elapsed}]`)}`
)
return secrets.close() return secrets.close()
} }
if (subcommand === 'rename') { if (subcommand === 'rename') {
if (args.length !== 2) { if (args.length !== 2) {
error( error(`Invalid number of arguments. Usage: ${chalk.cyan('`now secret rename <old-name> <new-name>`')}`)
`Invalid number of arguments. Usage: ${chalk.cyan('`now secret rename <old-name> <new-name>`')}`
)
return exit(1) return exit(1)
} }
const secret = await secrets.rename(args[0], args[1]) const secret = await secrets.rename(args[0], args[1])
const elapsed = ms(new Date() - start) const elapsed = ms(new Date() - start)
console.log( console.log(`${chalk.cyan('> Success!')} Secret ${chalk.bold(secret.oldName)} ${chalk.gray(`(${secret.uid})`)} renamed to ${chalk.bold(args[1])} ${chalk.gray(`[${elapsed}]`)}`)
`${chalk.cyan('> Success!')} Secret ${chalk.bold(secret.oldName)} ${chalk.gray(`(${secret.uid})`)} renamed to ${chalk.bold(args[1])} ${chalk.gray(`[${elapsed}]`)}`
)
return secrets.close() return secrets.close()
} }
if (subcommand === 'add' || subcommand === 'set') { if (subcommand === 'add' || subcommand === 'set') {
if (args.length !== 2) { if (args.length !== 2) {
error( error(`Invalid number of arguments. Usage: ${chalk.cyan('`now secret add <name> <value>`')}`)
`Invalid number of arguments. Usage: ${chalk.cyan('`now secret add <name> <value>`')}`
)
if (args.length > 2) { if (args.length > 2) {
const example = chalk.cyan(`$ now secret add ${args[0]}`) const example = chalk.cyan(`$ now secret add ${args[0]}`)
console.log( console.log(`> If your secret has spaces, make sure to wrap it in quotes. Example: \n ${example} `)
`> If your secret has spaces, make sure to wrap it in quotes. Example: \n ${example} `
)
} }
return exit(1) return exit(1)
@ -228,9 +210,7 @@ async function run({ token, config: { currentTeam, user } }) {
const secret = await secrets.add(name, value) const secret = await secrets.add(name, value)
const elapsed = ms(new Date() - start) const elapsed = ms(new Date() - start)
console.log( 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}]`)}`)
`${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() return secrets.close()
} }
@ -255,9 +235,8 @@ function readConfirmation(secret) {
process.stdout.write('> The following secret will be removed permanently\n') process.stdout.write('> The following secret will be removed permanently\n')
process.stdout.write(' ' + tbl + '\n') process.stdout.write(' ' + tbl + '\n')
process.stdout.write( process.stdout
`${chalk.bold.red('> Are you sure?')} ${chalk.gray('[y/N] ')}` .write(`${chalk.bold.red('> Are you sure?')} ${chalk.gray('[y/N] ')}`)
)
process.stdin process.stdin
.on('data', d => { .on('data', d => {

22
bin/now-teams.js

@ -30,8 +30,7 @@ const argv = minimist(process.argv.slice(2), {
const subcommand = argv._[0] const subcommand = argv._[0]
const help = () => { const help = () => {
console.log( console.log(`
`
${chalk.bold(`${logo} now teams`)} <add | ls | rm | invite> ${chalk.bold(`${logo} now teams`)} <add | ls | rm | invite>
${chalk.dim('Options:')} ${chalk.dim('Options:')}
@ -68,8 +67,7 @@ const help = () => {
${chalk.cyan(`$ now teams rm <id>`)} ${chalk.cyan(`$ now teams rm <id>`)}
${chalk.gray('–')} If the id is omitted, you can choose interactively ${chalk.gray('–')} If the id is omitted, you can choose interactively
` `)
)
} }
// Options // Options
@ -85,7 +83,7 @@ if (argv.help || !subcommand) {
exit(0) exit(0)
} else { } else {
Promise.resolve().then(async () => { Promise.resolve().then(async () => {
const config = await cfg.read({token: argv.token}) const config = await cfg.read({ token: argv.token })
let token let token
try { try {
@ -115,17 +113,25 @@ async function run({ token, config: { currentTeam } }) {
switch (subcommand) { switch (subcommand) {
case 'switch': case 'switch':
case 'change': { case 'change': {
await require(resolve(__dirname, 'teams', 'switch.js'))({teams, args, token}) await require(resolve(__dirname, 'teams', 'switch.js'))({
teams,
args,
token
})
break break
} }
case 'add': case 'add':
case 'create': { case 'create': {
await require(resolve(__dirname, 'teams', 'add.js'))({teams, token}) await require(resolve(__dirname, 'teams', 'add.js'))({ teams, token })
break break
} }
case 'invite': { case 'invite': {
await require(resolve(__dirname, 'teams', 'invite.js'))({teams, args, token}) await require(resolve(__dirname, 'teams', 'invite.js'))({
teams,
args,
token
})
break break
} }

20
bin/now-upgrade.js

@ -31,8 +31,7 @@ const argv = minimist(process.argv.slice(2), {
}) })
const help = () => { const help = () => {
console.log( console.log(`
`
${chalk.bold(`${logo} now upgrade`)} [plan] ${chalk.bold(`${logo} now upgrade`)} [plan]
${chalk.dim('Options:')} ${chalk.dim('Options:')}
@ -55,8 +54,7 @@ const help = () => {
${chalk.gray('–')} Pick a specific plan (premium): ${chalk.gray('–')} Pick a specific plan (premium):
${chalk.cyan(`$ now upgrade premium`)} ${chalk.cyan(`$ now upgrade premium`)}
` `)
)
} }
// Options // Options
@ -80,7 +78,7 @@ if (argv.help) {
exit(0) exit(0)
} else { } else {
Promise.resolve().then(async () => { Promise.resolve().then(async () => {
const config = await cfg.read({token: argv.token}) const config = await cfg.read({ token: argv.token })
let token let token
try { try {
@ -213,9 +211,7 @@ async function run({ token, config: { currentTeam, user } }) {
newPlan = await plans.set(planId) newPlan = await plans.set(planId)
} catch (err) { } catch (err) {
if (err.code === 'customer_not_found' || err.code === 'source_not_found') { if (err.code === 'customer_not_found' || err.code === 'source_not_found') {
error( error(`You have no payment methods available. Run ${cmd('now billing add')} to add one`)
`You have no payment methods available. Run ${cmd('now billing add')} to add one`
)
} else { } else {
error(`An unknow error occured. Please try again later ${err.message}`) error(`An unknow error occured. Please try again later ${err.message}`)
} }
@ -224,13 +220,9 @@ async function run({ token, config: { currentTeam, user } }) {
} }
if (currentPlan.until && newPlan.id !== 'oss') { if (currentPlan.until && newPlan.id !== 'oss') {
success( success(`The cancelation has been undone. You're back on the ${chalk.bold(`${newPlan.name} plan`)}`)
`The cancelation has been undone. You're back on the ${chalk.bold(`${newPlan.name} plan`)}`
)
} else if (newPlan.until) { } else if (newPlan.until) {
success( success(`Your plan will be switched to ${chalk.bold(newPlan.name)} in ${chalk.bold(newPlan.until)}. Your card will not be charged again`)
`Your plan will be switched to ${chalk.bold(newPlan.name)} in ${chalk.bold(newPlan.until)}. Your card will not be charged again`
)
} else { } else {
success(`You're now on the ${chalk.bold(`${newPlan.name} plan`)}`) success(`You're now on the ${chalk.bold(`${newPlan.name} plan`)}`)
} }

10
bin/teams/add.js

@ -25,24 +25,20 @@ function validateSlugKeypress(data, value) {
function gracefulExit() { function gracefulExit() {
console.log() // Blank line console.log() // Blank line
note( note(`Your team is now active for all ${cmd('now')} commands!\n Run ${cmd('now switch')} to change it in the future.`)
`Your team is now active for all ${cmd('now')} commands!\n Run ${cmd('now switch')} to change it in the future.`
)
return exit() return exit()
} }
const teamUrlPrefix = rightPad('Team URL', 14) + chalk.gray('zeit.co/') const teamUrlPrefix = rightPad('Team URL', 14) + chalk.gray('zeit.co/')
const teamNamePrefix = rightPad('Team Name', 14) const teamNamePrefix = rightPad('Team Name', 14)
module.exports = async function({teams, token}) { module.exports = async function({ teams, token }) {
let slug let slug
let team let team
let elapsed let elapsed
let stopSpinner let stopSpinner
info( info(`Pick a team identifier for its url (e.g.: ${chalk.cyan('`zeit.co/acme`')})`)
`Pick a team identifier for its url (e.g.: ${chalk.cyan('`zeit.co/acme`')})`
)
do { do {
try { try {
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop

11
bin/teams/invite.js

@ -60,13 +60,10 @@ function emailAutoComplete(value, teamSlug) {
return false return false
} }
module.exports = async function({ module.exports = async function(
teams, { teams, args, token, introMsg, noopMsg = 'No changes made' } = {}
args, ) {
token, const { user, currentTeam } = await cfg.read({ token })
introMsg, noopMsg = 'No changes made'
} = {}) {
const { user, currentTeam } = await cfg.read({token})
domains.push(user.email.split('@')[1]) domains.push(user.email.split('@')[1])

4
bin/teams/switch.js

@ -15,10 +15,10 @@ async function updateCurrentTeam({ cfg, newTeam } = {}) {
await cfg.merge({ currentTeam: newTeam }) await cfg.merge({ currentTeam: newTeam })
} }
module.exports = async function({teams, args, token}) { module.exports = async function({ teams, args, token }) {
let stopSpinner = wait('Fetching teams') let stopSpinner = wait('Fetching teams')
const list = (await teams.ls()).teams const list = (await teams.ls()).teams
let { user, currentTeam } = await cfg.read({token}) let { user, currentTeam } = await cfg.read({ token })
const accountIsCurrent = !currentTeam const accountIsCurrent = !currentTeam
stopSpinner() stopSpinner()

2
lib/cfg.js

@ -47,7 +47,7 @@ async function read({ force = false, token, apiUrl } = {}) {
// Will happen if `force`d or if `--token` is used and it's different from // Will happen if `force`d or if `--token` is used and it's different from
// The one that's stored (which can be `undefined`) // The one that's stored (which can be `undefined`)
if ((force && token) || (token && token !== existing.token) ) { if ((force && token) || (token && token !== existing.token)) {
const user = await getUser({ token, apiUrl }) const user = await getUser({ token, apiUrl })
if (user) { if (user) {
return { return {

4
lib/domains.js

@ -72,9 +72,7 @@ module.exports = class Domains extends Now {
} }
if (this._debug) { if (this._debug) {
console.log( console.log(`> [debug] Supplied domain "${domain}" has non-zeit nameservers`)
`> [debug] Supplied domain "${domain}" has non-zeit nameservers`
)
} }
const err3 = new Error(DNS_VERIFICATION_ERROR) const err3 = new Error(DNS_VERIFICATION_ERROR)

42
lib/index.js

@ -273,18 +273,12 @@ module.exports = class Now extends EventEmitter {
if (!quiet && deploymentType === 'npm' && deployment.nodeVersion) { if (!quiet && deploymentType === 'npm' && deployment.nodeVersion) {
if (engines && engines.node) { if (engines && engines.node) {
if (missingVersion) { if (missingVersion) {
console.log( console.log(`> Using Node.js ${chalk.bold(deployment.nodeVersion)} (default)`)
`> Using Node.js ${chalk.bold(deployment.nodeVersion)} (default)`
)
} else { } else {
console.log( console.log(`> Using Node.js ${chalk.bold(deployment.nodeVersion)} (requested: ${chalk.dim(`\`${engines.node}\``)})`)
`> Using Node.js ${chalk.bold(deployment.nodeVersion)} (requested: ${chalk.dim(`\`${engines.node}\``)})`
)
} }
} else { } else {
console.log( console.log(`> Using Node.js ${chalk.bold(deployment.nodeVersion)} (default)`)
`> Using Node.js ${chalk.bold(deployment.nodeVersion)} (default)`
)
} }
} }
@ -349,9 +343,7 @@ module.exports = class Now extends EventEmitter {
}) })
if (this._debug) { if (this._debug) {
console.timeEnd( console.timeEnd(`> [debug] /sync #${attempt} ${names.join(' ')}`)
`> [debug] /sync #${attempt} ${names.join(' ')}`
)
} }
// No retry on 4xx // No retry on 4xx
@ -441,9 +433,8 @@ module.exports = class Now extends EventEmitter {
console.time(`> [debug] /deployments/${deploymentId}/instances`) console.time(`> [debug] /deployments/${deploymentId}/instances`)
} }
const res = await this._fetch( const res = await this
`/now/deployments/${deploymentId}/instances` ._fetch(`/now/deployments/${deploymentId}/instances`)
)
if (this._debug) { if (this._debug) {
console.timeEnd(`> [debug] /deployments/${deploymentId}/instances`) console.timeEnd(`> [debug] /deployments/${deploymentId}/instances`)
@ -626,19 +617,14 @@ module.exports = class Now extends EventEmitter {
this.retry(async (bail, attempt) => { this.retry(async (bail, attempt) => {
if (this._debug) { if (this._debug) {
console.time( console.time(`> [debug] #${attempt} GET /whois-ns${fallback ? '-fallback' : ''}`)
`> [debug] #${attempt} GET /whois-ns${fallback ? '-fallback' : ''}`
)
} }
const res = await this._fetch( const res = await this
`/whois-ns${fallback ? '-fallback' : ''}?domain=${encodeURIComponent(domain)}` ._fetch(`/whois-ns${fallback ? '-fallback' : ''}?domain=${encodeURIComponent(domain)}`)
)
if (this._debug) { if (this._debug) {
console.timeEnd( console.timeEnd(`> [debug] #${attempt} GET /whois-ns${fallback ? '-fallback' : ''}`)
`> [debug] #${attempt} GET /whois-ns${fallback ? '-fallback' : ''}`
)
} }
const body = await res.json() const body = await res.json()
@ -904,9 +890,7 @@ module.exports = class Now extends EventEmitter {
setScale(nameOrId, scale) { setScale(nameOrId, scale) {
return this.retry(async (bail, attempt) => { return this.retry(async (bail, attempt) => {
if (this._debug) { if (this._debug) {
console.time( console.time(`> [debug] #${attempt} POST /deployments/${nameOrId}/instances`)
`> [debug] #${attempt} POST /deployments/${nameOrId}/instances`
)
} }
const res = await this._fetch(`/now/deployments/${nameOrId}/instances`, { const res = await this._fetch(`/now/deployments/${nameOrId}/instances`, {
@ -915,9 +899,7 @@ module.exports = class Now extends EventEmitter {
}) })
if (this._debug) { if (this._debug) {
console.timeEnd( console.timeEnd(`> [debug] #${attempt} POST /deployments/${nameOrId}/instances`)
`> [debug] #${attempt} POST /deployments/${nameOrId}/instances`
)
} }
if (res.status === 403) { if (res.status === 403) {

8
lib/login.js

@ -74,14 +74,10 @@ async function register(url, { retryEmail = false } = {}) {
} }
const { token, securityCode } = await getVerificationData(url, email) const { token, securityCode } = await getVerificationData(url, email)
console.log( console.log(`> Please follow the link sent to ${chalk.bold(email)} to log in.`)
`> Please follow the link sent to ${chalk.bold(email)} to log in.`
)
if (securityCode) { if (securityCode) {
console.log( console.log(`> Verify that the provided security code in the email matches ${chalk.cyan(chalk.bold(securityCode))}.`)
`> Verify that the provided security code in the email matches ${chalk.cyan(chalk.bold(securityCode))}.`
)
} }
process.stdout.write('\n') process.stdout.write('\n')

22
lib/re-alias.js

@ -21,13 +21,17 @@ exports.assignAlias = async (
user user
) => { ) => {
const aliases = new NowAlias({ apiUrl, token, debug, currentTeam }) const aliases = new NowAlias({ apiUrl, token, debug, currentTeam })
const domains = new NowDomains({apiUrl, token, debug, currentTeam}) const domains = new NowDomains({ apiUrl, token, debug, currentTeam })
console.log( console.log(`> Assigning alias ${chalk.bold.underline(autoAlias)} to deployment...`)
`> Assigning alias ${chalk.bold.underline(autoAlias)} to deployment...`
)
// Assign alias // Assign alias
await aliases.set(String(deployment), String(autoAlias), domains, currentTeam, user) await aliases.set(
String(deployment),
String(autoAlias),
domains,
currentTeam,
user
)
} }
exports.reAlias = async ( exports.reAlias = async (
@ -50,9 +54,7 @@ exports.reAlias = async (
} }
if (!fs.existsSync(configFiles.pkg) && !fs.existsSync(configFiles.nowJSON)) { if (!fs.existsSync(configFiles.pkg) && !fs.existsSync(configFiles.nowJSON)) {
error( error(`Couldn't find a now.json or package.json file with an alias list in it`)
`Couldn't find a now.json or package.json file with an alias list in it`
)
return return
} }
@ -84,9 +86,7 @@ exports.reAlias = async (
} else if (Array.isArray(value)) { } else if (Array.isArray(value)) {
pointers = pointers.concat(nowConfig.alias) pointers = pointers.concat(nowConfig.alias)
} else { } else {
error( error(`Property ${chalk.grey('aliases')} is not a valid array or string`)
`Property ${chalk.grey('aliases')} is not a valid array or string`
)
return exit(1) return exit(1)
} }
} }

4
lib/scale-info.js

@ -52,9 +52,7 @@ module.exports = async function(now, url) {
if (barcurr === targetReplicaCount) { if (barcurr === targetReplicaCount) {
linelog.clear() linelog.clear()
linelog( linelog(`> Scaled to ${chalk.bold(String(targetReplicaCount) + (targetReplicaCount === 1 ? ' instance' : ' instances'))}: ${chalk.gray('[' + ms(Date.now() - startTime) + ']')}\n`)
`> Scaled to ${chalk.bold(String(targetReplicaCount) + (targetReplicaCount === 1 ? ' instance' : ' instances'))}: ${chalk.gray('[' + ms(Date.now() - startTime) + ']')}\n`
)
return res return res
} }
} }

4
lib/scale.js

@ -13,9 +13,7 @@ module.exports = class Scale extends Now {
}) })
if (this._debug) { if (this._debug) {
console.timeEnd( console.timeEnd(`> [debug] #${attempt} GET /deployments/${id}/instances`)
`> [debug] #${attempt} GET /deployments/${id}/instances`
)
} }
if (res.status === 403) { if (res.status === 403) {

Loading…
Cancel
Save