Skip to content

Commit

Permalink
Require --alias for all existing kinds of automatic aliasing
Browse files Browse the repository at this point in the history
  • Loading branch information
leo committed Jan 28, 2017
1 parent 7ccb4de commit add7bcf
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 35 deletions.
29 changes: 0 additions & 29 deletions bin/now-alias.js
Expand Up @@ -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'],
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 changes: 45 additions & 6 deletions 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')
Expand Down Expand Up @@ -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):')}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit add7bcf

Please sign in to comment.