Browse Source

Determine deployment type like Now Desktop (#589)

* Automatically decide deployment type

* Should be a devDep

* Not throwing anymore if both Dockerfile and package.json exist

* Ask to choose type again

* Revert "Not throwing anymore if both Dockerfile and package.json exist"

This reverts commit 2d7136f2dc870406e60289e33de3b2beaea3a917.

* Prettified
master
Leo Lamprecht 8 years ago
committed by GitHub
parent
commit
7845b34b2b
  1. 27
      lib/read-metadata.js
  2. 1
      package.json

27
lib/read-metadata.js

@ -5,6 +5,7 @@ const { basename, resolve: resolvePath } = require('path')
const chalk = require('chalk')
const { readFile } = require('fs-extra')
const { parse: parseDockerfile } = require('docker-file-parser')
const determineType = require('deployment-type')
module.exports = readMetaData
@ -40,32 +41,20 @@ async function readMetaData(
}
if (!type) {
// `now.json` / `pkg.now` get default type preference
if (nowConfig) {
type = nowConfig.type
}
type = await determineType(path)
// Both `package.json` and `Dockerfile` exist! Prompt the user to pick one.
if (!type && pkg && dockerfile) {
// We can remove this soon (details are internal)
if (type === 'docker' && (pkg && dockerfile)) {
const err = new Error(
'Ambiguous deployment (`package.json` and `Dockerfile` found). ' +
'Please supply `--npm` or `--docker` to disambiguate.'
)
err.userError = true
err.code = 'MULTIPLE_MANIFESTS'
throw err
}
if (!type && pkg) {
type = 'npm'
}
if (!type && dockerfile) {
type = 'docker'
}
if (!type) {
type = 'static'
throw err
}
}
@ -78,16 +67,19 @@ async function readMetaData(
if (!name && pkg.name) {
name = String(pkg.name)
}
description = pkg.description
}
} else if (type === 'docker') {
if (strict && dockerfile.length <= 0) {
const err = new Error('No commands found in `Dockerfile`')
err.userError = true
throw err
}
const labels = {}
dockerfile.filter(cmd => cmd.name === 'LABEL').forEach(({ args }) => {
for (const key in args) {
if (!{}.hasOwnProperty.call(args, key)) {
@ -101,6 +93,7 @@ async function readMetaData(
const e = new Error(
`Error parsing value for LABEL ${key} in \`Dockerfile\``
)
e.userError = true
throw e
}

1
package.json

@ -73,6 +73,7 @@
"cross-spawn": "5.1.0",
"dateformat": "2.0.0",
"death": "1.1.0",
"deployment-type": "1.0.1",
"docker-file-parser": "1.0.2",
"dotenv": "4.0.0",
"download": "6.2.0",

Loading…
Cancel
Save