From 8cde1663c525e054d457f4afe2034d79d1a6bbc7 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Fri, 10 Feb 2017 23:35:39 +0100 Subject: [PATCH] Re-alias when running `now alias` --- bin/now-alias.js | 6 ++++++ bin/now-deploy.js | 2 +- lib/re-alias.js | 20 ++++++++++++-------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/bin/now-alias.js b/bin/now-alias.js index eea5445..bb4221f 100755 --- a/bin/now-alias.js +++ b/bin/now-alias.js @@ -13,6 +13,7 @@ const login = require('../lib/login') const cfg = require('../lib/cfg') const {error} = require('../lib/error') const toHost = require('../lib/to-host') +const {reAlias} = require('../lib/re-alias') const argv = minimist(process.argv.slice(2), { string: ['config', 'token'], @@ -212,6 +213,11 @@ async function run(token) { break } default: { + if (argv._.length === 0) { + await reAlias(token, null, help, exit, apiUrl, debug, alias) + break + } + if (argv._.length === 2) { await alias.set(String(argv._[0]), String(argv._[1])) } else if (argv._.length >= 3) { diff --git a/bin/now-deploy.js b/bin/now-deploy.js index 784ab8c..049fd6b 100755 --- a/bin/now-deploy.js +++ b/bin/now-deploy.js @@ -603,7 +603,7 @@ function printLogs(host, token) { await assignAlias(alias, token, host, apiUrl, debug) } } else { - await reAlias(token, host, help, exit) + await reAlias(token, host, help, exit, apiUrl, debug) } } diff --git a/lib/re-alias.js b/lib/re-alias.js index f11f241..3cb26f0 100644 --- a/lib/re-alias.js +++ b/lib/re-alias.js @@ -18,7 +18,7 @@ exports.assignAlias = async (autoAlias, token, deployment, apiUrl, debug) => { await aliases.set(String(deployment), String(autoAlias)) } -exports.reAlias = async (token, host, help, exit) => { +exports.reAlias = async (token, host, help, exit, apiUrl, debug, alias) => { const path = process.cwd() const configFiles = { @@ -31,11 +31,16 @@ exports.reAlias = async (token, host, help, exit) => { return } - const {nowConfig} = await readMetaData(path, { + const {nowConfig, name} = await readMetaData(path, { deploymentType: 'npm', // hard coding settingsā€¦ quiet: true // `quiet` }) + if (!host) { + const lastAlias = await alias.last(name) + host = lastAlias.url + } + if (!nowConfig) { help() return exit(0) @@ -48,13 +53,12 @@ exports.reAlias = async (token, host, help, exit) => { if (typeof value === 'string') { pointers.push(value) - } - - if (Array.isArray(value)) { + } else if (Array.isArray(value)) { pointers = pointers.concat(nowConfig.alias) + } else { + error(`Property ${chalk.grey('aliases')} is not a valid array or string`) + return exit(1) } - - error(`Property ${chalk.grey('aliases')} is not a valid array or string`) } if (nowConfig.aliases && Array.isArray(nowConfig.aliases)) { @@ -71,6 +75,6 @@ exports.reAlias = async (token, host, help, exit) => { } for (const pointer of pointers) { - await exports.assignAlias(pointer, token, host) + await exports.assignAlias(pointer, token, host, apiUrl, debug) } }