Skip to content

Commit

Permalink
[doc] Comments and cleanup on helpers.js and fs2.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jfhbrook committed Nov 5, 2011
1 parent 5b15fa0 commit 4559c53
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 138 deletions.
21 changes: 10 additions & 11 deletions lib/fs2.js
Expand Up @@ -89,9 +89,8 @@ fs2.dirToTree = function (dir) {

// Same as filesToTree, except we use Object.keys which is equivalent to the
// original list of files.
var _tree = fs2.filesToTree(Object.keys(dir));
return fs2.filesToTree(Object.keys(dir));

return _tree;
}


Expand All @@ -109,10 +108,9 @@ fs2.orderedTree = function (tree) {

// Take each subtree in the hash and replace it with an ordered subtree.
var subtrees = Hash(tree).map(function (v) {
return ordered(v);
}).items;

var _tree = [];
return ordered(v);
}).items,
_tree = [];

// This tree still needs to be ordered itself!
Object.keys(subtrees).forEach(function(k) {
Expand Down Expand Up @@ -157,12 +155,13 @@ fs2.readDir = function (p, resolve, filter, cb) {
}


var files = [];
var files = [],
finder;

// Finder throws errors instead of passing them, so we use a "try" to funnel
// any errors to the callback.
try {
var finder = findit.find(p, function (f) {
finder = findit.find(p, function (f) {
// This gets called for each individual file. Here we collect them all.
files.push(f);
});
Expand All @@ -188,10 +187,10 @@ fs2.readDir = function (p, resolve, filter, cb) {
// throws its errors, but is otherwise equivalent.
fs2.readDirSync = function (p, resolve, filter) {

// sync version returns a list of directories already.
// findit.sync returns a list of directories already.
var files = findit.sync(p);

if( typeof filter === 'function') {
if ( typeof filter === 'function') {
// Apply the filter, if any.
files = files.filter(filter);
}
Expand All @@ -209,7 +208,7 @@ fs2.writeFile = function(filePath, contents, callback) {
var fileDir = path.dirname(filePath);

mkdirp(fileDir, 0755, function(err){
if(err){
if (err) {
callback(err);
}
fs.writeFile(filePath, contents, callback);
Expand Down

0 comments on commit 4559c53

Please sign in to comment.