Permalink
Browse files

changed find.js so that it finds out whether the given path is a js file

  • Loading branch information...
1 parent ae715bf commit a8e84252d501cf26659713d2388494e745eb4aca @saschagehlich saschagehlich committed Aug 3, 2011
Showing with 28 additions and 14 deletions.
  1. +28 −14 lib/find.js
View
42 lib/find.js
@@ -29,28 +29,42 @@ module.exports = function(paths, fn){
, ret = [];
function find(path) {
- fs.readdir(path, function(err, files){
+ fs.stat(path, function(err, stat) {
if (err) {
fn(err);
fn = noop;
return
}
+
+ if(stat.isFile() && isJavaScript(path)) {
+ ret.push(path);
+
+ --pending || fn(null, ret);
+ } else {
+ fs.readdir(path, function(err, files){
+ if (err) {
+ fn(err);
+ fn = noop;
+ return
+ }
- files.forEach(function(file){
- file = join(path, file);
- if (isJavaScript(file)) {
- ret.push(file);
- } else {
- ++pending;
- fs.stat(file, function(err, stat){
- if (err) return;
- if (!stat.isDirectory()) return --pending || fn(null, ret);
- find(file);
+ files.forEach(function(file){
+ file = join(path, file);
+ if (isJavaScript(file)) {
+ ret.push(file);
+ } else {
+ ++pending;
+ fs.stat(file, function(err, stat){
+ if (err) return;
+ if (!stat.isDirectory()) return --pending || fn(null, ret);
+ find(file);
+ });
+ }
});
- }
- });
- --pending || fn(null, ret);
+ --pending || fn(null, ret);
+ });
+ }
});
}

0 comments on commit a8e8425

Please sign in to comment.