Browse Source

Ability to set name

This closes #150
master
Leo Lamprecht 8 years ago
parent
commit
25fef39f1a
No known key found for this signature in database GPG Key ID: B08517883D5E0E10
  1. 11
      bin/now-deploy.js
  2. 2
      lib/index.js
  3. 33
      lib/read-metadata.js

11
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,

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

33
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,

Loading…
Cancel
Save