Browse Source

Require `--alias` for all existing kinds of automatic aliasing

master
Leo Lamprecht 8 years ago
parent
commit
add7bcfbea
No known key found for this signature in database GPG Key ID: B08517883D5E0E10
  1. 29
      bin/now-alias.js
  2. 51
      bin/now-deploy.js

29
bin/now-alias.js

@ -13,7 +13,6 @@ const login = require('../lib/login')
const cfg = require('../lib/cfg')
const {error} = require('../lib/error')
const toHost = require('../lib/to-host')
const readMetaData = require('../lib/read-metadata')
const argv = minimist(process.argv.slice(2), {
string: ['config', 'token'],
@ -213,11 +212,6 @@ async function run(token) {
break
}
default: {
if (argv._.length === 0) {
await realias(alias)
break
}
if (argv._.length === 2) {
await alias.set(String(argv._[0]), String(argv._[1]))
} else if (argv._.length >= 3) {
@ -293,26 +287,3 @@ function findAlias(alias, list) {
return _alias
}
async function realias(alias) {
const path = process.cwd()
const {nowConfig, name} = await readMetaData(path, {
deploymentType: 'npm', // hard coding settings…
quiet: true // `quiet`
})
const targets = nowConfig && nowConfig.aliases
// the user never intended to support aliases from the package
if (!targets || !Array.isArray(targets)) {
help()
return exit(0)
}
// now try to find the last deployment
const source = await alias.last(name)
for (const target of targets) {
await alias.set(source.url, target)
}
}

51
bin/now-deploy.js

@ -1,7 +1,7 @@
#!/usr/bin/env node
// Native
const {resolve} = require('path')
const {resolve, join} = require('path')
// Packages
const Progress = require('progress')
@ -98,7 +98,7 @@ const help = () => {
-e, --env Include an env var (e.g.: ${chalk.dim('`-e KEY=value`')}). Can appear many times.
-C, --no-clipboard Do not attempt to copy URL to clipboard
-N, --forward-npm Forward login information to install private npm modules
-a, --alias Reassign an existing alias to the deployment
-a, --alias Re-assign existing aliases to the deployment
${chalk.dim('Enforcable Types (when both package.json and Dockerfile exist):')}
@ -168,7 +168,7 @@ const deploymentName = argv.name || false
const apiUrl = argv.url || 'https://api.zeit.co'
const isTTY = process.stdout.isTTY
const quiet = !isTTY
const autoAliases = argv.alias ? flatten([argv.alias]) : []
const autoAliases = typeof argv.alias === 'undefined' ? false : flatten([argv.alias])
if (argv.config) {
cfg.setConfigFile(argv.config)
@ -263,7 +263,7 @@ async function sync(token) {
}
}
// Make sure that directory is not too big
// Make sure that directory is deployable
await checkPath(path)
if (!quiet) {
@ -588,13 +588,52 @@ const assignAlias = async (autoAlias, token, deployment) => {
await aliases.set(String(deployment), String(related.alias))
}
async function realias(token, host) {
const path = process.cwd()
const configFiles = {
pkg: join(path, 'package.json'),
nowJSON: join(path, 'now.json')
}
if (!fs.existsSync(configFiles.pkg) && !fs.existsSync(configFiles.nowJSON)) {
error(`Couldn't find a now.json or package.json file with an alias list in it`)
return
}
const {nowConfig} = await readMetaData(path, {
deploymentType: 'npm', // hard coding settings…
quiet: true // `quiet`
})
const targets = nowConfig && nowConfig.aliases
// the user never intended to support aliases from the package
if (!targets || !Array.isArray(targets)) {
help()
return exit(0)
}
for (const target of targets) {
await assignAlias(target, token, host)
}
}
function printLogs(host, token) {
// log build
const logger = new Logger(host, {debug, quiet})
logger.on('close', async () => {
for (const autoAlias of autoAliases) {
await assignAlias(autoAlias, token, host)
if (Array.isArray(autoAliases)) {
const aliasList = autoAliases.filter(item => item !== '')
if (aliasList.length > 0) {
for (const alias of aliasList) {
await assignAlias(alias, token, host)
}
} else {
await realias(token, host)
}
}
if (!quiet) {

Loading…
Cancel
Save