Browse Source

Don't throw an error if alias doesn't exist

master
Leo Lamprecht 8 years ago
parent
commit
c545968ff6
No known key found for this signature in database GPG Key ID: B08517883D5E0E10
  1. 32
      lib/re-alias.js

32
lib/re-alias.js

@ -3,7 +3,6 @@ const {join} = require('path')
// Packages
const fs = require('fs-promise')
const publicSuffixList = require('psl')
const chalk = require('chalk')
// Ours
@ -12,38 +11,11 @@ const readMetaData = require('./read-metadata')
const NowAlias = require('./alias')
exports.assignAlias = async (autoAlias, token, deployment, apiUrl, debug) => {
const type = publicSuffixList.isValid(autoAlias) ? 'alias' : 'uid'
const aliases = new NowAlias(apiUrl, token, {debug})
const list = await aliases.ls()
let related
// Check if alias even exists
for (const alias of list) {
if (alias[type] === autoAlias) {
related = alias
break
}
}
// If alias doesn't exist
if (!related) {
// Check if the uid was actually an alias
if (type === 'uid') {
return exports.assignAlias(`${autoAlias}.now.sh`, token, deployment)
}
// If not, throw an error
const withID = type === 'uid' ? 'with ID ' : ''
error(`Alias ${withID}"${autoAlias}" doesn't exist`)
return
}
console.log(`> Assigning alias ${chalk.bold.underline(related.alias)} to deployment...`)
console.log(`> Assigning alias ${chalk.bold.underline(autoAlias)} to deployment...`)
// Assign alias
await aliases.set(String(deployment), String(related.alias))
await aliases.set(String(deployment), String(autoAlias))
}
exports.reAlias = async (token, host, help, exit) => {

Loading…
Cancel
Save