Skip to content

Commit

Permalink
Add support for branch deploys (#907)
Browse files Browse the repository at this point in the history
* Use this.error in ensureDirectory

* Deploy: Add context flag

* Deploy: Rename context to branch

* Update netlify packafge

* Formatting
  • Loading branch information
RaeesBhatti authored Jun 3, 2020
1 parent 330cdac commit c8639eb
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 14 deletions.
51 changes: 47 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"log-symbols": "^2.2.0",
"make-dir": "^3.0.0",
"minimist": "^1.2.5",
"netlify": "^4.1.8",
"netlify": "^4.3.0",
"netlify-redirect-parser": "^2.5.0",
"netlify-redirector": "^0.2.0",
"node-fetch": "^2.6.0",
Expand Down
24 changes: 15 additions & 9 deletions src/commands/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class DeployCommand extends Command {
const { api, site, config } = this.netlify

const deployToProduction = flags.prod
if (deployToProduction && flags.branch) {
this.error(`--prod and --branch flags cannot be used at the same time`)
}
await this.authenticate(flags.auth)

await this.config.runHook('analytics', {
Expand All @@ -31,6 +34,7 @@ class DeployCommand extends Command {
open: flags.open,
prod: flags.prod,
json: flags.json,
branch: Boolean(flags.branch),
},
})

Expand Down Expand Up @@ -142,7 +146,7 @@ class DeployCommand extends Command {
}
this.log(prettyjson.render(pathInfo))

ensureDirectory(deployFolder, this.exit)
ensureDirectory(deployFolder, this.error)

if (functionsFolder) {
// we used to hard error if functions folder is specified but doesnt exist
Expand Down Expand Up @@ -195,9 +199,10 @@ class DeployCommand extends Command {
configPath: configPath,
fnDir: functionsFolder,
statusCb: flags.json || flags.silent ? () => {} : deployProgressCb(),
draft: !deployToProduction,
draft: !deployToProduction && !flags.branch,
message: flags.message,
deployTimeout: flags.timeout * 1000 || 1.2e6,
branch: flags.branch,
})
} catch (e) {
switch (true) {
Expand Down Expand Up @@ -375,6 +380,10 @@ DeployCommand.flags = {
description: 'Deploy to production',
default: false,
}),
branch: flags.string({
char: 'b',
description: "Specifies the branch for deployment. Useful for creating specific deployment URL's",
}),
open: flags.boolean({
char: 'o',
description: 'Open site after deploy',
Expand Down Expand Up @@ -441,28 +450,25 @@ function deployProgressCb() {
}
}

function ensureDirectory(resolvedDeployPath, exit) {
function ensureDirectory(resolvedDeployPath, error) {
let stat
try {
stat = fs.statSync(resolvedDeployPath)
} catch (e) {
if (e.status === 'ENOENT') {
console.log(
return error(
`No such directory ${resolvedDeployPath}! Did you forget to create a functions folder or run a build?`
)
exit(1)
}

// Improve the message of permission errors
if (e.status === 'EACCES') {
console.log('Permission error when trying to access deploy folder')
exit(1)
return error('Permission error when trying to access deploy folder')
}
throw e
}
if (!stat.isDirectory) {
console.log('Deploy target must be a directory')
exit(1)
return error('Deploy target must be a directory')
}
return stat
}
Expand Down

0 comments on commit c8639eb

Please sign in to comment.