From 68a53c67f2ec188cf7a232bef475df9f0791f05d Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Thu, 15 Dec 2016 10:25:26 +0100 Subject: [PATCH] Ability to automatically assign an alias --- bin/now-deploy.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/now-deploy.js b/bin/now-deploy.js index 61c98d5..21bfcf1 100755 --- a/bin/now-deploy.js +++ b/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 list = await aliases.ls() let related + // Check if alias even exists for (const alias of list) { if (alias.alias === autoAlias) { related = alias @@ -559,12 +560,16 @@ const assignAlias = async token => { } } + // Throw an error if it doesn't if (!related) { error(`Alias "${autoAlias}" doesn't exist`) return } console.log(`> Assigning alias "${autoAlias}" to deployment...`) + + // Assign alias + await aliases.set(String(deployment), String(related.alias)) } function printLogs(host, token) { @@ -573,7 +578,7 @@ function printLogs(host, token) { logger.on('close', async () => { if (autoAlias) { - await assignAlias(token) + await assignAlias(token, host) } if (!quiet) {