Skip to content

Commit

Permalink
Merge pull request #596 from jenius/deploy-polish
Browse files Browse the repository at this point in the history
deploy using production settings if present
  • Loading branch information
Jeff Escalante committed Jan 8, 2015
2 parents 80e6df6 + 558b727 commit 943e9c2
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lib/api/deploy.coffee
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
W = require 'when'
Ship = require 'ship'
W = require 'when'
fs = require 'fs'
path = require 'path'
Ship = require 'ship'
Config = require '../config'

class Deploy
constructor: (@project) ->

exec: (opts = {}) ->
__track('api', { name: 'deploy', deployer: opts.to })

@project.compile()
.then => new Ship(root: @project.root, deployer: opts.to)
@project.clean()
.then =>
# So in reality, compile should take an env parameter. It does not at the
# moment though probably for performance reasons, so we can hack around
# this to get a compile in a different env. This should be refactored.
if fs.existsSync(path.join(@project.root, 'app.production.coffee'))
@project.config = new Config(@project, { env: 'production' })
.then => @project.compile()
.then =>
if fs.existsSync(path.join(@project.root, 'ship.production.conf'))
new Ship(root: @project.root, deployer: opts.to, env: 'production')
else
new Ship(root: @project.root, deployer: opts.to)
.tap (ship) ->
if not ship.is_configured()
ship.config_prompt()
Expand Down
30 changes: 30 additions & 0 deletions test/deploy.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,33 @@ describe 'deploy', ->
project = new Roots(p)

project.deploy(to: 'nowhere').should.be.fulfilled

it 'compiles before deploy', ->
p = path.join(base_path, 'deploy/compile')
project = new Roots(p)

project.deploy(to: 'nowhere')
.then -> path.join(p, 'public').should.be.a.directory()
.then -> path.join(p, 'public/index.html').should.be.a.file()
.should.be.fulfilled

it 'removes previous output folder before compiling', ->
p = path.join(base_path, 'deploy/remove_prev')
project = new Roots(p)

fs.mkdirSync(path.join(p, 'public'))
fs.writeFileSync(path.join(p, 'public/foo.html'), 'foo bar')

project.deploy(to: 'nowhere')
.tap -> path.join(p, 'public/foo.html').should.not.be.a.path()
.tap -> path.join(p, 'public/index.html').should.be.a.file()
.should.be.fulfilled

it 'compiles with app.production.coffee if available', ->
p = path.join(base_path, 'deploy/production')
project = new Roots(p)

project.deploy(to: 'nowhere')
.then -> path.join(p, 'public/index.html').should.have.content('production')
.catch(console.log)
.should.be.fulfilled
1 change: 1 addition & 0 deletions test/fixtures/deploy/compile/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>this should be compiled to itself</p>
2 changes: 2 additions & 0 deletions test/fixtures/deploy/compile/ship.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nowhere:
nothing: wow
2 changes: 2 additions & 0 deletions test/fixtures/deploy/production/app.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
locals:
env: 'development'
2 changes: 2 additions & 0 deletions test/fixtures/deploy/production/app.production.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
locals:
env: 'production'
1 change: 1 addition & 0 deletions test/fixtures/deploy/production/index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= env
6 changes: 6 additions & 0 deletions test/fixtures/deploy/production/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "test",
"dependencies": {
"jade": "*"
}
}
2 changes: 2 additions & 0 deletions test/fixtures/deploy/production/ship.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nowhere:
nothing: wow
1 change: 1 addition & 0 deletions test/fixtures/deploy/remove_prev/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>here!</p>
2 changes: 2 additions & 0 deletions test/fixtures/deploy/remove_prev/ship.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nowhere:
nothing: wow

0 comments on commit 943e9c2

Please sign in to comment.