Skip to content

Commit

Permalink
Process: skip file if not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy351 committed Mar 3, 2013
1 parent 970a938 commit 2515be5
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,37 +65,40 @@ module.exports = function(files, callback){
type = 'update';
}

var tasks = getProcessor(path);
if (!tasks.length) return next();

var source = sourceDir + path;

var obj = {
source: source,
path: path,
type: type,
read: function(){
var args = _.toArray(arguments),
callback = args.pop(),
encoding = args[0] ? args[0] : 'utf8';
fs.exists(source, function(exist){
if (!exist) return next();
var tasks = getProcessor(path);
if (!tasks.length) return next();

fs.readFile(source, function(err, content){
if (err) return callback(err);
if (encoding !== 'buffer'){
content = content.toString('utf8');
if (EOL !== '\n') content = content.replace(EOLre, '\n');
}
callback(err, content);
});
},
stat: function(callback){
fs.stat(source, callback);
}
};
var obj = {
source: source,
path: path,
type: type,
read: function(){
var args = _.toArray(arguments),
callback = args.pop(),
encoding = args[0] ? args[0] : 'utf8';

fs.readFile(source, function(err, content){
if (err) return callback(err);
if (encoding !== 'buffer'){
content = content.toString('utf8');
if (EOL !== '\n') content = content.replace(EOLre, '\n');
}
callback(err, content);
});
},
stat: function(callback){
fs.stat(source, callback);
}
};

async.forEach(tasks, function(task, next){
task.fn(_.extend(obj, {params: task.params}), next);
}, next);
async.forEach(tasks, function(task, next){
task.fn(_.extend(obj, {params: task.params}), next);
}, next);
});
}, function(){
hexo.emit('processAfter');
callback();
Expand Down

0 comments on commit 2515be5

Please sign in to comment.