Browse Source

Move files into content dir if static

master
Leo Lamprecht 8 years ago
parent
commit
c5626178ed
No known key found for this signature in database GPG Key ID: EF804E3FF4BBA8AB
  1. 3
      bin/now-deploy.js
  2. 29
      lib/index.js
  3. 33
      lib/read-metadata.js

3
bin/now-deploy.js

@ -389,7 +389,8 @@ async function sync(token) {
forceSync,
forwardNpm: alwaysForwardNpm || forwardNpm,
quiet,
wantsPublic
wantsPublic,
isStatic
})
} catch (err) {
if (debug) {

29
lib/index.js

@ -1,6 +1,6 @@
// Native
import {homedir} from 'os'
import {resolve as resolvePath} from 'path'
import {resolve as resolvePath, join as joinPaths} from 'path'
import EventEmitter from 'events'
// Packages
@ -43,15 +43,18 @@ export default class Now extends EventEmitter {
forceNew = false,
forceSync = false,
forwardNpm = false,
deploymentType = 'npm'
deploymentType = 'npm',
isStatic = false
}) {
this._path = path
this._static = isStatic
let files
const {pkg, name, description} = await readMetaData(path, {
deploymentType,
quiet
quiet,
isStatic
})
if (this._debug) {
@ -129,6 +132,10 @@ export default class Now extends EventEmitter {
// array has a group of files with the same sha but different path
files: Array.prototype.concat.apply([], Array.from(this._files).map(([sha, {data, names}]) => {
return names.map(n => {
if (this._static && toRelative(n, this._path) !== 'package.json') {
n = this.pathInsideContent(n)
}
return {
sha,
size: data.length,
@ -215,6 +222,14 @@ export default class Now extends EventEmitter {
return this._url
}
pathInsideContent(position) {
const relativePath = toRelative(position, this._path)
const contentDir = joinPaths(this._path, 'content')
const newPath = joinPaths(contentDir, relativePath)
return newPath
}
upload() {
const parts = splitArray(this._missing, MAX_CONCURRENT)
@ -241,7 +256,13 @@ export default class Now extends EventEmitter {
'Content-Length': data.length,
'x-now-deployment-id': this._id,
'x-now-sha': sha,
'x-now-file': names.map(name => toRelative(encodeURIComponent(name), this._path)).join(','),
'x-now-file': names.map(name => {
if (this._static) {
name = this.pathInsideContent(name)
}
return toRelative(encodeURIComponent(name), this._path)
}).join(','),
'x-now-size': data.length
},
body: stream

33
lib/read-metadata.js

@ -3,9 +3,20 @@ import chalk from 'chalk'
import {readFile} from 'fs-promise'
import {parse as parseDockerfile} from 'docker-file-parser'
const listPackage = {
version: '0.0.0',
scripts: {
start: 'list ./content'
},
dependencies: {
list: 'latest'
}
}
export default async function (path, {
deploymentType = 'npm',
quiet = false
quiet = false,
isStatic = false
}) {
let pkg = {}
@ -13,13 +24,17 @@ export default async function (path, {
let description
if (deploymentType === 'npm') {
try {
pkg = await readFile(resolvePath(path, 'package.json'))
pkg = JSON.parse(pkg)
} catch (err) {
const e = Error(`Failed to read JSON in "${path}/package.json"`)
e.userError = true
throw e
if (isStatic) {
pkg = listPackage
} else {
try {
pkg = await readFile(resolvePath(path, 'package.json'))
pkg = JSON.parse(pkg)
} catch (err) {
const e = Error(`Failed to read JSON in "${path}/package.json"`)
e.userError = true
throw e
}
}
if (!pkg.scripts || (!pkg.scripts.start && !pkg.scripts['now-start'])) {
@ -32,7 +47,7 @@ export default async function (path, {
if (pkg.name === null || typeof pkg.name !== 'string') {
name = basename(path)
if (!quiet) {
if (!quiet && !isStatic) {
console.log(`> No \`name\` in \`package.json\`, using ${chalk.bold(name)}`)
}
} else {

Loading…
Cancel
Save