Skip to content

Repository files navigation

dir-tree

Build statusCode Climate

dir-tree is a simple directory tree scanner for node, which supports directory level update, filters, display tree structure and so on.

Install

Assumed you have the node env.

npmidir-tree-scanner

Usage

Find

You can use find function as a try.

vardirTree=require('dir-tree-scanner');varpath='./test';dirTree.find(path).then(function(result){console.log(result);},function(err){console.log('err:',err);},function(data){console.log('progress: ',data);});

To make result more intuitive, you can use the display function.

vardirTree=require('dir-tree-scanner');varpath='./test';dirTree.find(path).then(function(result){dirTree.display(result.data);},function(err){console.log('err:',err);},function(data){console.log('progress: ',data);});

You can use filters as well.

vardirTree=require('dir-tree-scanner');varpath='./test';dirTree.find(path,{file: ['.js','.md']// the same as regular expression// file: /(\.js|\.md)$/}).then(function(result){dirTree.display(result.data);},function(err){console.log('err:',err);},function(data){console.log('progress: ',data);});

#Example

Use It For Mocha Test

Below is an example using dir-tree-scanner to do mocha test. The functionality of the code is the same as mocha cli to some extent. Remember to install all the dependencies to run the example.

vardirTree=require('dir-tree-scanner');varpath=require('path');varQ=require('q');varexec=require('child_process').exec;require('colors');dir_tree.find('./test',{file: /(\.t\.js)$/}).then(function(srcTree){vartestSrc=srcTree.data[0].children;loopTest(testSrc);});functionloopTest(testSrc){if(testSrc.length>0){doTest(testSrc.shift().name).then(function(){loopTest(testSrc);},function(err){console.log(err.red);})}}functiondoTest(testFile){returnQ.Promise(function(resolve,reject){varmochaTest=exec('mocha '+testFile);varbanner='----------------------';console.log((banner+path.basename(testFile)+' start '+banner).green);mochaTest.stdout.on('data',function(data){console.log(data);});mochaTest.stderr.on('data',function(err){console.log(err.red);});mochaTest.on('close',function(code){console.log((banner+path.basename(testFile)+' end '+banner).green);console.log('child process exited with code '+code);resolve();});mochaTest.on('error',function(err){console.log(err);reject();});});}

About

Directory Tree Scanner For Node

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages