directory-tree 2.3.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/node.js.yml +31 -0
- package/.idea/encodings.xml +4 -0
- package/.idea/modules.xml +8 -0
- package/.idea/node-directory-tree.iml +8 -0
- package/.idea/vcs.xml +6 -0
- package/README.md +3 -3
- package/index.d.ts +2 -2
- package/lib/directory-tree.js +31 -11
- package/package.json +1 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
|
|
2
|
+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
|
3
|
+
|
|
4
|
+
name: Node.js CI
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
push:
|
|
8
|
+
branches: [ master ]
|
|
9
|
+
pull_request:
|
|
10
|
+
branches: [ master ]
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
|
|
17
|
+
strategy:
|
|
18
|
+
matrix:
|
|
19
|
+
node-version: [12.x, 14.x, 16.x]
|
|
20
|
+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
|
21
|
+
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@v2
|
|
24
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
25
|
+
uses: actions/setup-node@v2
|
|
26
|
+
with:
|
|
27
|
+
node-version: ${{ matrix.node-version }}
|
|
28
|
+
cache: 'npm'
|
|
29
|
+
- run: npm ci
|
|
30
|
+
- run: npm run build --if-present
|
|
31
|
+
- run: npm test
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/node-directory-tree.iml" filepath="$PROJECT_DIR$/.idea/node-directory-tree.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="WEB_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager">
|
|
4
|
+
<content url="file://$MODULE_DIR$" />
|
|
5
|
+
<orderEntry type="inheritedJdk" />
|
|
6
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
7
|
+
</component>
|
|
8
|
+
</module>
|
package/.idea/vcs.xml
ADDED
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[](https://api.travis-ci.com/mihneadb/node-directory-tree.svg?branch=master)
|
|
2
2
|
|
|
3
3
|
# directory-tree
|
|
4
4
|
|
|
@@ -48,7 +48,7 @@ const dirTree = require('directory-tree');
|
|
|
48
48
|
const filteredTree = dirTree('/some/path', {attributes:['mode', 'mtime']});
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
The default attributes are `[name,
|
|
51
|
+
The default attributes are `[name, path]` for Files and `[name, path, children]` for Directories
|
|
52
52
|
|
|
53
53
|
A callback function can be executed with each file that matches the extensions provided:
|
|
54
54
|
|
|
@@ -98,7 +98,7 @@ photos
|
|
|
98
98
|
└── snowboard.jpg
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
-
`directory-tree` will return this JS object:
|
|
101
|
+
`directory-tree` with `attributes: ["size", "type", "extension"]` will return this JS object:
|
|
102
102
|
|
|
103
103
|
```json
|
|
104
104
|
{
|
package/index.d.ts
CHANGED
|
@@ -22,11 +22,11 @@ declare namespace directoryTree {
|
|
|
22
22
|
export interface DirectoryTreeOptions {
|
|
23
23
|
normalizePath ? : boolean;
|
|
24
24
|
exclude ? : RegExp | RegExp[];
|
|
25
|
-
attributes ? : (keyof
|
|
25
|
+
attributes ? : (keyof Stats | "type" | "extension")[];
|
|
26
26
|
extensions ? : RegExp;
|
|
27
27
|
followSymlink ? : boolean;
|
|
28
28
|
}
|
|
29
29
|
export type DirectoryTreeCallback = (item: DirectoryTree, path: string, stats: Stats) => void;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export = directoryTree;
|
|
32
|
+
export = directoryTree;
|
package/lib/directory-tree.js
CHANGED
|
@@ -80,7 +80,7 @@ function directoryTree (path, options, onEachFile, onEachDirectory) {
|
|
|
80
80
|
options = { ...options, symlinks: [] };
|
|
81
81
|
// Skip if a cyclic symbolic link has been found
|
|
82
82
|
if (options.symlinks.find(ino => ino === lstat.ino)) {
|
|
83
|
-
return null;
|
|
83
|
+
return null;
|
|
84
84
|
} else {
|
|
85
85
|
options.symlinks.push(lstat.ino);
|
|
86
86
|
}
|
|
@@ -94,13 +94,20 @@ function directoryTree (path, options, onEachFile, onEachDirectory) {
|
|
|
94
94
|
if (options.extensions && !options.extensions.test(ext))
|
|
95
95
|
return null;
|
|
96
96
|
|
|
97
|
-
item.size = stats.size; // File size in bytes
|
|
98
|
-
item.extension = ext;
|
|
99
|
-
item.type = constants.FILE;
|
|
100
97
|
|
|
101
98
|
if (options.attributes) {
|
|
102
99
|
options.attributes.forEach((attribute) => {
|
|
103
|
-
|
|
100
|
+
switch (attribute) {
|
|
101
|
+
case 'extension':
|
|
102
|
+
item.extension = ext;
|
|
103
|
+
break;
|
|
104
|
+
case 'type':
|
|
105
|
+
item.type = constants.FILE;
|
|
106
|
+
break;
|
|
107
|
+
default:
|
|
108
|
+
item[attribute] = stats[attribute];
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
104
111
|
});
|
|
105
112
|
}
|
|
106
113
|
|
|
@@ -112,16 +119,29 @@ function directoryTree (path, options, onEachFile, onEachDirectory) {
|
|
|
112
119
|
let dirData = safeReadDirSync(path);
|
|
113
120
|
if (dirData === null) return null;
|
|
114
121
|
|
|
122
|
+
item.children = dirData
|
|
123
|
+
.map(child => directoryTree(PATH.join(path, child), options, onEachFile, onEachDirectory))
|
|
124
|
+
.filter(e => !!e);
|
|
125
|
+
|
|
115
126
|
if (options.attributes) {
|
|
116
127
|
options.attributes.forEach((attribute) => {
|
|
117
|
-
|
|
128
|
+
switch (attribute) {
|
|
129
|
+
case 'size':
|
|
130
|
+
item.size = item.children.reduce((prev, cur) => prev + cur.size, 0);
|
|
131
|
+
break;
|
|
132
|
+
case 'type':
|
|
133
|
+
item.type = constants.DIRECTORY;
|
|
134
|
+
break;
|
|
135
|
+
case 'extension':
|
|
136
|
+
break;
|
|
137
|
+
default:
|
|
138
|
+
item[attribute] = stats[attribute];
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
|
|
118
142
|
});
|
|
119
143
|
}
|
|
120
|
-
|
|
121
|
-
.map(child => directoryTree(PATH.join(path, child), options, onEachFile, onEachDirectory))
|
|
122
|
-
.filter(e => !!e);
|
|
123
|
-
item.size = item.children.reduce((prev, cur) => prev + cur.size, 0);
|
|
124
|
-
item.type = constants.DIRECTORY;
|
|
144
|
+
|
|
125
145
|
if (onEachDirectory) {
|
|
126
146
|
onEachDirectory(item, path, stats);
|
|
127
147
|
}
|