Browse Source

Ability to automatically assign an alias

master
Leo Lamprecht 8 years ago
parent
commit
68a53c67f2
No known key found for this signature in database GPG Key ID: B08517883D5E0E10
  1. 9
      bin/now-deploy.js

9
bin/now-deploy.js

@ -546,12 +546,13 @@ async function sync(token) {
} }
} }
const assignAlias = async token => { const assignAlias = async (token, deployment) => {
const aliases = new NowAlias(apiUrl, token, {debug}) const aliases = new NowAlias(apiUrl, token, {debug})
const list = await aliases.ls() const list = await aliases.ls()
let related let related
// Check if alias even exists
for (const alias of list) { for (const alias of list) {
if (alias.alias === autoAlias) { if (alias.alias === autoAlias) {
related = alias related = alias
@ -559,12 +560,16 @@ const assignAlias = async token => {
} }
} }
// Throw an error if it doesn't
if (!related) { if (!related) {
error(`Alias "${autoAlias}" doesn't exist`) error(`Alias "${autoAlias}" doesn't exist`)
return return
} }
console.log(`> Assigning alias "${autoAlias}" to deployment...`) console.log(`> Assigning alias "${autoAlias}" to deployment...`)
// Assign alias
await aliases.set(String(deployment), String(related.alias))
} }
function printLogs(host, token) { function printLogs(host, token) {
@ -573,7 +578,7 @@ function printLogs(host, token) {
logger.on('close', async () => { logger.on('close', async () => {
if (autoAlias) { if (autoAlias) {
await assignAlias(token) await assignAlias(token, host)
} }
if (!quiet) { if (!quiet) {

Loading…
Cancel
Save