From 9a92d1f830e4dcb3a248ab589897e49f70fe533b Mon Sep 17 00:00:00 2001 From: Deividas Gustys Date: Thu, 21 Jan 2016 12:03:02 +0200 Subject: [PATCH] 1. Updated roots version, 2. Added options paramenter `outdir` for custom configuration output --- lib/index.coffee | 5 +++-- package.json | 8 ++++---- test/fixtures/outdir/app.coffee | 25 ++++++++++++++++++++++++ test/fixtures/outdir/expected/_headers | 6 ++++++ test/fixtures/outdir/expected/_redirects | 6 ++++++ test/fixtures/outdir/index.jade | 1 + test/fixtures/outdir/package.json | 6 ++++++ test/test.coffee | 8 ++++++++ 8 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 test/fixtures/outdir/app.coffee create mode 100644 test/fixtures/outdir/expected/_headers create mode 100644 test/fixtures/outdir/expected/_redirects create mode 100644 test/fixtures/outdir/index.jade create mode 100644 test/fixtures/outdir/package.json diff --git a/lib/index.coffee b/lib/index.coffee index f760509..01f25d4 100644 --- a/lib/index.coffee +++ b/lib/index.coffee @@ -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(@)]) @@ -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) @@ -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 diff --git a/package.json b/package.json index 41509a2..8002fad 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/fixtures/outdir/app.coffee b/test/fixtures/outdir/app.coffee new file mode 100644 index 0000000..872a59f --- /dev/null +++ b/test/fixtures/outdir/app.coffee @@ -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' + ] diff --git a/test/fixtures/outdir/expected/_headers b/test/fixtures/outdir/expected/_headers new file mode 100644 index 0000000..8c58bfd --- /dev/null +++ b/test/fixtures/outdir/expected/_headers @@ -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 diff --git a/test/fixtures/outdir/expected/_redirects b/test/fixtures/outdir/expected/_redirects new file mode 100644 index 0000000..f06066a --- /dev/null +++ b/test/fixtures/outdir/expected/_redirects @@ -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 diff --git a/test/fixtures/outdir/index.jade b/test/fixtures/outdir/index.jade new file mode 100644 index 0000000..4bb415d --- /dev/null +++ b/test/fixtures/outdir/index.jade @@ -0,0 +1 @@ +p hello world diff --git a/test/fixtures/outdir/package.json b/test/fixtures/outdir/package.json new file mode 100644 index 0000000..2d0ae2c --- /dev/null +++ b/test/fixtures/outdir/package.json @@ -0,0 +1,6 @@ +{ + "name": "test", + "dependencies": { + "jade": "*" + } +} diff --git a/test/test.coffee b/test/test.coffee index dbd383b..0ce6a2f 100644 --- a/test/test.coffee +++ b/test/test.coffee @@ -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