Browse Source

Re-alias when running `now alias`

master
Leo Lamprecht 8 years ago
parent
commit
8cde1663c5
No known key found for this signature in database GPG Key ID: B08517883D5E0E10
  1. 6
      bin/now-alias.js
  2. 2
      bin/now-deploy.js
  3. 20
      lib/re-alias.js

6
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) {

2
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)
}
}

20
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)
}
}

Loading…
Cancel
Save