Browse Source

initial `now.json` support

master
Nathan Rajlich 8 years ago
parent
commit
4c9caa420b
  1. 5
      bin/now-alias.js
  2. 4
      bin/now-deploy.js
  3. 8
      lib/index.js
  4. 21
      lib/read-metadata.js

5
bin/now-alias.js

@ -296,13 +296,12 @@ function findAlias(alias, list) {
async function realias(alias) {
const path = process.cwd()
const {pkg, name} = await readMetaData(path, {
const {nowConfig, name} = await readMetaData(path, {
deploymentType: 'npm', // hard coding settings…
quiet: true // `quiet`
})
const pkgConfig = pkg ? pkg.now || {} : {}
const target = pkgConfig.alias
const target = nowConfig.alias
// the user never intended to support aliases from the package
if (!target) {

4
bin/now-deploy.js

@ -363,7 +363,7 @@ async function sync(token) {
}
}
const {pkg: {now: pkgConfig = {}} = {}} = await readMetaData(path, {
const {nowConfig} = await readMetaData(path, {
deploymentType,
deploymentName,
isStatic,
@ -373,7 +373,7 @@ async function sync(token) {
const now = new Now(apiUrl, token, {debug})
// Merge `now.env` from package.json with `-e` arguments.
const pkgEnv = pkgConfig.env
const pkgEnv = nowConfig.env
const envs = [
...Object.keys(pkgEnv || {}).map(k => `${k}=${pkgEnv[k]}`),
...[].concat(argv.env || [])

8
lib/index.js

@ -53,7 +53,7 @@ module.exports = class Now extends EventEmitter {
let files
const {pkg, name, description} = await readMetaData(path, {
const {pkg, name, description, nowConfig} = await readMetaData(path, {
deploymentType,
deploymentName,
quiet,
@ -74,9 +74,7 @@ module.exports = class Now extends EventEmitter {
console.timeEnd('> [debug] Getting files')
}
const nowProperties = pkg ? pkg.now || {} : {}
forwardNpm = forwardNpm || nowProperties.forwardNpm
forwardNpm = forwardNpm || nowConfig.forwardNpm
// Read .npmrc
let npmrc = {}
@ -118,7 +116,7 @@ module.exports = class Now extends EventEmitter {
this._files = hashes
const engines = nowProperties.engines || pkg.engines
const engines = nowConfig.engines || pkg.engines
const deployment = await this.retry(async bail => {
if (this._debug) {

21
lib/read-metadata.js

@ -19,10 +19,23 @@ module.exports = async function (path, {
isStatic = false
}) {
let pkg = {}
let nowConfig = {}
let name
let description
try {
nowConfig = await readFile(resolvePath(path, 'now.json'))
nowConfig = JSON.parse(nowConfig)
} catch (err) {
// if the file doesn't exist then that's fine; any other error bubbles up
if (err.code !== 'ENOENT') {
const e = Error(`Failed to read JSON in "${path}/now.json"`)
e.userError = true
throw e
}
}
if (deploymentType === 'npm') {
if (isStatic) {
pkg = listPackage
@ -113,9 +126,15 @@ module.exports = async function (path, {
name = deploymentName
}
// merge in `package.now` if present, but have `now.json` take precedence
if (pkg.now) {
nowConfig = extend({}, pkg.now, nowConfig)
}
return {
name,
description,
pkg
pkg,
nowConfig
}
}

Loading…
Cancel
Save