Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1. Updated roots version, 2. Added options paramenter outdir for custom configuration output #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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