Permalink
Browse files

support more than one path

  • Loading branch information...
1 parent 1546475 commit 5269df487b3b934e5e041ec6fcd0b648a209d0ce @quackingduck quackingduck committed May 19, 2012
Showing with 40 additions and 36 deletions.
  1. +21 −19 lib/emport.js
  2. +18 −16 src/emport.coffee
  3. +1 −1 test/integration_test.coffee
View
@@ -60,26 +60,28 @@ targetFilename is in.
coffee = require('coffee-script');
module.exports = emport = function(targetFilename, options, callback) {
- var basePath, emportMap;
- basePath = options.path || path.dirname(targetFilename);
+ var basePaths, emportMap;
+ basePaths = options.paths || [path.dirname(targetFilename)];
emportMap = {};
- return async.waterfall([
- function(cb) {
- return glob("" + basePath + "/**/*.@(js|coffee)", cb);
- }, function(filenames, cb) {
- return async.forEach(filenames, function(filename, eachCb) {
- return fs.readFile(filename, 'utf8', function(err, contents) {
- var importsAndExports, relPath;
- if (contents == null) return eachCb();
- relPath = path.relative(basePath, filename);
- importsAndExports = parseSourceForImportsAndExports(contents);
- emportMap[relPath] = importsAndExports;
- emportMap[relPath].contents = contents;
- return eachCb();
- });
- }, cb);
- }
- ], function(err) {
+ return async.forEachSeries(basePaths, function(basePath, cb) {
+ return async.waterfall([
+ function(cb) {
+ return glob("" + basePath + "/**/*.@(js|coffee)", cb);
+ }, function(filenames, cb) {
+ return async.forEach(filenames, function(filename, eachCb) {
+ return fs.readFile(filename, 'utf8', function(err, contents) {
+ var importsAndExports, relPath;
+ if (contents == null) return eachCb();
+ relPath = path.relative(basePath, filename);
+ importsAndExports = parseSourceForImportsAndExports(contents);
+ emportMap[relPath] = importsAndExports;
+ emportMap[relPath].contents = contents;
+ return eachCb();
+ });
+ }, cb);
+ }
+ ], cb);
+ }, function(err) {
var contents, contentsInOrder, dependencies, exportVar, exports, filename, filenamesInOrder, importVar, importsAndExports, _i, _len, _ref, _ref2;
if (err != null) return callback(err);
if (options.map != null) {
View
@@ -52,32 +52,34 @@ async = require 'async'
coffee = require 'coffee-script'
module.exports = emport = (targetFilename, options, callback) ->
- basePath = options.path or path.dirname(targetFilename)
+ basePaths = options.paths or [path.dirname(targetFilename)]
# data structure with entries like
# 'filename': imports: [], exports: [], contents: "... file contents ..."
emportMap = {}
- async.waterfall [
+ async.forEachSeries basePaths, (basePath, cb) ->
+ async.waterfall [
- # enumerate all paths
- (cb) -> glob "#{basePath}/**/*.@(js|coffee)", cb
+ # enumerate all paths
+ (cb) -> glob "#{basePath}/**/*.@(js|coffee)", cb
- (filenames, cb) ->
- # parrallel process each file
- async.forEach filenames, (filename, eachCb) ->
- fs.readFile filename, 'utf8', (err, contents) ->
- return eachCb() unless contents? # ignores directories
+ (filenames, cb) ->
+ # parrallel process each file
+ async.forEach filenames, (filename, eachCb) ->
+ fs.readFile filename, 'utf8', (err, contents) ->
+ return eachCb() unless contents? # ignores directories
- relPath = path.relative basePath, filename
- importsAndExports = parseSourceForImportsAndExports contents
- emportMap[relPath] = importsAndExports
- emportMap[relPath].contents = contents
+ relPath = path.relative basePath, filename
+ importsAndExports = parseSourceForImportsAndExports contents
+ emportMap[relPath] = importsAndExports
+ emportMap[relPath].contents = contents
- eachCb()
- , cb
+ eachCb()
+ , cb
- ], (err) ->
+ ], cb
+ , (err) ->
return callback(err) if err?
# apply the map given in options over map produced from scanning files
@@ -2,7 +2,7 @@ assert = require 'assert'
emport = require '../src/emport'
test "example/small-app", (done) ->
- emport 'app.coffee', path: __dirname+'/../examples/small-app/frontend', map:
+ emport 'app.coffee', paths: [__dirname+'/../examples/small-app/frontend'], map:
'vendor/jquery.js' : exports: '$'
'vendor/underscore.js' : exports: '_'
'vendor/backbone.js' : exports: 'Backbone', imports: '_'

0 comments on commit 5269df4

Please sign in to comment.