dir-tree-creator
Advanced tools
Comparing version 1.0.4 to 2.0.0
{ | ||
"name": "dir-tree-creator", | ||
"version": "1.0.4", | ||
"version": "2.0.0", | ||
"description": "simple directory tree structure creator based on the given root path", | ||
"main": "dirTree.js", | ||
"dependencies": { | ||
"archy": "^1.0.0", | ||
"fs-extra": "^0.26.7" | ||
}, | ||
"devDependencies": { | ||
"jshint": "^2.9.1" | ||
}, | ||
"main": "dir_tree_creator.js", | ||
"repository": { | ||
@@ -20,3 +13,3 @@ "type": "git", | ||
"tree", | ||
"file" | ||
"dir tree" | ||
], | ||
@@ -28,3 +21,8 @@ "author": "Mawni Maghsoudlou", | ||
}, | ||
"homepage": "https://github.com/mawni/dir-tree-nodejs#readme" | ||
"homepage": "https://github.com/mawni/dir-tree-nodejs#readme", | ||
"dependencies": { | ||
"archy": "^1.0.0", | ||
"async": "^2.1.2", | ||
"glob": "^7.1.1" | ||
} | ||
} |
107
readme.md
@@ -1,73 +0,56 @@ | ||
<p>dir-tree-creator is a node.js module that simply creates an npm like directory tree structure of the given path and returns the string representation of it. It also accepts an array of paths to ignore as an optional argument.</p> | ||
#dir-tree-creator | ||
<h5>Install</h5> | ||
[![npm](https://img.shields.io/npm/v/dir-tree-creator.svg?maxAge=2592000?style=flat-square)](https://www.npmjs.com/package/dir-tree-creator) | ||
Use `npm install dir-tree-creator` to install the module. If you want to add it to your application dependencies, simply run `npm install --save dir-tree-creator`. | ||
dir-tree-creator is a tiny module that creates an npm like directory tree structure of the given path and returns the string representation of it. | ||
<h5>Function Signature</h5> | ||
```javascript | ||
var dir_tree = require('dir-tree-creator'); | ||
dir_tree(root_path, root_label, paths_to_ignore, callback) | ||
``` | ||
root_path: path to root directory [type: string] | ||
root_label: label for the root node of the directory tree [type: string] | ||
paths_to_ignore: list of paths to ignore [type: array] | ||
callback function: it takes one argument, the final tree and returns the string representation of it [type: function] | ||
<h5>Usage</h5> | ||
####Install | ||
As of version 0.0.2, the function header changed. In the new version, the function takes 4 arguments. First argument is the root path. Second argument is the root label. The third argument is the optional array of paths to ignore. If there is no path to ignore, we set that to `null`. Finally, the fourth argument is the callback function that contains the string representation of the final directory tree. The string representation can be outputted to the console, or written to a file or whatever else we want to do with it. | ||
Please use `npm install dir-tree-creator`. | ||
<h5>Examples</h5> | ||
####API | ||
<h6>exp1: output to the console with nothing to ignore</h6> | ||
**dirtree(options, cb)** | ||
* `options` `{Object}` | ||
* `root` `{String}` root path | ||
* `label` `{String}` *(optional)* label for the root node of the directory tree; if nothing specified, then the root path's basename will be used. | ||
* `ignore` `{Array}` *(optional)* an array of [node-glob](https://github.com/isaacs/node-glob) patterns to ignore. By default, `node_modules` and `.git` are ignored. | ||
* `cb` `{Function}` | ||
* `err` `{Error | null}` | ||
* `dirtree` `{String}` String representation of the directory structure | ||
```javascript | ||
var dir_tree = require('dir-tree-creator'); | ||
var root_path = '/path/to/root/directory'; | ||
dir_tree(root_path, 'my root label', null, function(final_dir_tree) { | ||
console.log(final_dir_tree); | ||
const dir_tree = require('dir-tree-creator'); | ||
var opts = { | ||
root: __dirname, | ||
label: 'your custom label', | ||
ignore: ['foo.js', 'test/**'] // ignore foo.js and test dir | ||
}; | ||
dir_tree(opts, (er, tr) => { | ||
if (er) { | ||
console.error(er); | ||
} else { | ||
console.log(tr); | ||
} | ||
}); | ||
``` | ||
<h6>exp1 result:</h6> | ||
``` | ||
my root label | ||
├─┬ dir1 | ||
│ └── file1.js | ||
├─┬ dir2 | ||
│ ├─┬ dir3 | ||
│ │ └── file3.js | ||
│ └── file2.js | ||
├── file1-under-root.js | ||
└── file2-under-root.js | ||
``` | ||
<h6>exp2: output to the console with paths to ignore</h6> | ||
```javascript | ||
var dir_tree = require('dir-tree-creator'); | ||
var root_path = '/path/to/root/directory'; | ||
var paths_to_ignore = ['/path1/to/ignore', '/path2/to/ignore']; | ||
dir_tree(root_path, 'my root label', paths_to_ignore, function(final_dir_tree) { | ||
console.log(final_dir_tree); | ||
}); | ||
#####Sample output | ||
``` | ||
<h6>exp2 result (excluded dir1 as an example):</h6> | ||
your custom label | ||
├─┬ dir0 | ||
│ └── file0.js | ||
├─┬ dir1 | ||
│ ├─┬ dir2 | ||
│ │ └── file2.js | ||
│ └── file1.md | ||
├── file-under-root.js | ||
└── .gitignore | ||
``` | ||
my root label | ||
├─┬ dir2 | ||
│ ├─┬ dir3 | ||
│ │ └── file3.js | ||
│ └── file2.js | ||
├── file1-under-root.js | ||
└── file2-under-root.js | ||
``` | ||
<h6>exp3: write to a file</h6> | ||
```javascript | ||
var fs = require('fs'); | ||
var dir_tree = require('dir-tree-creator'); | ||
var root_path = '/path/to/root/directory'; | ||
dir_tree(root_path, 'my root label', null, function(final_dir_tree) { | ||
fs.writeFile('/dir-tree-structure.txt', final_dir_tree, 'utf8', function(err) { | ||
if (err) throw err; | ||
console.log('dir tree structure saved successfully'); | ||
}); | ||
}); | ||
``` | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
0
4894
3
55
57
+ Addedasync@^2.1.2
+ Addedglob@^7.1.1
+ Addedasync@2.6.4(transitive)
+ Addedlodash@4.17.21(transitive)
- Removedfs-extra@^0.26.7
- Removedfs-extra@0.26.7(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedjsonfile@2.4.0(transitive)
- Removedklaw@1.3.1(transitive)
- Removedrimraf@2.7.1(transitive)