1 | const fileTree = require('node-file-tree');
|
2 | const path = require('path');
|
3 | const { join } = path;
|
4 | const cwd = process.cwd();
|
5 |
|
6 | module.exports = function getStreamPathList(input, suffix = 'js', ignoreDir = '__test__') {
|
7 | let dirList = [];
|
8 | const inputPath = join(cwd, input);
|
9 | const files = fileTree(inputPath, true);
|
10 | var ignoreReg = new RegExp(ignoreDir);
|
11 |
|
12 | function getDirPath(pathList) {
|
13 | pathList.forEach(path => {
|
14 | if (path.isDir && !ignoreReg.test(path.fullPath)) {
|
15 | dirList.push(path.fullPath);
|
16 | }
|
17 |
|
18 | if (path.files) {
|
19 | getDirPath(path.files);
|
20 | }
|
21 | });
|
22 | }
|
23 |
|
24 | function getStreamPath(input, num, suffix = 'js', ignoreDir = '__test__') {
|
25 | const list = [];
|
26 | let str = ''
|
27 | let testStr = `${ignoreDir}/`;
|
28 |
|
29 | for (let i = 0; i < num; i++) {
|
30 | list.push(`${input}/${str}*.${suffix}`);
|
31 | list.push(`!${input}/${testStr}*.${suffix}`);
|
32 | str += '*/'
|
33 | testStr = str + `${ignoreDir}/`;
|
34 | }
|
35 |
|
36 | return list;
|
37 | }
|
38 |
|
39 | getDirPath(files);
|
40 | dirList = dirList.map(dir => dir.split(inputPath)[1]);
|
41 |
|
42 | let maxDepth = 1;
|
43 | dirList.forEach(dir => {
|
44 | const temp = dir.split('/').filter(Boolean);
|
45 | maxDepth = temp.length > maxDepth ? temp.length : maxDepth;
|
46 | });
|
47 |
|
48 | return getStreamPath(input, maxDepth, suffix, ignoreDir);
|
49 |
|
50 | } |
\ | No newline at end of file |