-
-
Save Marak/395527 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Recursively traverse a hierarchy, returning | |
// a list of all relevant .js files. | |
// | |
function paths(dir) { | |
var paths = []; | |
try { fs.statSync(dir) } | |
catch (e) { return [] } | |
(function traverse(dir, stack) { | |
stack.push(dir); | |
fs.readdirSync(stack.join('/')).forEach(function (file) { | |
var path = stack.concat([file]).join('/'), | |
stat = fs.statSync(path); | |
if (file[0] == '.' || file === 'vendor') { | |
return; | |
} else if (stat.isFile() && /\.js$/.test(file)) { | |
paths.push(path); | |
} else if (stat.isDirectory()) { | |
traverse(file, stack); | |
} | |
}); | |
stack.pop(); | |
})(dir || '.', []); | |
return paths; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment