Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

support more than one path

  • Loading branch information...
commit 5269df487b3b934e5e041ec6fcd0b648a209d0ce 1 parent 1546475
Myles Byrne authored
40 lib/emport.js
@@ -60,26 +60,28 @@ targetFilename is in.
60 60 coffee = require('coffee-script');
61 61
62 62 module.exports = emport = function(targetFilename, options, callback) {
63   - var basePath, emportMap;
64   - basePath = options.path || path.dirname(targetFilename);
  63 + var basePaths, emportMap;
  64 + basePaths = options.paths || [path.dirname(targetFilename)];
65 65 emportMap = {};
66   - return async.waterfall([
67   - function(cb) {
68   - return glob("" + basePath + "/**/*.@(js|coffee)", cb);
69   - }, function(filenames, cb) {
70   - return async.forEach(filenames, function(filename, eachCb) {
71   - return fs.readFile(filename, 'utf8', function(err, contents) {
72   - var importsAndExports, relPath;
73   - if (contents == null) return eachCb();
74   - relPath = path.relative(basePath, filename);
75   - importsAndExports = parseSourceForImportsAndExports(contents);
76   - emportMap[relPath] = importsAndExports;
77   - emportMap[relPath].contents = contents;
78   - return eachCb();
79   - });
80   - }, cb);
81   - }
82   - ], function(err) {
  66 + return async.forEachSeries(basePaths, function(basePath, cb) {
  67 + return async.waterfall([
  68 + function(cb) {
  69 + return glob("" + basePath + "/**/*.@(js|coffee)", cb);
  70 + }, function(filenames, cb) {
  71 + return async.forEach(filenames, function(filename, eachCb) {
  72 + return fs.readFile(filename, 'utf8', function(err, contents) {
  73 + var importsAndExports, relPath;
  74 + if (contents == null) return eachCb();
  75 + relPath = path.relative(basePath, filename);
  76 + importsAndExports = parseSourceForImportsAndExports(contents);
  77 + emportMap[relPath] = importsAndExports;
  78 + emportMap[relPath].contents = contents;
  79 + return eachCb();
  80 + });
  81 + }, cb);
  82 + }
  83 + ], cb);
  84 + }, function(err) {
83 85 var contents, contentsInOrder, dependencies, exportVar, exports, filename, filenamesInOrder, importVar, importsAndExports, _i, _len, _ref, _ref2;
84 86 if (err != null) return callback(err);
85 87 if (options.map != null) {
34 src/emport.coffee
@@ -52,32 +52,34 @@ async = require 'async'
52 52 coffee = require 'coffee-script'
53 53
54 54 module.exports = emport = (targetFilename, options, callback) ->
55   - basePath = options.path or path.dirname(targetFilename)
  55 + basePaths = options.paths or [path.dirname(targetFilename)]
56 56
57 57 # data structure with entries like
58 58 # 'filename': imports: [], exports: [], contents: "... file contents ..."
59 59 emportMap = {}
60 60
61   - async.waterfall [
  61 + async.forEachSeries basePaths, (basePath, cb) ->
  62 + async.waterfall [
62 63
63   - # enumerate all paths
64   - (cb) -> glob "#{basePath}/**/*.@(js|coffee)", cb
  64 + # enumerate all paths
  65 + (cb) -> glob "#{basePath}/**/*.@(js|coffee)", cb
65 66
66   - (filenames, cb) ->
67   - # parrallel process each file
68   - async.forEach filenames, (filename, eachCb) ->
69   - fs.readFile filename, 'utf8', (err, contents) ->
70   - return eachCb() unless contents? # ignores directories
  67 + (filenames, cb) ->
  68 + # parrallel process each file
  69 + async.forEach filenames, (filename, eachCb) ->
  70 + fs.readFile filename, 'utf8', (err, contents) ->
  71 + return eachCb() unless contents? # ignores directories
71 72
72   - relPath = path.relative basePath, filename
73   - importsAndExports = parseSourceForImportsAndExports contents
74   - emportMap[relPath] = importsAndExports
75   - emportMap[relPath].contents = contents
  73 + relPath = path.relative basePath, filename
  74 + importsAndExports = parseSourceForImportsAndExports contents
  75 + emportMap[relPath] = importsAndExports
  76 + emportMap[relPath].contents = contents
76 77
77   - eachCb()
78   - , cb
  78 + eachCb()
  79 + , cb
79 80
80   - ], (err) ->
  81 + ], cb
  82 + , (err) ->
81 83 return callback(err) if err?
82 84
83 85 # apply the map given in options over map produced from scanning files
2  test/integration_test.coffee
@@ -2,7 +2,7 @@ assert = require 'assert'
2 2 emport = require '../src/emport'
3 3
4 4 test "example/small-app", (done) ->
5   - emport 'app.coffee', path: __dirname+'/../examples/small-app/frontend', map:
  5 + emport 'app.coffee', paths: [__dirname+'/../examples/small-app/frontend'], map:
6 6 'vendor/jquery.js' : exports: '$'
7 7 'vendor/underscore.js' : exports: '_'
8 8 'vendor/backbone.js' : exports: 'Backbone', imports: '_'

0 comments on commit 5269df4

Please sign in to comment.
Something went wrong with that request. Please try again.