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, forceSync,
forwardNpm: alwaysForwardNpm || forwardNpm, forwardNpm: alwaysForwardNpm || forwardNpm,
quiet, quiet,
wantsPublic wantsPublic,
isStatic
}) })
} catch (err) { } catch (err) {
if (debug) { if (debug) {

29
lib/index.js

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

33
lib/read-metadata.js

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

Loading…
Cancel
Save