0.1.1 • Published 9 years ago

broccoli-tree-traverser v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

broccoli-tree-traverser

Manages src tree navigation, letting you deal with each file.

The traverser takes a path and a Visitor.

It traverses the input path, calling visitor#visit for each file it finds.

Visitor

A visitor can be any object with a visit method. the visit method takes a file path (string) located somewhere along the input path. It should return a promise if it does anything asynchronously.

Future enhancements

Traversal

The traversal algorithm is an in-order traversal. That is, it traverses files and directories in the order returned by fs.readdir. Feel free to submit pull requests with other traversal algorithms.

Visit Directories

The traverser only calls visit for plain files. Feel free to submit pull requests if you want to visit directories.

Example use

In a Brocfile:

//Brocfile.js
var traverser = require('broccoli-tree-traverser');

var visitor = {
  visit:function(path){
    console.log('visiting', path);  
  }
};

module.exports = traverser('interesting/path', visitor);

Within another plugin

//index.js
var traverser = require('broccoli-tree-traverser');


function MyPlugin(inputTree){
  this.traverser = traverser(inputTree, this);
}

MyPlugin.prototype.visit = function(path){
  //do something interesting with the path
};

MyPlugin.prototype.read = function(readTree){
  return readTree(this.traverser);
};


module.exports = MyPlugin;