Permalink
Browse files

Allow exports to different location

  • Loading branch information...
1 parent c4b16ec commit d696a1f89a5012a26a34df769eb3c4a40b4f6418 @Gozala Gozala committed Mar 14, 2013
Showing with 6 additions and 2 deletions.
  1. +6 −2 index.js
View
@@ -2,12 +2,15 @@ var fs = require('fs');
var path = require('path');
var EventEmitter = require('events').EventEmitter;
+function _resolve(path) { return path + '.js'; }
+
module.exports = function (files, opts) {
if (!opts) opts = {};
if (!files) files = [];
if (!Array.isArray(files)) files = [ files ];
if (opts.ext && !/^\./.test(opts.ext)) opts.ext = '.' + opts.ext;
var emitter = new EventEmitter;
+ var resolve = opts.resolve || _resolve
var pending = files.length;
files.forEach(function (file) {
@@ -22,8 +25,9 @@ module.exports = function (files, opts) {
}
var rs = fs.createReadStream(file);
+ var dest = resolve(file);
rs.on('error', emitter.emit.bind(emitter, 'error'));
- var ws = fs.createWriteStream(file + '.js');
+ var ws = fs.createWriteStream(dest);
ws.on('error', emitter.emit.bind(emitter, 'error'));
ws.write('module.exports="');
@@ -33,7 +37,7 @@ module.exports = function (files, opts) {
});
rs.on('end', function () {
ws.end('"\n');
- emitter.emit('export', file);
+ emitter.emit('export', file, dest);
if (--pending === 0) emitter.emit('end');
});
});

0 comments on commit d696a1f

Please sign in to comment.