Skip to content
Browse files

asynch version of getJsFilesRecursively, though it relies on the UNIX…

… find command iso of native Node API
  • Loading branch information...
1 parent 3b15c65 commit d59191a80b7e9f3552f8d6f5473c19c6870d47a6 @davybrion committed Aug 14, 2011
Showing with 15 additions and 24 deletions.
  1. +15 −24 lib/runner.js
View
39 lib/runner.js
@@ -1,37 +1,28 @@
var fs = require('fs'),
- path = require('path');
+ path = require('path'),
+ exec = require('child_process').exec;
// TODO: rewrite this to make it fully asynchronous
-function getJsFileNamesRecursivelySync(start) {
- var stat = fs.lstatSync(start),
- allJsFiles = [];
- if (!stat.isDirectory()) { return []; }
-
- var files = fs.readdirSync(start);
-
- files.forEach(function(f) {
- var fullpath = path.join(start, f),
- subStat = fs.lstatSync(fullpath);
-
- if (subStat.isDirectory() && !/node_modules\//.test(fullpath)) {
- allJsFiles = allJsFiles.concat(getJsFileNamesRecursivelySync(fullpath));
- }
- else {
- if (/.js$/.test(fullpath)) {
- allJsFiles.push(fullpath);
+function getJsFilesRecursively(startPath, callback) {
+ exec('find ' + startPath, function(err, stdout) {
+ var jsFiles = []
+ stdout.split('\n').forEach(function(f) {
+ if (!/node_modules\//.test(f) && /.js$/.test(f)) {
+ jsFiles.push(f);
};
- }
- });
+ });
- return allJsFiles;
+ callback(null, jsFiles);
+ });
};
module.exports = {
check: function(path, options, callback) {
- var jsFiles = getJsFileNamesRecursivelySync(path);
- jsFiles.forEach(function(f) {
- console.log(f);
+ getJsFilesRecursively(path, function(err, jsFiles) {
+ jsFiles.forEach(function(f) {
+ console.log(f);
+ });
});
callback(null, null);

0 comments on commit d59191a

Please sign in to comment.
Something went wrong with that request. Please try again.