Skip to content

Commit

Permalink
write hook creates a directory if it doesnt exist
Browse files Browse the repository at this point in the history
- thanks to @monkeez for this
- closes #438
  • Loading branch information
Jeff Escalante committed Apr 22, 2014
1 parent 063f728 commit fa18710
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/compiler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ nodefn = require 'when/node'
pipeline = require 'when/pipeline'
sequence = require 'when/sequence'
File = require 'vinyl'
mkdirp = require 'mkdirp'

###*
* @class Compiler
Expand Down Expand Up @@ -204,7 +205,8 @@ class CompileFile

obj.path = @roots.config.out(obj.path, obj.extension)

nodefn.call(fs.writeFile, obj.path, obj.content)
nodefn.call(mkdirp, path.dirname(obj.path))
.then(-> nodefn.call(fs.writeFile, obj.path, obj.content))

###*
* Read the file's extension and grab any and all adapters that match. If
Expand Down
2 changes: 2 additions & 0 deletions test/extensions_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ describe 'write hook', ->
path.join(@public, 'multi1.html').should.have.content('clone 1')
path.join(@public, 'multi2.html').should.be.a.file()
path.join(@public, 'multi2.html').should.have.content('clone 2')
path.join(@public, 'subdir/multi3.html').should.be.a.file()
path.join(@public, 'subdir/multi3.html').should.have.content('clone 3')

describe 'categories', ->

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/extensions/write_hook/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ write_multiple = ->
[
{ path: path.join(ctx.roots.root, 'multi1.html'), content: 'clone 1' },
{ path: path.join(ctx.roots.root, 'multi2.html'), content: 'clone 2' }
{ path: path.join(ctx.roots.root, 'subdir/multi3.html'), content: 'clone 3' }
]

module.exports =
Expand Down

0 comments on commit fa18710

Please sign in to comment.