directory-tree
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -28,2 +28,3 @@ import { Stats } from 'fs'; | ||
followSymlink ? : boolean; | ||
depth ? : number; | ||
} | ||
@@ -30,0 +31,0 @@ export type DirectoryTreeCallback = (item: DirectoryTree, path: string, stats: Stats) => void; |
@@ -51,3 +51,7 @@ 'use strict'; | ||
*/ | ||
function directoryTree (path, options, onEachFile, onEachDirectory) { | ||
function directoryTree (path, options, onEachFile, onEachDirectory, currentDepth = 0) { | ||
if (options.depth !== undefined && options.attributes.indexOf('size') !== -1) { | ||
throw new Error('usage of size attribute with depth option is prohibited'); | ||
} | ||
const name = PATH.basename(path); | ||
@@ -123,5 +127,7 @@ options = options || {}; | ||
item.children = dirData | ||
.map(child => directoryTree(PATH.join(path, child), options, onEachFile, onEachDirectory)) | ||
.filter(e => !!e); | ||
if (options.depth === undefined || options.depth > currentDepth) { | ||
item.children = dirData | ||
.map(child => directoryTree(PATH.join(path, child), options, onEachFile, onEachDirectory, currentDepth + 1)) | ||
.filter(e => !!e); | ||
} | ||
@@ -128,0 +134,0 @@ if (options.attributes) { |
{ | ||
"name": "directory-tree", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "Convert a directory tree to a JS object.", | ||
@@ -20,2 +20,6 @@ "repository": { | ||
"homepage": "https://github.com/mihneadb/node-directory-tree", | ||
"dependencies": { | ||
"command-line-args": "^5.2.0", | ||
"command-line-usage": "^6.1.1" | ||
}, | ||
"devDependencies": { | ||
@@ -25,2 +29,3 @@ "chai": "^2.3.0", | ||
}, | ||
"bin": "bin/index.js", | ||
"engines": { | ||
@@ -27,0 +32,0 @@ "node": ">=10.0" |
@@ -86,2 +86,4 @@ [![Build Status](https://api.travis-ci.com/mihneadb/node-directory-tree.svg?branch=master)](https://api.travis-ci.com/mihneadb/node-directory-tree.svg?branch=master) | ||
`depth` : `number` - If presented, reads so many nested dirs as specified in argument. Usage of size attribute with depth option is prohibited. | ||
## Result | ||
@@ -190,1 +192,20 @@ | ||
Check out version `0.1.1` if you need support for older versions of Node. | ||
## CLI usage | ||
You can use script directly from command line for generating json data. | ||
```bash | ||
$ npx directory-tree --help | ||
``` | ||
```bash | ||
$ npx directory-tree --path /Users/user/target --attributes type,extension --pretty -o ./xz.json --depth 1 | ||
``` | ||
### Available options | ||
-p, --path string 🗂 The input folder to process. Required. | ||
-e, --exclude string 🐒 Exclude some folders from processing by regexp string. Ex -e "test_data/some_dir$|js|.DS_Store" | ||
-o, --output string 📝 Put result into file provided by this options. Overwrites if exists. | ||
-d, --depth number ☞ Reads dirs in deep as specified. Usage of size attribute with depth option is prohibited. | ||
--attributes string ℹ️ Grab file attributes. Example: --attributes size,type,extension. Usage of size attribute with depth option is prohibited | ||
--pretty 💎 Json pretty print |
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
16676
11
263
210
2
2
+ Addedcommand-line-args@^5.2.0
+ Addedcommand-line-usage@^6.1.1
+ Addedansi-styles@3.2.1(transitive)
+ Addedarray-back@3.1.04.0.2(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedcommand-line-args@5.2.1(transitive)
+ Addedcommand-line-usage@6.1.3(transitive)
+ Addeddeep-extend@0.6.0(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfind-replace@3.0.0(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedlodash.camelcase@4.3.0(transitive)
+ Addedreduce-flatten@2.0.0(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedtable-layout@1.0.2(transitive)
+ Addedtypical@4.0.05.2.0(transitive)
+ Addedwordwrapjs@4.0.1(transitive)