|
|
@ -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 |
|
|
|