filter-scan-dir 1.2.0 → 1.5.0
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/CHANGELOG.md +20 -0
- package/LICENSE +201 -0
- package/README.md +35 -91
- package/dist/filter-scan-dir.d.ts +126 -0
- package/dist/filter-scan-dir.js +357 -0
- package/dist/filter-scan-dir.js.map +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +9 -205
- package/package.json +16 -5
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# v1.5.0
|
|
2
|
+
|
|
3
|
+
- add `fullStat` option to allow enable using the `withFileTypes` option of readdir for huge performance boost (requires node.js 10.10+) [node.js docs](https://nodejs.org/api/fs.html#fsreaddirpath-options-callback).
|
|
4
|
+
- add `concurrency` option to allow using concurrent mode in async version for massive performance boost.
|
|
5
|
+
- convert to typescript
|
|
6
|
+
|
|
7
|
+
# v1.4.1
|
|
8
|
+
|
|
9
|
+
- use fs.lstat instead of fs.stat
|
|
10
|
+
|
|
11
|
+
# v1.4.0
|
|
12
|
+
|
|
13
|
+
- process files before directories
|
|
14
|
+
|
|
15
|
+
# v1.3.0
|
|
16
|
+
|
|
17
|
+
- `sortFiles` option
|
|
18
|
+
- support filter callbacks returning `result.formatName`
|
|
19
|
+
- CI
|
|
20
|
+
- readme badges
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2021 Joel Chen
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
# filter-scan-dir
|
|
2
2
|
|
|
3
|
+
[![dependency status][deps-svg]][deps-url]
|
|
4
|
+
[![dev dependency status][dev-deps-svg]][dev-deps-url]
|
|
5
|
+
[![License][license-image]][license-url]
|
|
6
|
+
[![build][build-image]][build-url]
|
|
7
|
+
[![coverage][coverage-image]][coverage-url]
|
|
8
|
+
|
|
9
|
+
[![Downloads][downloads-image]][downloads-url]
|
|
10
|
+
|
|
11
|
+
[![npm badge][npm-badge-png]][package-url]
|
|
12
|
+
|
|
3
13
|
Recursively scan and filter directory for a flat array of files.
|
|
4
14
|
|
|
15
|
+
- Supports super fast concurrent mode in async version.
|
|
16
|
+
|
|
17
|
+
- **[API Docs](https://jchip.github.io/filter-scan-dir/modules.html#filterScanDir)**
|
|
18
|
+
- **[Github](https://github.com/jchip/filter-scan-dir)**
|
|
19
|
+
|
|
5
20
|
# Install
|
|
6
21
|
|
|
7
22
|
```bash
|
|
@@ -10,103 +25,32 @@ npm install --save filter-scan-dir
|
|
|
10
25
|
|
|
11
26
|
# Usage
|
|
12
27
|
|
|
13
|
-
```
|
|
14
|
-
|
|
28
|
+
```ts
|
|
29
|
+
import { filterScanDir, filterScanDirSync } from "filter-scan-dir";
|
|
15
30
|
|
|
16
31
|
// sync
|
|
17
|
-
|
|
18
|
-
console.log(files);
|
|
32
|
+
console.log(filterScanDirSync({ cwd: "test" }));
|
|
19
33
|
|
|
20
34
|
// async
|
|
21
|
-
filterScanDir({
|
|
22
|
-
console.log(files);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
console.log(await filterScanDir({ dir: "test" }));
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## API
|
|
29
|
-
|
|
30
|
-
`filterScanDir(options)` or `filterScanDir(dir)`
|
|
31
|
-
|
|
32
|
-
Sync version: `filterScanDir.sync`
|
|
33
|
-
|
|
34
|
-
`options`:
|
|
35
|
-
|
|
36
|
-
| name | description | default |
|
|
37
|
-
| -------------- | -------------------------------------------------------------------------- | --------------- |
|
|
38
|
-
| `cwd` | current working directory to start scanning | `process.cwd()` |
|
|
39
|
-
| `prefix` | prefix to add to the paths to scan | |
|
|
40
|
-
| `prependCwd` | prepend CWD to paths returned | `false` |
|
|
41
|
-
| `filter` | callback to filter files. it should return filter result. | |
|
|
42
|
-
| `ignoreExt` | array or string of extensions to ignore. ext must include `.`, ie: `".js"` | |
|
|
43
|
-
| `filterExt` | array or string of extensions to include only, apply after `ignoreExt`. | |
|
|
44
|
-
| `filterDir` | callback to filter directories. it should return filter result | |
|
|
45
|
-
| `includeDir` | include directories in result if `true` | |
|
|
46
|
-
| `grouping` | enable [grouping](#grouping) if `true` | |
|
|
47
|
-
| `maxLevel` | zero base max level of directories to recurse into | `Infinity` |
|
|
48
|
-
| `rethrowError` | set to `true` to throw errors instead of ignoring them | `false` |
|
|
49
|
-
|
|
50
|
-
`filterDir` and `filter` callback signature:
|
|
51
|
-
|
|
52
|
-
```js
|
|
53
|
-
function filter(file, path, extras) {}
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
params:
|
|
57
|
-
|
|
58
|
-
| name | description |
|
|
59
|
-
| ----------------- | ---------------------------------------------- |
|
|
60
|
-
| `file` | name of the file being considered |
|
|
61
|
-
| `path` | path to directory being processed |
|
|
62
|
-
| `extras.stat` | result of `fs.stat` on the file |
|
|
63
|
-
| `extras.dirFile` | `Path.join(path, file)` |
|
|
64
|
-
| `extras.ext` | extension of the file including `.`, ie: `.js` |
|
|
65
|
-
| `extras.noExt` | file name without the extension |
|
|
66
|
-
| `extras.fullFile` | `Path.join(cwd, path, file)` |
|
|
67
|
-
|
|
68
|
-
should return filter result:
|
|
69
|
-
|
|
70
|
-
- `false` - skip the file or directory
|
|
71
|
-
- _string_ - name of the group to add the file or directory (need to enable [grouping](#grouping))
|
|
72
|
-
- _object_ - `{ group, skip, stop }` where:
|
|
73
|
-
- `group` - name of the group to add the file or directory (need to enable [grouping](#grouping))
|
|
74
|
-
- `skip` - if `true` then skip the file or directory, else add it.
|
|
75
|
-
- `stop` - stop the scanning and return the result immediately
|
|
76
|
-
|
|
77
|
-
## grouping
|
|
78
|
-
|
|
79
|
-
If `grouping` is true, then the results will be grouped in an object.
|
|
80
|
-
|
|
81
|
-
The `filter` and `filterDir` callback can return a non-empty string as the label of a group.
|
|
82
|
-
|
|
83
|
-
Assuming `filter` returns `"group1"` and `"group2"` for some files, the return value will be an object:
|
|
84
|
-
|
|
85
|
-
```js
|
|
86
|
-
{
|
|
87
|
-
// default group, when filter callback returns non-string truthy value
|
|
88
|
-
files: [ "foo" ],
|
|
89
|
-
// other groups
|
|
90
|
-
group1: [ "file1" ],
|
|
91
|
-
group2: [ "file2" ]
|
|
92
|
-
}
|
|
35
|
+
console.log(await filterScanDir({ cwd: "test" }));
|
|
93
36
|
```
|
|
94
37
|
|
|
95
|
-
## Path Separator
|
|
96
|
-
|
|
97
|
-
By default all paths generated always use forward slash `/` as separator, even on Windows.
|
|
98
|
-
|
|
99
|
-
If you really want to force using Windows `\`, then you can pass in `options._path`:
|
|
100
|
-
|
|
101
|
-
```js
|
|
102
|
-
const path = require("path");
|
|
103
|
-
scanDir({ dir: "test", _path: path });
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
> Internally this is default to `require("path").posix`.
|
|
107
|
-
|
|
108
|
-
If you only want to keep `\` in the dir you passed in, then you can just set `_path` to `path.posix`.
|
|
109
|
-
|
|
110
38
|
# License
|
|
111
39
|
|
|
112
40
|
Licensed under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
|
41
|
+
|
|
42
|
+
[npm-version-svg]: https://badge.fury.io/js/filter-scan-dir.svg
|
|
43
|
+
[package-url]: https://npmjs.com/package/filter-scan-dir
|
|
44
|
+
[deps-svg]: https://david-dm.org/filter-scan-dir.svg
|
|
45
|
+
[deps-url]: https://david-dm.org/filter-scan-dir
|
|
46
|
+
[dev-deps-svg]: https://david-dm.org/filter-scan-dir/dev-status.svg
|
|
47
|
+
[dev-deps-url]: https://david-dm.org/filter-scan-dir#info=devDependencies
|
|
48
|
+
[license-image]: https://img.shields.io/npm/l/filter-scan-dir.svg
|
|
49
|
+
[license-url]: LICENSE
|
|
50
|
+
[build-image]: https://github.com/jchip/filter-scan-dir/actions/workflows/node.js.yml/badge.svg
|
|
51
|
+
[build-url]: https://github.com/jchip/filter-scan-dir/actions/workflows/node.js.yml
|
|
52
|
+
[coverage-image]: https://coveralls.io/repos/github/jchip/filter-scan-dir/badge.svg?branch=main
|
|
53
|
+
[coverage-url]: https://coveralls.io/github/jchip/filter-scan-dir?branch=main
|
|
54
|
+
[downloads-image]: https://img.shields.io/npm/dm/filter-scan-dir.svg
|
|
55
|
+
[downloads-url]: https://npm-stat.com/charts.html?package=filter-scan-dir
|
|
56
|
+
[npm-badge-png]: https://nodei.co/npm/filter-scan-dir.png?downloads=true&stars=true
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Dirent, Stats } from "fs";
|
|
3
|
+
/**
|
|
4
|
+
* type of the 3rd argument for the filter callback
|
|
5
|
+
*/
|
|
6
|
+
export declare type ExtrasData = {
|
|
7
|
+
/** name of the file being considered */
|
|
8
|
+
file: string;
|
|
9
|
+
/** path to the directory being processed that contains the file */
|
|
10
|
+
path: string;
|
|
11
|
+
/** result from fs.lstat or readdir */
|
|
12
|
+
stat: Dirent | Stats;
|
|
13
|
+
/** full path with cwd + path + file */
|
|
14
|
+
fullFile: string;
|
|
15
|
+
/** path to file without cwd: path + file */
|
|
16
|
+
dirFile: string;
|
|
17
|
+
/** extsion of the file, ie: `.js` */
|
|
18
|
+
ext: string;
|
|
19
|
+
/** file name without the extension */
|
|
20
|
+
noExt: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Info from the filter callback to indicate what to do next
|
|
24
|
+
*/
|
|
25
|
+
export declare type FilterInfo = {
|
|
26
|
+
/** name of the group to add the file or directory (if grouping is enabled) */
|
|
27
|
+
group?: string;
|
|
28
|
+
/** if `true` then skip the file or directory, else add it */
|
|
29
|
+
skip?: boolean;
|
|
30
|
+
/** stop the scanning and return the result immediately. */
|
|
31
|
+
stop?: boolean;
|
|
32
|
+
/** if not `undefined`, then use this as the value to add to the output */
|
|
33
|
+
formatName?: string;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* result from the filter callback
|
|
37
|
+
* - `false` or `undefined` - skip the file or directory
|
|
38
|
+
* - `true` - include the file in the default result
|
|
39
|
+
* - _string_ - name of the group to add the file or directory (if grouping is enabled)
|
|
40
|
+
* - _FilterInfo_ - see type {@link FilterInfo} for details
|
|
41
|
+
*/
|
|
42
|
+
export declare type FilterResult = boolean | string | FilterInfo;
|
|
43
|
+
/**
|
|
44
|
+
* filter callback for file or directory entry
|
|
45
|
+
* @param file - name of the file/dir being considered
|
|
46
|
+
* @param path - path to the directory containing the file. Not the full path,
|
|
47
|
+
* just the relative path from CWD. It's empty string for the files in the
|
|
48
|
+
* first level directory.
|
|
49
|
+
* @param extras - extras data
|
|
50
|
+
*/
|
|
51
|
+
export declare type FilterCallback = (file: string, path: string, extras: ExtrasData) => FilterResult;
|
|
52
|
+
/**
|
|
53
|
+
* Options for filterScanDir
|
|
54
|
+
*/
|
|
55
|
+
export declare type Options = {
|
|
56
|
+
/** current working directory to start scanning */
|
|
57
|
+
cwd?: string;
|
|
58
|
+
/**
|
|
59
|
+
* prefix to add to the paths to scan. It's applied after `cwd`.
|
|
60
|
+
* - The `prefix` will be in the resulting paths. Useful if you want
|
|
61
|
+
* to scan a dir further down from `cwd` but you don't want to prepend
|
|
62
|
+
* CWD to the resulting paths.
|
|
63
|
+
*/
|
|
64
|
+
prefix?: string;
|
|
65
|
+
/** prepend CWD to paths returned */
|
|
66
|
+
prependCwd?: boolean;
|
|
67
|
+
/** sort files from each dir */
|
|
68
|
+
sortFiles?: boolean;
|
|
69
|
+
/** include directories in result */
|
|
70
|
+
includeDir?: boolean;
|
|
71
|
+
/** enable grouping of files */
|
|
72
|
+
grouping?: boolean;
|
|
73
|
+
/** zero base max level of directories to recurse into. Default: `Infinity` */
|
|
74
|
+
maxLevel?: number;
|
|
75
|
+
/**
|
|
76
|
+
* use `fs.lstat` to get stat of each file, instead of `readir`'s `withFileTypes` option.
|
|
77
|
+
*
|
|
78
|
+
* - *Default*: `true` - for significant performance improvement, set this to `false`
|
|
79
|
+
*
|
|
80
|
+
*/
|
|
81
|
+
fullStat?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* for async version only - numer of directories to process concurrently. *Default*: `50`
|
|
84
|
+
*
|
|
85
|
+
* - Set this to `0` or `1` to disable concurrent mode
|
|
86
|
+
*
|
|
87
|
+
* NOTE: setting this to a very large number, or `Infinity`, could potentially
|
|
88
|
+
* increase performance very significantly, however, there is a dimishing return
|
|
89
|
+
* and more memory usage, so the default is already fairly good.
|
|
90
|
+
*/
|
|
91
|
+
concurrency?: number;
|
|
92
|
+
/** set to `true` to throw errors instead of ignoring them */
|
|
93
|
+
rethrowError?: boolean;
|
|
94
|
+
/** callback to filter files. */
|
|
95
|
+
filter?: FilterCallback;
|
|
96
|
+
/** callback to filter directories. */
|
|
97
|
+
filterDir?: FilterCallback;
|
|
98
|
+
/** array or string of extensions to ignore. ext must include `.`, ie: `".js"` */
|
|
99
|
+
ignoreExt?: string | string[];
|
|
100
|
+
/** array or string of extensions to include only, apply after `ignoreExt` */
|
|
101
|
+
filterExt?: string | string[];
|
|
102
|
+
/**
|
|
103
|
+
* path separator to use to join entries
|
|
104
|
+
*
|
|
105
|
+
* - *Default*: `path.posix.sep`
|
|
106
|
+
* - If you didn't specify this, then `cwd` is automatically converted to use `/`.
|
|
107
|
+
*/
|
|
108
|
+
pathSep?: string;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* The scanned result if grouping is enabled.
|
|
112
|
+
*
|
|
113
|
+
* - The default `files` group will contain all files not assigned a group
|
|
114
|
+
* - All other files with a group will be assigned to that field
|
|
115
|
+
*/
|
|
116
|
+
export declare type GroupingResult = {
|
|
117
|
+
files: string[];
|
|
118
|
+
} & Record<string, string[]>;
|
|
119
|
+
/**
|
|
120
|
+
* async version of filter scan dir
|
|
121
|
+
* @param options
|
|
122
|
+
* @returns
|
|
123
|
+
*/
|
|
124
|
+
export declare function filterScanDir(options?: string | Options): Promise<string[] | GroupingResult>;
|
|
125
|
+
/** sync version of filter scan dir */
|
|
126
|
+
export declare function filterScanDirSync(options?: string | Options): string[] | GroupingResult;
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable max-statements, complexity, comma-dangle, max-params, max-depth */
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.filterScanDirSync = exports.filterScanDir = void 0;
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const util_1 = __importDefault(require("util"));
|
|
11
|
+
function makeExtrasData(file, fullFile, path, stat, options) {
|
|
12
|
+
const dirFile = options._join2(path, file);
|
|
13
|
+
const ix = file.lastIndexOf(".");
|
|
14
|
+
if (ix > 0) {
|
|
15
|
+
return {
|
|
16
|
+
file,
|
|
17
|
+
path,
|
|
18
|
+
stat,
|
|
19
|
+
fullFile,
|
|
20
|
+
dirFile,
|
|
21
|
+
ext: file.substring(ix),
|
|
22
|
+
noExt: file.substring(0, ix),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return {
|
|
27
|
+
file,
|
|
28
|
+
path,
|
|
29
|
+
stat,
|
|
30
|
+
fullFile,
|
|
31
|
+
dirFile,
|
|
32
|
+
ext: "",
|
|
33
|
+
noExt: file,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Add a file entry to the result
|
|
39
|
+
*
|
|
40
|
+
* @param result
|
|
41
|
+
* @param options
|
|
42
|
+
* @param extras
|
|
43
|
+
*/
|
|
44
|
+
function addResult(result, options, extras) {
|
|
45
|
+
const group = (options.grouping && typeof result === "string" ? result : result && result.group) || "files";
|
|
46
|
+
if (!options.result[group]) {
|
|
47
|
+
options.result[group] = [];
|
|
48
|
+
}
|
|
49
|
+
if (result.formatName !== undefined) {
|
|
50
|
+
options.result[group].push(result.formatName);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
options.result[group].push(options.prependCwd ? extras.fullFile : extras.dirFile);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Process a directory entry
|
|
58
|
+
*
|
|
59
|
+
* @param options
|
|
60
|
+
* @param extras
|
|
61
|
+
* @returns
|
|
62
|
+
*/
|
|
63
|
+
function processDir(options, extras) {
|
|
64
|
+
const filterResult = options.filterDir
|
|
65
|
+
? options.filterDir(extras.file, extras.path, extras)
|
|
66
|
+
: true;
|
|
67
|
+
if (filterResult) {
|
|
68
|
+
if (filterResult.skip !== true && options.includeDir) {
|
|
69
|
+
addResult(filterResult, options, extras);
|
|
70
|
+
}
|
|
71
|
+
return { stop: filterResult.stop, skip: filterResult.skip };
|
|
72
|
+
}
|
|
73
|
+
return { stop: false, skip: true };
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* process a file entry
|
|
77
|
+
*
|
|
78
|
+
* @param options
|
|
79
|
+
* @param extras
|
|
80
|
+
* @returns
|
|
81
|
+
*/
|
|
82
|
+
function processFile(options, extras) {
|
|
83
|
+
if (options.ignoreExt.length > 0 && options.ignoreExt.indexOf(extras.ext) >= 0) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
if (options.filterExt.length > 0 && options.filterExt.indexOf(extras.ext) < 0) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
const filterResult = options.filter ? options.filter(extras.file, extras.path, extras) : true; // default to include
|
|
90
|
+
if (filterResult) {
|
|
91
|
+
if (filterResult.skip !== true) {
|
|
92
|
+
addResult(filterResult, options, extras);
|
|
93
|
+
}
|
|
94
|
+
return filterResult.stop;
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* get the result base on grouping enable flag
|
|
100
|
+
*
|
|
101
|
+
* @param options
|
|
102
|
+
* @returns
|
|
103
|
+
*/
|
|
104
|
+
function getResult(options) {
|
|
105
|
+
return options.grouping
|
|
106
|
+
? Object.assign({ files: [] }, options.result)
|
|
107
|
+
: options.result.files || [];
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* compare Dirent for sorting
|
|
111
|
+
*
|
|
112
|
+
* @param a
|
|
113
|
+
* @param b
|
|
114
|
+
* @returns
|
|
115
|
+
*/
|
|
116
|
+
const direntCmp = (a, b) => {
|
|
117
|
+
/* istanbul ignore next */
|
|
118
|
+
if (a.name === b.name) {
|
|
119
|
+
/* istanbul ignore next */
|
|
120
|
+
return 0;
|
|
121
|
+
/* istanbul ignore next */
|
|
122
|
+
}
|
|
123
|
+
else if (a.name > b.name) {
|
|
124
|
+
/* istanbul ignore next */
|
|
125
|
+
return 1;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
/* istanbul ignore next */
|
|
129
|
+
return -1;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* sync version of directory walk
|
|
134
|
+
*
|
|
135
|
+
* @param path
|
|
136
|
+
* @param options
|
|
137
|
+
* @param level
|
|
138
|
+
* @returns
|
|
139
|
+
*/
|
|
140
|
+
function walkSync(path, options, level = 0) {
|
|
141
|
+
try {
|
|
142
|
+
const dir = options._join2(options.dir, path);
|
|
143
|
+
let files = fs_1.default.readdirSync(dir, options.readdirOpts);
|
|
144
|
+
if (options.sortFiles) {
|
|
145
|
+
if (options.fullStat) {
|
|
146
|
+
files = files.sort();
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
files = files.sort(direntCmp);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const dirs = [];
|
|
153
|
+
let stop = false;
|
|
154
|
+
// process files first
|
|
155
|
+
for (let ix = 0; !stop && ix < files.length; ix++) {
|
|
156
|
+
const file = files[ix];
|
|
157
|
+
let extras;
|
|
158
|
+
if (options.fullStat) {
|
|
159
|
+
const fullFile = options._join2(dir, file);
|
|
160
|
+
const stat = fs_1.default.lstatSync(fullFile);
|
|
161
|
+
extras = makeExtrasData(file, fullFile, path, stat, options);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
const fullFile = options._join2(dir, file.name);
|
|
165
|
+
extras = makeExtrasData(file.name, fullFile, path, file, options);
|
|
166
|
+
}
|
|
167
|
+
if (extras.stat.isDirectory()) {
|
|
168
|
+
dirs.push(extras);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
stop = processFile(options, extras);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// now process dirs
|
|
175
|
+
if (!stop && dirs.length > 0) {
|
|
176
|
+
for (let ix = 0; ix < dirs.length; ix++) {
|
|
177
|
+
const extras = dirs[ix];
|
|
178
|
+
const flags = processDir(options, extras);
|
|
179
|
+
if (flags.stop) {
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
if (!flags.skip && level < options.maxLevel) {
|
|
183
|
+
walkSync(extras.dirFile, options, level + 1);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
if (options.rethrowError) {
|
|
190
|
+
throw err;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return getResult(options);
|
|
194
|
+
}
|
|
195
|
+
const asyncReaddir = util_1.default.promisify(fs_1.default.readdir);
|
|
196
|
+
const asyncLStat = util_1.default.promisify(fs_1.default.lstat);
|
|
197
|
+
/**
|
|
198
|
+
* async version of dir walk
|
|
199
|
+
*
|
|
200
|
+
* @param path
|
|
201
|
+
* @param options
|
|
202
|
+
* @param level
|
|
203
|
+
* @returns
|
|
204
|
+
*/
|
|
205
|
+
async function walk(path, options, level = 0) {
|
|
206
|
+
try {
|
|
207
|
+
const dir = options._join2(options.dir, path);
|
|
208
|
+
let files = await asyncReaddir(dir, options.readdirOpts);
|
|
209
|
+
if (options.sortFiles) {
|
|
210
|
+
if (options.fullStat) {
|
|
211
|
+
files = files.sort();
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
files = files.sort(direntCmp);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const dirs = [];
|
|
218
|
+
let stop = false;
|
|
219
|
+
// process files first
|
|
220
|
+
for (let ix = 0; !stop && ix < files.length; ix++) {
|
|
221
|
+
const file = files[ix];
|
|
222
|
+
let extras;
|
|
223
|
+
if (options.fullStat) {
|
|
224
|
+
const fullFile = options._join2(dir, file);
|
|
225
|
+
const stat = await asyncLStat(fullFile);
|
|
226
|
+
extras = makeExtrasData(file, fullFile, path, stat, options);
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
const fullFile = options._join2(dir, file.name);
|
|
230
|
+
extras = makeExtrasData(file.name, fullFile, path, file, options);
|
|
231
|
+
}
|
|
232
|
+
if (extras.stat.isDirectory()) {
|
|
233
|
+
dirs.push(extras);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
stop = processFile(options, extras);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
// now process dirs
|
|
240
|
+
if (!stop && dirs.length > 0) {
|
|
241
|
+
let promises = [];
|
|
242
|
+
for (let ix = 0; ix < dirs.length; ix++) {
|
|
243
|
+
const extras = dirs[ix];
|
|
244
|
+
const flags = processDir(options, extras);
|
|
245
|
+
if (flags.stop) {
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
if (!flags.skip && level < options.maxLevel) {
|
|
249
|
+
const walkP = walk(extras.dirFile, options, level + 1);
|
|
250
|
+
if (options.concurrency > 1) {
|
|
251
|
+
if (options._concurrentCount < options.concurrency) {
|
|
252
|
+
options._concurrentCount++;
|
|
253
|
+
promises.push(walkP);
|
|
254
|
+
}
|
|
255
|
+
else if (promises.length) {
|
|
256
|
+
await Promise.all(promises);
|
|
257
|
+
options._concurrentCount -= promises.length;
|
|
258
|
+
promises = [walkP];
|
|
259
|
+
options._concurrentCount++;
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
await walkP;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
await walkP;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (promises.length) {
|
|
271
|
+
await Promise.all(promises);
|
|
272
|
+
options._concurrentCount -= promises.length;
|
|
273
|
+
promises = [];
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
catch (err) {
|
|
278
|
+
if (options.rethrowError) {
|
|
279
|
+
throw err;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return getResult(options);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* make a copy of the user's options with proper defaults
|
|
286
|
+
*
|
|
287
|
+
* @param opts
|
|
288
|
+
* @returns
|
|
289
|
+
*/
|
|
290
|
+
function makeOptions(opts) {
|
|
291
|
+
const options = typeof opts === "string" ? { cwd: opts } : opts;
|
|
292
|
+
const sep = options.pathSep || path_1.default.posix.sep;
|
|
293
|
+
let cwd = options.cwd || options.dir || process.cwd();
|
|
294
|
+
if (!options.hasOwnProperty("pathSep") && cwd.includes("\\")) {
|
|
295
|
+
cwd = cwd.replace(/\\/g, "/");
|
|
296
|
+
}
|
|
297
|
+
const cleanExt = (ext) => {
|
|
298
|
+
if (!ext) {
|
|
299
|
+
return ext;
|
|
300
|
+
}
|
|
301
|
+
if (ext.startsWith("*.")) {
|
|
302
|
+
return ext.substring(1);
|
|
303
|
+
}
|
|
304
|
+
if (!ext.startsWith(".")) {
|
|
305
|
+
return `.${ext}`;
|
|
306
|
+
}
|
|
307
|
+
return ext;
|
|
308
|
+
};
|
|
309
|
+
// `includeRoot` was renamed to `prependCwd`, this avoid breaking code still using that
|
|
310
|
+
const prependCwd = (options.hasOwnProperty("includeRoot") ? options.includeRoot : options.prependCwd) ||
|
|
311
|
+
false;
|
|
312
|
+
// a simple and faster version of path.join that handles just 2
|
|
313
|
+
// arguments using posix separator
|
|
314
|
+
const _join2 = (a, b) => (a && b ? a + sep + b : a ? a : b); // eslint-disable-line
|
|
315
|
+
const opts2 = Object.assign({
|
|
316
|
+
_join2,
|
|
317
|
+
maxLevel: Infinity,
|
|
318
|
+
prefix: "",
|
|
319
|
+
prependCwd,
|
|
320
|
+
fullStat: true,
|
|
321
|
+
concurrency: 50,
|
|
322
|
+
readdirOpts: undefined,
|
|
323
|
+
}, options, {
|
|
324
|
+
dir: cwd,
|
|
325
|
+
result: {},
|
|
326
|
+
ignoreExt: []
|
|
327
|
+
.concat(options.ignoreExt)
|
|
328
|
+
.map(cleanExt)
|
|
329
|
+
.filter((x) => x),
|
|
330
|
+
filterExt: []
|
|
331
|
+
.concat(options.filterExt)
|
|
332
|
+
.map(cleanExt)
|
|
333
|
+
.filter((x) => x),
|
|
334
|
+
_concurrentCount: 0,
|
|
335
|
+
});
|
|
336
|
+
if (!opts2.fullStat) {
|
|
337
|
+
opts2.readdirOpts = { withFileTypes: true };
|
|
338
|
+
}
|
|
339
|
+
return opts2;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* async version of filter scan dir
|
|
343
|
+
* @param options
|
|
344
|
+
* @returns
|
|
345
|
+
*/
|
|
346
|
+
function filterScanDir(options = {}) {
|
|
347
|
+
const options2 = makeOptions(options);
|
|
348
|
+
return walk(options2.prefix, options2);
|
|
349
|
+
}
|
|
350
|
+
exports.filterScanDir = filterScanDir;
|
|
351
|
+
/** sync version of filter scan dir */
|
|
352
|
+
function filterScanDirSync(options = {}) {
|
|
353
|
+
const options2 = makeOptions(options);
|
|
354
|
+
return walkSync(options2.prefix, options2);
|
|
355
|
+
}
|
|
356
|
+
exports.filterScanDirSync = filterScanDirSync;
|
|
357
|
+
//# sourceMappingURL=filter-scan-dir.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-scan-dir.js","sourceRoot":"","sources":["../src/filter-scan-dir.ts"],"names":[],"mappings":";AAAA,oFAAoF;;;;;;AAEpF,4CAAuC;AACvC,gDAAwB;AACxB,gDAAwB;AA2HxB,SAAS,cAAc,CACrB,IAAY,EACZ,QAAgB,EAChB,IAAY,EACZ,IAAoB,EACpB,OAAqB;IAErB,MAAM,OAAO,GAAW,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACnD,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAEjC,IAAI,EAAE,GAAG,CAAC,EAAE;QACV,OAAO;YACL,IAAI;YACJ,IAAI;YACJ,IAAI;YACJ,QAAQ;YACR,OAAO;YACP,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YACvB,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC;SAC7B,CAAC;KACH;SAAM;QACL,OAAO;YACL,IAAI;YACJ,IAAI;YACJ,IAAI;YACJ,QAAQ;YACR,OAAO;YACP,GAAG,EAAE,EAAE;YACP,KAAK,EAAE,IAAI;SACZ,CAAC;KACH;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAS,SAAS,CAAC,MAAM,EAAE,OAAqB,EAAE,MAAkB;IAClE,MAAM,KAAK,GACT,CAAC,OAAO,CAAC,QAAQ,IAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC;IAEhG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;QAC1B,OAAO,CAAC,MAAM,CA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W,CAAC,OAAO,CAAC,CAAC;IACtC,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AACzC,CAAC;AAHD,sCAGC;AAED,sCAAsC;AACtC,SAAgB,iBAAiB,CAAC,UAA4B,EAAE;IAC9D,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IACtC,OAAO,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAC7C,CAAC;AAHD,8CAGC"}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
CHANGED
|
@@ -1,205 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
let dirFile = options._path.join(extras.path, file);
|
|
11
|
-
|
|
12
|
-
const ix = file.lastIndexOf(".");
|
|
13
|
-
|
|
14
|
-
if (ix > 0) {
|
|
15
|
-
extras.ext = file.substr(ix);
|
|
16
|
-
extras.noExt = file.substring(0, ix);
|
|
17
|
-
} else {
|
|
18
|
-
extras.ext = "";
|
|
19
|
-
extras.noExt = file;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
extras.dirFile = dirFile;
|
|
23
|
-
|
|
24
|
-
const add = result => {
|
|
25
|
-
const group =
|
|
26
|
-
(options.grouping && typeof result === "string"
|
|
27
|
-
? result
|
|
28
|
-
: result && result.group) || "files";
|
|
29
|
-
|
|
30
|
-
if (!options.result[group]) {
|
|
31
|
-
options.result[group] = [];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
options.result[group].push(options.prependCwd ? extras.fullFile : dirFile);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
let filterResult;
|
|
38
|
-
|
|
39
|
-
if (extras.stat.isDirectory()) {
|
|
40
|
-
if (options.filterDir) {
|
|
41
|
-
filterResult = options.filterDir(file, extras.path, extras);
|
|
42
|
-
} else {
|
|
43
|
-
filterResult = true;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (filterResult && filterResult.skip !== true) {
|
|
47
|
-
if (options.includeDir) {
|
|
48
|
-
add(filterResult);
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
dirFile = undefined;
|
|
52
|
-
}
|
|
53
|
-
} else {
|
|
54
|
-
if (
|
|
55
|
-
options.ignoreExt.length > 0 &&
|
|
56
|
-
options.ignoreExt.indexOf(extras.ext) >= 0
|
|
57
|
-
) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
if (
|
|
61
|
-
options.filterExt.length > 0 &&
|
|
62
|
-
options.filterExt.indexOf(extras.ext) < 0
|
|
63
|
-
) {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (options.filter) {
|
|
68
|
-
filterResult = options.filter(file, extras.path, extras);
|
|
69
|
-
} else {
|
|
70
|
-
filterResult = true;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (filterResult && filterResult.skip !== true) {
|
|
74
|
-
add(filterResult);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
dirFile = undefined;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return { dirFile, stop: filterResult && filterResult.stop };
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function getResult(options) {
|
|
84
|
-
return options.grouping
|
|
85
|
-
? Object.assign({ files: [] }, options.result)
|
|
86
|
-
: options.result.files || [];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function walkSync(path, options, level = 0) {
|
|
90
|
-
try {
|
|
91
|
-
const dir = options._path.join(options.dir, path);
|
|
92
|
-
const files = Fs.readdirSync(dir);
|
|
93
|
-
|
|
94
|
-
for (const file of files) {
|
|
95
|
-
const fullFile = options._path.join(dir, file);
|
|
96
|
-
const stat = Fs.statSync(fullFile);
|
|
97
|
-
const result = processFile(file, options, { path, stat, fullFile });
|
|
98
|
-
|
|
99
|
-
if (result) {
|
|
100
|
-
if (result.stop) {
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (result.dirFile && level < options.maxLevel) {
|
|
105
|
-
walkSync(result.dirFile, options, level + 1);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
} catch (err) {
|
|
110
|
-
if (options.rethrowError) {
|
|
111
|
-
throw err;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return getResult(options);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const asyncReaddir = Util.promisify(Fs.readdir);
|
|
119
|
-
const asyncStat = Util.promisify(Fs.stat);
|
|
120
|
-
|
|
121
|
-
async function walk(path, options, level = 0) {
|
|
122
|
-
try {
|
|
123
|
-
const dir = options._path.join(options.dir, path);
|
|
124
|
-
const files = await asyncReaddir(dir);
|
|
125
|
-
|
|
126
|
-
for (const file of files) {
|
|
127
|
-
const fullFile = options._path.join(dir, file);
|
|
128
|
-
const stat = await asyncStat(fullFile);
|
|
129
|
-
const result = processFile(file, options, { path, stat, fullFile });
|
|
130
|
-
|
|
131
|
-
if (result) {
|
|
132
|
-
if (result.stop) {
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (result.dirFile && level < options.maxLevel) {
|
|
137
|
-
await walk(result.dirFile, options, level + 1);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
} catch (err) {
|
|
142
|
-
if (options.rethrowError) {
|
|
143
|
-
throw err;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return getResult(options);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function makeOptions(options) {
|
|
151
|
-
let cwd =
|
|
152
|
-
(typeof options === "string" ? options : options.cwd || options.dir) ||
|
|
153
|
-
process.cwd();
|
|
154
|
-
|
|
155
|
-
if (!options._path && cwd.indexOf("\\") >= 0) {
|
|
156
|
-
cwd = cwd.replace(/\\/g, "/");
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const cleanExt = ext => {
|
|
160
|
-
if (!ext) {
|
|
161
|
-
return ext;
|
|
162
|
-
}
|
|
163
|
-
if (ext.startsWith("*.")) {
|
|
164
|
-
return ext.substring(1);
|
|
165
|
-
}
|
|
166
|
-
if (!ext.startsWith(".")) {
|
|
167
|
-
return `.${ext}`;
|
|
168
|
-
}
|
|
169
|
-
return ext;
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
const prependCwd =
|
|
173
|
-
(options.hasOwnProperty("includeRoot")
|
|
174
|
-
? options.includeRoot
|
|
175
|
-
: options.prependCwd) || false;
|
|
176
|
-
|
|
177
|
-
return Object.assign(
|
|
178
|
-
{ _path: Path.posix, maxLevel: Infinity, prefix: "", prependCwd },
|
|
179
|
-
options,
|
|
180
|
-
{
|
|
181
|
-
dir: cwd,
|
|
182
|
-
result: {},
|
|
183
|
-
ignoreExt: []
|
|
184
|
-
.concat(options.ignoreExt)
|
|
185
|
-
.map(cleanExt)
|
|
186
|
-
.filter(x => x),
|
|
187
|
-
filterExt: []
|
|
188
|
-
.concat(options.filterExt)
|
|
189
|
-
.map(cleanExt)
|
|
190
|
-
.filter(x => x)
|
|
191
|
-
}
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function filterScanDir(options) {
|
|
196
|
-
const options2 = makeOptions(options);
|
|
197
|
-
return walk(options2.prefix, options2);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
filterScanDir.sync = function filterScanDirSync(options) {
|
|
201
|
-
const options2 = makeOptions(options);
|
|
202
|
-
return walkSync(options2.prefix, options2);
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
module.exports = filterScanDir;
|
|
1
|
+
const fsd = require("../dist/filter-scan-dir");
|
|
2
|
+
|
|
3
|
+
const asyncApi = (options) => fsd.filterScanDir(options);
|
|
4
|
+
Object.defineProperties(asyncApi, {
|
|
5
|
+
sync: { value: fsd.filterScanDirSync },
|
|
6
|
+
filterScanDir: { value: fsd.filterScanDir },
|
|
7
|
+
filterScanDirSync: { value: fsd.filterScanDirSync },
|
|
8
|
+
});
|
|
9
|
+
module.exports = asyncApi;
|
package/package.json
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "filter-scan-dir",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Recursively scan and filter directory for a flat array of files",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
8
|
+
"build": "rm -rf dist && tsc",
|
|
9
|
+
"test": "xrun -x build xarc/test-only",
|
|
10
|
+
"lint": "clap lint",
|
|
11
|
+
"coveralls": "cat coverage/lcov.info | coveralls",
|
|
12
|
+
"coverage": "xrun -x build xarc/test-cov",
|
|
13
|
+
"ci:check": "xrun --serial build check coveralls",
|
|
14
|
+
"prepack": "publish-util-prepack",
|
|
15
|
+
"postpack": "publish-util-postpack",
|
|
16
|
+
"prepublishOnly": "xrun --serial [[build, docs], xarc/check]",
|
|
17
|
+
"docs": "xrun xarc/docs && touch docs/.nojekyll"
|
|
10
18
|
},
|
|
11
19
|
"repository": {
|
|
12
20
|
"type": "git",
|
|
@@ -16,6 +24,7 @@
|
|
|
16
24
|
"registry": "https://registry.npmjs.com/"
|
|
17
25
|
},
|
|
18
26
|
"files": [
|
|
27
|
+
"dist",
|
|
19
28
|
"lib"
|
|
20
29
|
],
|
|
21
30
|
"keywords": [
|
|
@@ -27,7 +36,9 @@
|
|
|
27
36
|
"dir",
|
|
28
37
|
"directory",
|
|
29
38
|
"readdir",
|
|
30
|
-
"fs"
|
|
39
|
+
"fs",
|
|
40
|
+
"fast",
|
|
41
|
+
"glob"
|
|
31
42
|
],
|
|
32
43
|
"author": "Joel Chen <joel123@gmail.com>",
|
|
33
44
|
"license": "Apache-2.0",
|