Browse Source

copy alias to clipboard & show message (#201)

* copy alias to clipboard & show message

* ensure status output if not ttys or cant copy
master
Luke Edwards 8 years ago
committed by Leo Lamprecht
parent
commit
c584f42791
  1. 25
      lib/alias.js

25
lib/alias.js

@ -1,14 +1,23 @@
// Packages
import publicSuffixList from 'psl'
import minimist from 'minimist'
import chalk from 'chalk'
// Ours
import copy from './copy'
import toHost from './to-host'
import resolve4 from './dns'
import isZeitWorld from './is-zeit-world'
import {DOMAIN_VERIFICATION_ERROR} from './errors'
import Now from './'
const argv = minimist(process.argv.slice(2), {
boolean: ['no-clipboard'],
alias: {'no-clipboard': 'C'}
})
const isTTY = process.stdout.isTTY
const clipboard = !argv['no-clipboard']
const domainRegex = /^((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}$/
export default class Alias extends Now {
@ -234,7 +243,21 @@ export default class Alias extends Now {
}
const {created, uid} = newAlias
if (created) {
console.log(`${chalk.cyan('> Success!')} Alias created ${chalk.dim(`(${uid})`)}: ${chalk.bold(chalk.underline(`https://${alias}`))} now points to ${chalk.bold(`https://${depl.url}`)} ${chalk.dim(`(${depl.uid})`)}`)
const pretty = `https://${alias}`
const output = `${chalk.cyan('> Success!')} Alias created ${chalk.dim(`(${uid})`)}: ${chalk.bold(chalk.underline(pretty))} now points to ${chalk.bold(`https://${depl.url}`)} ${chalk.dim(`(${depl.uid})`)}`
if (isTTY && clipboard) {
let append
try {
await copy(pretty)
append = '[copied to clipboard]'
} catch (err) {
append = ''
} finally {
console.log(`${output} ${append}`)
}
} else {
console.log(output)
}
} else {
console.log(`${chalk.cyan('> Success!')} Alias already exists ${chalk.dim(`(${uid})`)}.`)
}

Loading…
Cancel
Save