Skip to content

Instantly share code, notes, and snippets.

@davewasmer
Created February 3, 2014 22:57
Show Gist options
  • Select an option

  • Save davewasmer/8794151 to your computer and use it in GitHub Desktop.

Select an option

Save davewasmer/8794151 to your computer and use it in GitHub Desktop.
# ...
module.exports = ->
output = new stream.Transform(objectMode: true)
output._transform = (file, enc, callback) ->
# Pass this file along (do this *before* finding dependencies to preserve load order)
output.push(file)
# Find include statements
includes = file.contents.match(includeStatementPattern)
for statement in includes
includedFiles = resolveIncludedFilepaths(statement, file)
for f in includedFiles
# Take an included file, write back into this same stream to recursively check
# for includes.
output.write(f)
return output
findDependencies = require('find-dependencies')
gulp.task 'scripts', ->
gulp.src([ 'app/index.coffee' ])
.pipe(findDependencies())
.pipe(coffee())
# ...
@davewasmer

Copy link
Copy Markdown
Author

The problem is that the gulp.src call can finish and emit an end event before the recursion from findDependencies finishes, resulting in a Error: write after end exception.

In principle, I'm trying to take a single file, and mid-pipeline, expand that to more files, and emit those down the stream (from that mid-pipeline point on) in certain order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment