Browse Source

Fix path alias updates (#493)

* Catch path alias changes correctly
Fixes #492

* And the automatic petteier changes for alias
master
Jarmo Isotalo 8 years ago
committed by Matheus Fernandes
parent
commit
9e22ad34d2
  1. 64
      bin/now-alias.js

64
bin/now-alias.js

@ -35,8 +35,7 @@ const subcommand = argv._[0]
// Options
const help = () => {
console.log(
`
console.log(`
${chalk.bold(`${logo} now alias`)} <ls | set | rm> <deployment> <alias>
${chalk.dim('Options:')}
@ -89,8 +88,7 @@ const help = () => {
To get the list of alias ids, use ${chalk.dim('`now alias ls`')}.
${chalk.dim('Alias:')} ln
`
)
`)
}
// Options
@ -177,9 +175,7 @@ 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)
}
@ -204,9 +200,7 @@ async function run({ token, config: { currentTeam, user } }) {
if (urls.get(target)) {
_sourceUrl = chalk.underline(`https://${urls.get(target)}`)
} 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' : ''}]`)
} else {
_sourceUrl = chalk.gray('<null>')
}
@ -233,9 +227,7 @@ async function run({ token, config: { currentTeam, user } }) {
)
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)}`)
if (text) {
console.log('\n' + text + '\n')
@ -253,9 +245,7 @@ async function run({ token, config: { currentTeam, user } }) {
}
if (args.length !== 1) {
error(
`Invalid number of arguments. Usage: ${chalk.cyan('`now alias rm <id>`')}`
)
error(`Invalid number of arguments. Usage: ${chalk.cyan('`now alias rm <id>`')}`)
return exit(1)
}
@ -280,9 +270,7 @@ 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)
@ -297,17 +285,37 @@ async function run({ token, config: { currentTeam, user } }) {
break
}
if (args.length !== 2) {
error(
`Invalid number of arguments. Usage: ${chalk.cyan('`now alias set <id> <domain>`')}`
)
error(`Invalid number of arguments. Usage: ${chalk.cyan('`now alias set <id> <domain>`')}`)
return exit(1)
}
await alias.set(String(args[0]), String(args[1]), domains, currentTeam, user)
await alias.set(
String(args[0]),
String(args[1]),
domains,
currentTeam,
user
)
break
}
default: {
if (argv._.length === 0) {
await reAlias(token, null, null, help, exit, apiUrl, debug, alias, currentTeam, user)
await reAlias(
token,
null,
null,
help,
exit,
apiUrl,
debug,
alias,
currentTeam,
user
)
break
}
if (argv.rules) {
await updatePathAlias(alias, argv._[0], argv.rules, domains)
break
}
@ -325,10 +333,6 @@ async function run({ token, config: { currentTeam, user } }) {
user
)
break
}
if (argv.rules) {
await updatePathAlias(alias, argv._[0], argv.rules, domains)
} else if (argv._.length === 2) {
await alias.set(
String(argv._[0]),
@ -424,8 +428,6 @@ 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}]`)
}
}

Loading…
Cancel
Save