Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

passing test but actually the path resolution is screwy

  • Loading branch information...
commit eded1a3f74662f4f044e412373697ce8b3a03bb2 1 parent a420460
@substack authored
Showing with 29 additions and 34 deletions.
  1. +1 −0  browser/files.js
  2. +23 −30 index.js
  3. +5 −1 package.json
  4. +0 −3  wrapper.js
View
1  browser/files.js
@@ -0,0 +1 @@
+module.exports = $bodies
View
53 index.js
@@ -3,57 +3,50 @@ var path = require('path');
var findit = require('findit');
var Seq = require('seq');
-var wrapper = fs.readFileSync(__dirname + '/wrapper.js', 'utf8');
-
module.exports = function (name, dir, ext) {
if (!name) throw new Error('Name required');
if (!dir) throw new Error('Directory or files required');
- return function (src, next) {
- var find = findit(dir);
-
- var files = [];
-
- find.on('file', function (absfile) {
+ return function (bundle) {
+ var files = findit.sync(dir).filter(function (absfile) {
var file = absfile.replace(dir.match(/\/$/) ? dir : dir + '/', '');
var e = (file.match(/\.([^\/.]+)$/) || [,''])[1];
if (typeof ext === 'function' && ext(file, e)) {
- files.push(file);
+ return true;
}
else if (file.split('/').some(function (p) {
return p.match(/^\./)
})) {
- // nop for hidden files and directories
+ // hidden files and directories
+ return false;
}
else if (Array.isArray(ext) && ext.indexOf(e) >= 0) {
- files.push(file);
+ return true;
}
else if (typeof ext === 'string' && e === ext) {
- files.push(file);
+ return true;
}
else if (!ext) {
- files.push(file);
+ return true;
}
});
- find.on('end', function () {
- Seq.ap(files)
- .parEach(15, function (file) {
- fs.readFile(dir + '/' + file, 'utf8', this.into(file));
- })
- .seq(function () {
- var vars = this.vars;
- next(src + wrapper
- .replace('$vars', function () {
- return JSON.stringify(vars)
- })
- .replace('$name', function () {
- return JSON.stringify(name)
- })
- );
- })
- ;
+ var bodies = files.reduce(function (acc, file) {
+ var rel = file.slice(dir.length);
+ acc[rel] = fs.readFileSync(file, 'utf8');
+ return acc;
+ }, {});
+
+ bundle.register(function (body, file) {
+ if (file === __dirname + '/browser/files.js') {
+ return body.replace(/\$bodies/, function () {
+ return JSON.stringify(bodies);
+ });
+ }
+ else return body;
});
+
+ bundle.require(__dirname + '/browser/files.js');
};
};
View
6 package.json
@@ -12,7 +12,11 @@
"seq" : ">=0.2.5 <0.3"
},
"devDependencies" : {
- "browserify" : "1.0.x"
+ "browserify" : "1.2.x",
+ "expresso" : "0.7.x"
+ },
+ "scripts" : {
+ "test" : "expresso"
},
"repository" : {
"type" : "git",
View
3  wrapper.js
@@ -1,3 +0,0 @@
-require.modules[$name] = function () {
- return $vars
-};
Please sign in to comment.
Something went wrong with that request. Please try again.