Skip to content

Commit

Permalink
Made now <file> work (#1139)
Browse files Browse the repository at this point in the history
* Added functionality for single static file deployments.

* Added friendly error message to now alias command

* Deleted temp files

* Removed empty line

* Make it work

* Removed alias message

* Corrected intentation

* Brought variable back

* Removed it

* Set correct name

* Bumped lockfile
  • Loading branch information
spal1 authored and leo committed Feb 27, 2018
1 parent 0450be2 commit 42f1310
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 31 deletions.
62 changes: 43 additions & 19 deletions src/providers/sh/commands/deploy.js
Expand Up @@ -366,16 +366,26 @@ async function sync({ token, config: { currentTeam, user }, showMessage }) {
}
}

// Make sure that directory is deployable
try {
await checkPath(path)
} catch (err) {
console.error(error({
message: err.message,
slug: 'path-not-deployable'
}))
let deploymentType
let isStaticFile = false

await exit(1)
const fsData = await fs.lstat(path)

if (fsData.isFile()) {
deploymentType = 'static'
isStaticFile = true
} else {
// Make sure that directory is deployable
try {
await checkPath(path)
} catch (err) {
console.error(error({
message: err.message,
slug: 'path-not-deployable'
}))

await exit(1)
}
}

if (!quiet && showMessage) {
Expand All @@ -397,8 +407,6 @@ async function sync({ token, config: { currentTeam, user }, showMessage }) {
}
}

let deploymentType

// CLI deployment type explicit overrides
if (argv.docker) {
if (debug) {
Expand All @@ -421,14 +429,29 @@ async function sync({ token, config: { currentTeam, user }, showMessage }) {
}

let meta
;({
meta,
deploymentName,
deploymentType,
sessionAffinity
} = await readMeta(path, deploymentName, deploymentType, sessionAffinity))
const nowConfig = meta.nowConfig

if (isStaticFile) {
meta = {
name: 'file',
type: deploymentType,
pkg: undefined,
nowConfig: undefined,
hasNowJson: false,

// XXX: legacy
deploymentType,
sessionAffinity
}
} else {
;({
meta,
deploymentName,
deploymentType,
sessionAffinity
} = await readMeta(path, deploymentName, deploymentType, sessionAffinity))
}

const nowConfig = meta.nowConfig
const now = new Now({ apiUrl, token, debug, currentTeam })

let dotenvConfig
Expand Down Expand Up @@ -577,7 +600,8 @@ async function sync({ token, config: { currentTeam, user }, showMessage }) {
forwardNpm: alwaysForwardNpm || forwardNpm,
quiet,
wantsPublic,
sessionAffinity
sessionAffinity,
isStaticFile
},
meta
)
Expand Down
12 changes: 9 additions & 3 deletions src/providers/sh/util/index.js
Expand Up @@ -62,10 +62,11 @@ module.exports = class Now extends EventEmitter {
pkg = {},
nowConfig = {},
hasNowJson = false,
sessionAffinity = 'ip'
sessionAffinity = 'ip',
isStaticFile = false
}
) {
this._path = path
this._path = isStaticFile ? path.split('/').slice(0, -1).join('/') : path

let files
let engines
Expand All @@ -75,6 +76,7 @@ module.exports = class Now extends EventEmitter {
}

const opts = { debug: this._debug, hasNowJson }

if (type === 'npm') {
files = await getNpmFiles(path, pkg, nowConfig, opts)

Expand All @@ -92,7 +94,11 @@ module.exports = class Now extends EventEmitter {
engines = nowConfig.engines || pkg.engines
forwardNpm = forwardNpm || nowConfig.forwardNpm
} else if (type === 'static') {
files = await getFiles(path, nowConfig, opts)
if (isStaticFile) {
files = [resolvePath(path)]
} else {
files = await getFiles(path, nowConfig, opts)
}
} else if (type === 'docker') {
files = await getDockerFiles(path, nowConfig, opts)
}
Expand Down
23 changes: 14 additions & 9 deletions yarn.lock
Expand Up @@ -117,8 +117,8 @@ ajv@^5.1.5, ajv@^5.2.0:
json-schema-traverse "^0.3.0"

ajv@^6.0.1:
version "6.1.1"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.1.1.tgz#978d597fbc2b7d0e5a5c3ddeb149a682f2abfa0e"
version "6.2.0"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.2.0.tgz#afac295bbaa0152449e522742e4547c1ae9328d2"
dependencies:
fast-deep-equal "^1.0.0"
fast-json-stable-stringify "^2.0.0"
Expand Down Expand Up @@ -2318,11 +2318,10 @@ esquery@^1.0.0:
estraverse "^4.0.0"

esrecurse@^4.1.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/esrecurse/-/esrecurse-4.2.0.tgz#fa9568d98d3823f9a41d91e902dcab9ea6e5b163"
version "4.2.1"
resolved "https://registry.yarnpkg.com/esrecurse/-/esrecurse-4.2.1.tgz#007a3b9fdbc2b3bb87e4879ea19c92fdbd3942cf"
dependencies:
estraverse "^4.1.0"
object-assign "^4.0.1"

estraverse@^1.9.1:
version "1.9.3"
Expand Down Expand Up @@ -2450,8 +2449,8 @@ extsprintf@^1.2.0:
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.0.tgz#e2689f8f356fad62cca65a3a91c5df5f9551692f"

fast-deep-equal@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.0.0.tgz#96256a3bc975595eb36d82e9929d060d893439ff"
version "1.1.0"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz#c053477817c86b51daa853c81e059b733d023614"

fast-diff@^1.1.1:
version "1.1.2"
Expand Down Expand Up @@ -5252,6 +5251,12 @@ supports-color@^4.0.0, supports-color@^4.2.1:
dependencies:
has-flag "^2.0.0"

supports-color@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.2.0.tgz#b0d5333b1184dd3666cbe5aa0b45c5ac7ac17a4a"
dependencies:
has-flag "^3.0.0"

symbol-observable@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.0.1.tgz#8340fc4702c3122df5d22288f88283f513d3fdd4"
Expand Down Expand Up @@ -5412,8 +5417,8 @@ to-fast-properties@^2.0.0:
resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e"

tough-cookie@2.x, tough-cookie@~2.3.0:
version "2.3.3"
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.3.tgz#0b618a5565b6dea90bf3425d04d55edc475a7561"
version "2.3.4"
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.4.tgz#ec60cee38ac675063ffc97a5c18970578ee83655"
dependencies:
punycode "^1.4.1"

Expand Down

0 comments on commit 42f1310

Please sign in to comment.