index.js
function tree(app, options) {
  var opts = extend({}, options);
  var node = {
    label: getLabel(app, opts),
    metadata: getMetadata(app, opts)
  };

  // get the names of the children to lookup
  var names = arrayify(opts.names || ['nodes']);
  return names.reduce(function(acc, name) {
    var children = app[name];
    if (typeof children !== 'object') {
      return node;
    }

    // build a tree for each child node
    var nodes = [];
    for (var key in children) {
      var child = children[key];
      if (typeof child[opts.method] === 'function') {
        nodes.push(child[opts.method](opts));
      } else {
        var res = tree(child, opts);
        nodes.push(res);
      }
    }

    if (nodes.length) {
      node.nodes = (node.nodes || []).concat(nodes);
    }
    return node;
  }, node);


}
function tree(app, options) {
  var opts = extend({}, options);
  var node = {
    label: getLabel(app, opts),
    metadata: getMetadata(app, opts)
  };

  // get the names of the children to lookup
  var names = arrayify(opts.names || ['nodes']);
  return names.reduce(function(acc, name) {
    var children = app[name];
    if (typeof children !== 'object') {
      return node;
    }

    // build a tree for each child node
    var nodes = [];
    for (var key in children) {
      var child = children[key];
      if (typeof child[opts.method] === 'function') {
        nodes.push(child[opts.method](opts));
      } else {
        var res = tree(child, opts);
        nodes.push(res);
      }
    }

    if (nodes.length) {
      node.nodes = (node.nodes || []).concat(nodes);
    }
    return node;
  }, node);


}
function tree ( app , options ) { var opts = extend ( { } , options ) ; var node = { label : getLabel ( app , opts ) , metadata : getMetadata ( app , opts ) } ; // get the names of the children to lookup var names = arrayify ( opts . names || [ 'nodes' ] ) ; return names . reduce ( function ( acc , name ) { var children = app [ name ] ; if ( typeof children !== 'object' ) { return node ; } // build a tree for each child node var nodes = [ ] ; for ( var key in children ) { var child = children [ key ] ; if ( typeof child [ opts . method ] === 'function' ) { nodes . push ( child [ opts . method ] ( opts ) ) ; } else { var res = tree ( child , opts ) ; nodes . push ( res ) ; } } if ( nodes . length ) { node . nodes = ( node . nodes || [ ] ) . concat ( nodes ) ; } return node ; } , node ) ; }
Default tree building function. Gets the label and metadata properties for the current `app` and
recursively generates the child nodes and child trees if possible.

This method may be overriden by passing a `.tree` function on options.

@param  {Object} `app` Current application to build a node and tree from.
@param  {Object} `options` Options used to control how the `label` and `metadata` properties are retreived.
@return {Object} Generated node containing `label`, `metadata`, and `nodes` properties for current segment of a tree.
@api public
@name  options.tree
Default tree building function . Gets the label and metadata properties for the current app and recursively generates the child nodes and child trees if possible .