Skip to content

Commit

Permalink
Merge 9a92d1f into 9b62cde
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgustys committed Jan 21, 2016
2 parents 9b62cde + 9a92d1f commit 08d8da2
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = (opts) ->
setup: ->
W(opts).with(@)
.then (opts) ->
opts.outdir ?= ''
@opts = _.defaults(opts, {redirects: {}, rewrites: {}, headers: {}})
.then ->
W.all([write_headers.call(@), write_redirects.call(@)])
Expand All @@ -23,7 +24,7 @@ module.exports = (opts) ->
str += " #{k}: #{v}\n" for k, v of conf
return str
, ''
@util.write '_headers', res
@util.write path.join(@opts.outdir, '_headers'), res

write_redirects = ->
redirects = _.pick(@opts.redirects, codes)
Expand All @@ -37,4 +38,4 @@ module.exports = (opts) ->
str += "#{k} #{v} #{code}\n"
return str
, ''
@util.write '_redirects', res
@util.write path.join(@opts.outdir, '_redirects'), res
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
},
"devDependencies": {
"coffee-script": "1.7.x",
"mocha": "*",
"should": "*",
"roots": "3.0.0-rc.10",
"coveralls": "2.x",
"istanbul": "0.3.x"
"istanbul": "0.3.x",
"mocha": "*",
"roots": "^3.1.0",
"should": "*"
},
"scripts": {
"test": "mocha",
Expand Down
25 changes: 25 additions & 0 deletions test/fixtures/outdir/app.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
netlify = require '../../..'

module.exports =
ignores: ["**/.DS_Store"]
extensions: [
netlify
outdir: 'customdir'
redirects:
'/news': '/blog'
'/news/:year/:month:/:date/:slug': '/blog/:year/:month/:date/:story_id'
'/news/*': '/blog/:splat'
'302':
'/temp_redirect': '/'
'404':
'/ecommerce': '/closed'
rewrites:
'/*': '/index.html'
headers:
'/protected/path':
'Cache-Control': 'max-age: 3000'
'Basic-Auth': 'username:password'
'/*':
'X-Frame-Options': 'DENY'
'X-XSS-Protection': '1; mode=block'
]
6 changes: 6 additions & 0 deletions test/fixtures/outdir/expected/_headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/protected/path
Cache-Control: max-age: 3000
Basic-Auth: username:password
/*
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
6 changes: 6 additions & 0 deletions test/fixtures/outdir/expected/_redirects
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* /index.html 200
/news /blog 301
/news/:year/:month:/:date/:slug /blog/:year/:month/:date/:story_id 301
/news/* /blog/:splat 301
/temp_redirect / 302
/ecommerce /closed 404
1 change: 1 addition & 0 deletions test/fixtures/outdir/index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
p hello world
6 changes: 6 additions & 0 deletions test/fixtures/outdir/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "test",
"dependencies": {
"jade": "*"
}
}
8 changes: 8 additions & 0 deletions test/test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,11 @@ describe 'promises support', ->
compiled = path.join(@public, '_redirects')
expected = path.join(@public, 'expected', '_redirects')
h.file.matches_file(compiled, expected).should.be.true

describe 'custom output directory', ->

before (done) -> compile_fixture.call(@, 'outdir', -> done())

it 'compiles basic project to custom directory', ->
p = path.join(@public, '/customdir/index.html')
h.file.exists(p).should.be.ok

0 comments on commit 08d8da2

Please sign in to comment.