Skip to content

Commit

Permalink
Add options param to bundle() to allow string wrap/join
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobeat committed Mar 29, 2013
1 parent 4cdd0ba commit 8d3db3c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
18 changes: 13 additions & 5 deletions flour.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,38 @@ flour =
logger.log pos.red, e.reason.grey
cb? passed, errors, file

bundle: (files, dest, cb) ->
bundle: (files, options, dest, cb) ->

return flour.getFiles files, (results) ->
results.filepath = files
flour.bundleFiles results, dest, cb
flour.bundleFiles results, options, dest, cb

bundleFiles: (files, dest, cb) ->
bundleFiles: (files, options, dest, cb) ->

if files.length is 0
throw ERROR.NO_MATCH files.filepath

# No options object
if not dest? or typeof options isnt 'object'
[options, dest, cb] = [{}, options, dest]

options.wrap ?= []

results = []
counter = 0

done = ->
return unless files.length is ++counter
shim = new File dest, results.join("\n")
shim = new File dest
sep = if shim.ext is 'js' then "\n;" else "\n"
shim.buffer = [options.before] + results.join(sep) + [options.after]
shim.minify (output) ->
success dest, @, output, 'Packaged', cb

files.forEach (file, i) ->
file = new File file
file.compile (output) ->
results[i] = output
results[i] = [options.wrap[0]] + output + [options.wrap[1]]
done()

return
Expand Down
20 changes: 20 additions & 0 deletions test/flour.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,26 @@ describe 'Bundle', ->
contents.should.include 'bundle2=function('
done()

it 'should wrap compiled code', (done) ->
flour.bundle "#{sources_js}/*", {
wrap: ['TEST(', ');']
}, output_file, ->
contents = readFile output_file
contents.should.include 'TEST(function(){return 1})'
done()

it 'should add before/after strings to bundle', (done) ->
flour.minifiers.disable()
options =
before: '(function(n,y,c){'
after: '}("wrap"));'
flour.bundle "#{sources_js}/*", options, output_file, ->
contents = readFile output_file
contents.should.include options.before
contents.should.include options.after
flour.minifiers.enable()
done()

describe 'File path handling', ->

m1 = "#{dir.temp}/multi1.js"
Expand Down

0 comments on commit 8d3db3c

Please sign in to comment.