From 25fef39f1a2051c66b2c444cea23cd57f53eb3e5 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Sat, 3 Dec 2016 12:41:08 +0100 Subject: [PATCH] Ability to set name This closes #150 --- bin/now-deploy.js | 11 +++++++++-- lib/index.js | 2 ++ lib/read-metadata.js | 33 +++++++++++++++++++++------------ 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/bin/now-deploy.js b/bin/now-deploy.js index 896c10e..7935a84 100755 --- a/bin/now-deploy.js +++ b/bin/now-deploy.js @@ -27,7 +27,8 @@ import readMetaData from '../lib/read-metadata' const argv = minimist(process.argv.slice(2), { string: [ 'config', - 'token' + 'token', + 'name' ], boolean: [ 'help', @@ -53,7 +54,8 @@ const argv = minimist(process.argv.slice(2), { login: 'L', public: 'p', 'no-clipboard': 'C', - 'forward-npm': 'N' + 'forward-npm': 'N', + name: 'n' } }) @@ -76,6 +78,7 @@ const help = () => { -h, --help Output usage information -v, --version Output the version number + -n, --name Set the name of the deployment -c ${chalk.underline('FILE')}, --config=${chalk.underline('FILE')} Config file -d, --debug Debug mode [off] -f, --force Force a new deployment even if nothing has changed @@ -149,6 +152,7 @@ const forceNew = argv.force const forceSync = argv.forceSync const shouldLogin = argv.login const wantsPublic = argv.public +const deploymentName = argv.name || false const apiUrl = argv.url || 'https://api.zeit.co' const isTTY = process.stdout.isTTY const quiet = !isTTY @@ -337,6 +341,7 @@ async function sync(token) { const {pkg: {now: pkgConfig = {}} = {}} = await readMetaData(path, { deploymentType, + deploymentName, isStatic, quiet: true }) @@ -366,6 +371,7 @@ async function sync(token) { error('Env key and value missing') return process.exit(1) } + const [key, ...rest] = kv.split('=') let val @@ -433,6 +439,7 @@ async function sync(token) { await now.create(path, { env, deploymentType, + deploymentName, forceNew, forceSync, forwardNpm: alwaysForwardNpm || forwardNpm, diff --git a/lib/index.js b/lib/index.js index d97609b..e29eced 100644 --- a/lib/index.js +++ b/lib/index.js @@ -44,6 +44,7 @@ export default class Now extends EventEmitter { forceSync = false, forwardNpm = false, deploymentType = 'npm', + deploymentName, isStatic = false }) { this._path = path @@ -53,6 +54,7 @@ export default class Now extends EventEmitter { const {pkg, name, description} = await readMetaData(path, { deploymentType, + deploymentName, quiet, isStatic }) diff --git a/lib/read-metadata.js b/lib/read-metadata.js index c76d5d4..579aab0 100644 --- a/lib/read-metadata.js +++ b/lib/read-metadata.js @@ -15,6 +15,7 @@ const listPackage = { export default async function (path, { deploymentType = 'npm', + deploymentName, quiet = false, isStatic = false }) { @@ -44,13 +45,15 @@ export default async function (path, { throw e } - if (typeof pkg.name === 'string') { - name = pkg.name - } else { - name = basename(path) + if (!deploymentName) { + if (typeof pkg.name === 'string') { + name = pkg.name + } else { + name = basename(path) - if (!quiet && !isStatic) { - console.log(`> No \`name\` in \`package.json\`, using ${chalk.bold(name)}`) + if (!quiet && !isStatic) { + console.log(`> No \`name\` in \`package.json\`, using ${chalk.bold(name)}`) + } } } @@ -106,19 +109,25 @@ export default async function (path, { } }) - if (labels.name) { - name = labels.name - } else { - name = basename(path) + if (!deploymentName) { + if (labels.name) { + name = labels.name + } else { + name = basename(path) - if (!quiet) { - console.log(`> No \`name\` LABEL in \`Dockerfile\`, using ${chalk.bold(name)}`) + if (!quiet) { + console.log(`> No \`name\` LABEL in \`Dockerfile\`, using ${chalk.bold(name)}`) + } } } description = labels.description } + if (deploymentName) { + name = deploymentName + } + return { name, description,