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) { async function realias(alias) {
const path = process.cwd() const path = process.cwd()
const {pkg, name} = await readMetaData(path, { const {nowConfig, name} = await readMetaData(path, {
deploymentType: 'npm', // hard coding settings… deploymentType: 'npm', // hard coding settings…
quiet: true // `quiet` quiet: true // `quiet`
}) })
const pkgConfig = pkg ? pkg.now || {} : {} const target = nowConfig.alias
const target = pkgConfig.alias
// the user never intended to support aliases from the package // the user never intended to support aliases from the package
if (!target) { 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, deploymentType,
deploymentName, deploymentName,
isStatic, isStatic,
@ -373,7 +373,7 @@ async function sync(token) {
const now = new Now(apiUrl, token, {debug}) const now = new Now(apiUrl, token, {debug})
// Merge `now.env` from package.json with `-e` arguments. // Merge `now.env` from package.json with `-e` arguments.
const pkgEnv = pkgConfig.env const pkgEnv = nowConfig.env
const envs = [ const envs = [
...Object.keys(pkgEnv || {}).map(k => `${k}=${pkgEnv[k]}`), ...Object.keys(pkgEnv || {}).map(k => `${k}=${pkgEnv[k]}`),
...[].concat(argv.env || []) ...[].concat(argv.env || [])

8
lib/index.js

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

21
lib/read-metadata.js

@ -19,10 +19,23 @@ module.exports = async function (path, {
isStatic = false isStatic = false
}) { }) {
let pkg = {} let pkg = {}
let nowConfig = {}
let name let name
let description 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 (deploymentType === 'npm') {
if (isStatic) { if (isStatic) {
pkg = listPackage pkg = listPackage
@ -113,9 +126,15 @@ module.exports = async function (path, {
name = deploymentName name = deploymentName
} }
// merge in `package.now` if present, but have `now.json` take precedence
if (pkg.now) {
nowConfig = extend({}, pkg.now, nowConfig)
}
return { return {
name, name,
description, description,
pkg pkg,
nowConfig
} }
} }

Loading…
Cancel
Save