btt

broccoli-tree-to-json

roll up a tree into a JSON document

Showing:

Popularity

Downloads/wk

1

GitHub Stars

1

Maintenance

Last Commit

7yrs ago

Contributors

1

Package

Dependencies

3

Size (min+gzip)

22.2KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

broccoli-tree-to-json

A Broccoli plugin for rolling up a directory tree into a JSON document.

The directory structure:

root
|--key1.txt #123
|--key2.txt #val2
+--subdir
   |--key3.txt #true
   +--key4.txt #val4

Will result in the following json:

//destDir/root.json
{
  "key1":123,
  "key2":"val2",
  "subdir":{
    "key3":true,
    "key4":"val4"
  }
}

The file extension is ignored. The JSON key is determined by the portion of the file to the left of the first dot.

File contents are parsed by JSON.parse, and if that fails the contents of the file is treated like a string.

TODO

  • Better Array support

Example use

In a Brocfile:

//Brocfile.js
var tree2Json = require('broccoli-tree-to-json');

module.exports = tree2Json('interesting/path');

Within another plugin

//index.js
var tree2Json = require('broccoli-tree-to-json'),
  path = require('path');

function MyPlugin(inputTree){
  this.jsonTree = tree2Json(path.join(inputTree, 'json'));
}

MyPlugin.prototype.read = function(readTree){
  return readTree(this.jsonTree)
    .then(function(){
      //...
    });
};

module.exports = MyPlugin; 

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial