Skip to content

Commit

Permalink
upgrading runnel and using it's seed feature
Browse files Browse the repository at this point in the history
  • Loading branch information
thlorenz committed Jul 6, 2013
1 parent 3ffdfc1 commit abcf401
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
46 changes: 22 additions & 24 deletions index.js
Expand Up @@ -31,30 +31,28 @@ module.exports = function addRemoteScripts(bify, remote, cb) {
var keys = Object.keys(remote);
if (!keys.length) return cb(null, []);

var gens = [];

var tasks = keys
.map(function (k) {
var rem = remote[k];
rem.key = k;

return function (cb) {
genRemote(rem, function (err, gen) {
if (err) return cb(err);
gens.push(gen);
cb();
});
};
})
.concat(genIndex.bind(null, gens))
.concat(
function (err) {
if (err) return cb(err);
if (bify) gens.forEach(function (gen) { bify.add(gen); });

cb(null, gens);
}
);
var tasks = [ runnel.seed([]) ]
.concat(keys.map(
function (k) {
var rem = remote[k];
rem.key = k;

return function (acc, cb) {
genRemote(rem, function (err, gen) {
if (err) return cb(err);
acc.push(gen);
cb(null, acc);
});
};
})
)
.concat(genIndex)
.concat(function done (err, acc) {
if (err) return cb(err);
if (bify) acc.forEach(bify.add.bind(bify));

cb(null, acc);
});

runnel(tasks);
});
Expand Down
6 changes: 4 additions & 2 deletions lib/gen-index.js
Expand Up @@ -16,7 +16,7 @@ var genPath = path.join(__dirname, '..', 'loaders');
* @name genIndex
* @function
* @param fullPaths {Array} of full paths to the loader files
* @param cb {Function} calls back with error or none
* @param cb {Function} calls back with error or none and same fullPaths that were passed in
*/
var genIndex = module.exports = function (fullPaths, cb) {
if (!fullPaths.length) cb(null);
Expand All @@ -30,5 +30,7 @@ var genIndex = module.exports = function (fullPaths, cb) {
var s = index({ keys: keys });

var filePath = path.join(genPath, 'index.js');
fs.writeFile(filePath, s, 'utf8', cb);
fs.writeFile(filePath, s, 'utf8', function (err) {
cb(err, fullPaths);
});
};
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -16,7 +16,7 @@
"scriptjs": "~2.4.0",
"xtend": "~2.0.6",
"handlebars": "~1.0.12",
"runnel": "~0.4.1"
"runnel": "~0.5.0"
},
"devDependencies": {
"tape": "~1.0.4",
Expand Down

0 comments on commit abcf401

Please sign in to comment.