Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions lib/assetmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var fs = require('fs')
, jsmin = require('./../deps/jsmin').minify
, htmlmin = require('./../deps/htmlmin').minify
, cssmin = require('./../deps/cssmin').minify
, crypto = require('crypto');
, crypto = require('crypto')
, async = require('async');

var zlib;
try {
Expand All @@ -17,6 +18,25 @@ var cache = {}
, cacheHashes = {}
, cacheTimestamps = {};

var q = async.queue(function (task, callback) {
(function (task, fileInfo) {
file = task.file
fileInfo = task.fileInfo
fs.readFile(file, function (err, data) {
if (err) {
console.log('Could not find: '+file);
callback(null, '');
return;
}
fileInfo.content = data.toString();
fs.stat(file, function (err, stat) {
fileInfo.modified = stat.mtime;
callback(null, fileInfo);
});
});
})(task);
}, 10);

module.exports = function assetManager (assets) {
var self = this;

Expand Down Expand Up @@ -142,6 +162,7 @@ module.exports = function assetManager (assets) {
userAgentMatches = Object.keys(userAgentMatches);
}


userAgentMatches.forEach(function(match) {
var path = group.path;
Step(function () {
Expand Down Expand Up @@ -306,21 +327,9 @@ module.exports = function assetManager (assets) {
callback(null, fileInfo);
});
} else {
setTimeout(function() {
fs.readFile(path+file, function (err, data) {
if (err) {
console.log('Could not find: '+file);
callback(null, '');
return;
}
fileInfo.content = data.toString();

fs.stat(path+file, function (err, stat) {
fileInfo.modified = stat.mtime;
callback(null, fileInfo);
});
});
}, 100);
q.push({fileInfo: fileInfo, file: path+file}, function (err, fileInfo) {
callback(err, fileInfo);
});
}
};

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
"directories" : { "lib" : "./lib" },
"main" : "./lib/assetmanager",
"repository" : [
{ "type":"git", "url":"http://github.com/mape/connect-assetmanager.git" }
{ "type":"git", "url":"http://github.com/lordkada/connect-assetmanager.git" }
],
"dependencies" : {
"request" : ">=0.10.0",
"step" : ">=0.0.3"
"step" : ">=0.0.3",
"async" : "0.1.22"
}
}