Permalink
Browse files

support glob filters for paths, new version

  • Loading branch information...
1 parent 56ee4a7 commit b337f3e973d4236a9b4409541827cc0b9674d1c1 @quackingduck quackingduck committed Jun 12, 2012
Showing with 19 additions and 10 deletions.
  1. +4 −1 lib/emport.js
  2. +1 −1 package.json
  3. +11 −7 src/emport.coffee
  4. +3 −1 test/integration_test.coffee
View
@@ -66,7 +66,10 @@ targetFilename is in.
return async.forEachSeries(basePaths, function(basePath, cb) {
return async.waterfall([
function(cb) {
- return glob("" + basePath + "/**/*.@(js|coffee)", cb);
+ var basePathGlob, _ref;
+ _ref = basePath.split(' '), basePath = _ref[0], basePathGlob = _ref[1];
+ if (basePathGlob == null) basePathGlob = '**/*.@(js|coffee)';
+ return glob(basePath + '/' + basePathGlob, cb);
}, function(filenames, cb) {
return async.forEach(filenames, function(filename, eachCb) {
return fs.readFile(filename, 'utf8', function(err, contents) {
View
@@ -1,5 +1,5 @@
{ "name": "emport"
-, "version": "0.2.0"
+, "version": "0.5.0"
, "author": "Myles Byrne"
View
@@ -2,7 +2,7 @@
Example usage:
- emport 'app.coffee', path: 'frontend', map:
+ emport 'app.coffee', paths: [ 'frontend **/*.js' ], map:
'vendor/jquery.js' : exports: '$'
, (err, js) ->
throw err if err?
@@ -14,8 +14,12 @@ on).
Here's a rough overview of what happens when `emport` is called:
-* The base path is scanned (infinitely deep) for .js and .coffee files
-* All of those files are read into memory, in parallel
+* If no base paths are provided - via the `paths` argument - the directory of
+ the target file is used.
+* The base paths are scanned for all files matching the optional glob or
+ against the default glob: `**/*.@(js|coffee)` (all js and coffee files,
+ infinitely deep).
+* All of the matched files are read into memory, in parallel
* Each file is scanned for the special import and export comments
* An `emportMap` data strcuture is built up containing:
* The file name (relative to the base path)
@@ -40,9 +44,6 @@ Here's a rough overview of what happens when `emport` is called:
its compiled first.
* Finally the callback is called with that string as the second arg.
-n.b. The base path is either the value of options.path or the directory that
-targetFilename is in.
-
###
path = require 'path'
@@ -62,7 +63,10 @@ module.exports = emport = (targetFilename, options, callback) ->
async.waterfall [
# enumerate all paths
- (cb) -> glob "#{basePath}/**/*.@(js|coffee)", cb
+ (cb) ->
+ [basePath, basePathGlob] = basePath.split ' '
+ basePathGlob ?= '**/*.@(js|coffee)'
+ glob basePath+'/'+basePathGlob, cb
(filenames, cb) ->
# parrallel process each file
@@ -2,7 +2,9 @@ assert = require 'assert'
emport = require '../src/emport'
test "example/small-app", (done) ->
- emport 'app.coffee', paths: [__dirname+'/../examples/small-app/frontend'], map:
+ dir = __dirname + '/../examples/small-app/frontend'
+ # optional glob filter provided
+ emport 'app.coffee', paths: [ dir + ' **/*.@(js|coffee)' ], map:
'vendor/jquery.js' : exports: '$'
'vendor/underscore.js' : exports: '_'
'vendor/backbone.js' : exports: 'Backbone', imports: '_'

0 comments on commit b337f3e

Please sign in to comment.