Skip to content

tjhart/broccoli-tree-traverser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

broccoli-tree-traverser

A Broccoli plugin for managing src tree navigation.

The traverser takes a path and a Visitor.

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

Visitor

A visitor is 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; 

About

Manages src tree navigation, letting you deal with each file

Resources

License

Stars

Watchers

Forks

Packages

No packages published