content-tree
v0.0.1
Published
Generate a json representation of a file tree with file information
Downloads
12
Readme
node-content-tree
Generate a json representation of a file tree with file information
Installation
npm install content-tree
Usage
var tree = require('content-tree')('/path/to/directory');
tree.generate(function(tree){
console.log(tree);
});
Or if you want a promise based interface
var tree = require('content-tree')('/path/to/directory');
tree.generate().then(function(tree){
console.log(tree);
});
Then it's probably useful to use something like traverse.
File object information
Each file object will have not only the file path but the stat file object as well as mime type and charset information:
{
path: 'file path',
basename: 'file basename',
stat: [Stat object],
mimeType: 'file mimetype',
charset: 'file charset'
}
If you wish to enhance the information for each object, you can use the
file
event as such:
var somePath = '/path/to/directory';
var tree = require('content-tree')(somePath);
tree.on('file', function(file){
file.relativePath = file.path.replace(somePath +'/', '');
})
tree.generate();
API
TODO: finish this section
generate
getRelativePath
getRelativeFilePath
Events
file
TODO
- finish documentation
- tests