@ainc/fs 0.1.15 → 0.1.17

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.
Files changed (255) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +18 -42
  3. package/dist/findUp.d.ts +6 -0
  4. package/dist/findUp.js +36 -0
  5. package/dist/index.d.ts +7 -38
  6. package/dist/index.js +21 -80
  7. package/dist/jsonc.d.ts +4 -14
  8. package/dist/jsonc.js +19 -27
  9. package/dist/lookup.d.ts +18 -0
  10. package/dist/lookup.js +64 -0
  11. package/dist/readFile.d.ts +1 -25
  12. package/dist/readFile.js +9 -12
  13. package/dist/relative.d.ts +12 -1
  14. package/dist/relative.js +47 -16
  15. package/dist/resolveFile.d.ts +6 -0
  16. package/dist/resolveFile.js +41 -0
  17. package/dist/{extname.d.ts → rm.d.ts} +2 -3
  18. package/dist/rm.js +35 -0
  19. package/dist/stat.d.ts +1 -16
  20. package/dist/stat.js +4 -11
  21. package/dist/{helpers → utils}/stripComments.d.ts +1 -2
  22. package/dist/utils/stripComments.js +120 -0
  23. package/package.json +33 -30
  24. package/bin/clean.js +0 -45
  25. package/bin/cli.js +0 -42
  26. package/bin/git.js +0 -40
  27. package/bin/run.js +0 -41
  28. package/dist/basename.d.ts +0 -7
  29. package/dist/basename.d.ts.map +0 -1
  30. package/dist/basename.js +0 -17
  31. package/dist/basename.js.map +0 -1
  32. package/dist/copy.d.ts +0 -41
  33. package/dist/copy.d.ts.map +0 -1
  34. package/dist/copy.js +0 -90
  35. package/dist/copy.js.map +0 -1
  36. package/dist/cpdir.d.ts +0 -20
  37. package/dist/cpdir.d.ts.map +0 -1
  38. package/dist/cpdir.js +0 -29
  39. package/dist/cpdir.js.map +0 -1
  40. package/dist/cwd.d.ts +0 -7
  41. package/dist/cwd.d.ts.map +0 -1
  42. package/dist/cwd.js +0 -17
  43. package/dist/cwd.js.map +0 -1
  44. package/dist/dirname.d.ts +0 -7
  45. package/dist/dirname.d.ts.map +0 -1
  46. package/dist/dirname.js +0 -31
  47. package/dist/dirname.js.map +0 -1
  48. package/dist/extname.d.ts.map +0 -1
  49. package/dist/extname.js +0 -17
  50. package/dist/extname.js.map +0 -1
  51. package/dist/filename.d.ts +0 -7
  52. package/dist/filename.d.ts.map +0 -1
  53. package/dist/filename.js +0 -25
  54. package/dist/filename.js.map +0 -1
  55. package/dist/find.d.ts +0 -27
  56. package/dist/find.d.ts.map +0 -1
  57. package/dist/find.js +0 -73
  58. package/dist/find.js.map +0 -1
  59. package/dist/findFile.d.ts +0 -21
  60. package/dist/findFile.d.ts.map +0 -1
  61. package/dist/findFile.js +0 -40
  62. package/dist/findFile.js.map +0 -1
  63. package/dist/finddir.d.ts +0 -21
  64. package/dist/finddir.d.ts.map +0 -1
  65. package/dist/finddir.js +0 -40
  66. package/dist/finddir.js.map +0 -1
  67. package/dist/helpers/FileResolver.d.ts +0 -54
  68. package/dist/helpers/FileResolver.d.ts.map +0 -1
  69. package/dist/helpers/FileResolver.js +0 -184
  70. package/dist/helpers/FileResolver.js.map +0 -1
  71. package/dist/helpers/compose.d.ts +0 -14
  72. package/dist/helpers/compose.d.ts.map +0 -1
  73. package/dist/helpers/compose.js +0 -38
  74. package/dist/helpers/compose.js.map +0 -1
  75. package/dist/helpers/each.d.ts +0 -7
  76. package/dist/helpers/each.d.ts.map +0 -1
  77. package/dist/helpers/each.js +0 -21
  78. package/dist/helpers/each.js.map +0 -1
  79. package/dist/helpers/match.d.ts +0 -7
  80. package/dist/helpers/match.d.ts.map +0 -1
  81. package/dist/helpers/match.js +0 -30
  82. package/dist/helpers/match.js.map +0 -1
  83. package/dist/helpers/normalizePath.d.ts +0 -23
  84. package/dist/helpers/normalizePath.d.ts.map +0 -1
  85. package/dist/helpers/normalizePath.js +0 -37
  86. package/dist/helpers/normalizePath.js.map +0 -1
  87. package/dist/helpers/safeCall.d.ts +0 -7
  88. package/dist/helpers/safeCall.d.ts.map +0 -1
  89. package/dist/helpers/safeCall.js +0 -24
  90. package/dist/helpers/safeCall.js.map +0 -1
  91. package/dist/helpers/split.d.ts +0 -7
  92. package/dist/helpers/split.d.ts.map +0 -1
  93. package/dist/helpers/split.js +0 -25
  94. package/dist/helpers/split.js.map +0 -1
  95. package/dist/helpers/stripBOM.d.ts +0 -7
  96. package/dist/helpers/stripBOM.d.ts.map +0 -1
  97. package/dist/helpers/stripBOM.js +0 -19
  98. package/dist/helpers/stripBOM.js.map +0 -1
  99. package/dist/helpers/stripComments.d.ts.map +0 -1
  100. package/dist/helpers/stripComments.js +0 -145
  101. package/dist/helpers/stripComments.js.map +0 -1
  102. package/dist/homedir.d.ts +0 -7
  103. package/dist/homedir.d.ts.map +0 -1
  104. package/dist/homedir.js +0 -32
  105. package/dist/homedir.js.map +0 -1
  106. package/dist/includePaths.d.ts +0 -7
  107. package/dist/includePaths.d.ts.map +0 -1
  108. package/dist/includePaths.js +0 -54
  109. package/dist/includePaths.js.map +0 -1
  110. package/dist/index.d.ts.map +0 -1
  111. package/dist/index.js.map +0 -1
  112. package/dist/indir.d.ts +0 -14
  113. package/dist/indir.d.ts.map +0 -1
  114. package/dist/indir.js +0 -27
  115. package/dist/indir.js.map +0 -1
  116. package/dist/isAbsolutePath.d.ts +0 -7
  117. package/dist/isAbsolutePath.d.ts.map +0 -1
  118. package/dist/isAbsolutePath.js +0 -25
  119. package/dist/isAbsolutePath.js.map +0 -1
  120. package/dist/isDirectory.d.ts +0 -13
  121. package/dist/isDirectory.d.ts.map +0 -1
  122. package/dist/isDirectory.js +0 -27
  123. package/dist/isDirectory.js.map +0 -1
  124. package/dist/isRelativePath.d.ts +0 -7
  125. package/dist/isRelativePath.d.ts.map +0 -1
  126. package/dist/isRelativePath.js +0 -45
  127. package/dist/isRelativePath.js.map +0 -1
  128. package/dist/json.d.ts +0 -22
  129. package/dist/json.d.ts.map +0 -1
  130. package/dist/json.js +0 -35
  131. package/dist/json.js.map +0 -1
  132. package/dist/jsonc.d.ts.map +0 -1
  133. package/dist/jsonc.js.map +0 -1
  134. package/dist/lstat.d.ts +0 -23
  135. package/dist/lstat.d.ts.map +0 -1
  136. package/dist/lstat.js +0 -31
  137. package/dist/lstat.js.map +0 -1
  138. package/dist/mapdir.d.ts +0 -23
  139. package/dist/mapdir.d.ts.map +0 -1
  140. package/dist/mapdir.js +0 -43
  141. package/dist/mapdir.js.map +0 -1
  142. package/dist/mkdir.d.ts +0 -7
  143. package/dist/mkdir.d.ts.map +0 -1
  144. package/dist/mkdir.js +0 -38
  145. package/dist/mkdir.js.map +0 -1
  146. package/dist/parseJSON.d.ts +0 -16
  147. package/dist/parseJSON.d.ts.map +0 -1
  148. package/dist/parseJSON.js +0 -29
  149. package/dist/parseJSON.js.map +0 -1
  150. package/dist/readFile.d.ts.map +0 -1
  151. package/dist/readFile.js.map +0 -1
  152. package/dist/readStream.d.ts +0 -37
  153. package/dist/readStream.d.ts.map +0 -1
  154. package/dist/readStream.js +0 -20
  155. package/dist/readStream.js.map +0 -1
  156. package/dist/readdir.d.ts +0 -17
  157. package/dist/readdir.d.ts.map +0 -1
  158. package/dist/readdir.js +0 -35
  159. package/dist/readdir.js.map +0 -1
  160. package/dist/readline.d.ts +0 -17
  161. package/dist/readline.d.ts.map +0 -1
  162. package/dist/readline.js +0 -25
  163. package/dist/readline.js.map +0 -1
  164. package/dist/realpath.d.ts +0 -13
  165. package/dist/realpath.d.ts.map +0 -1
  166. package/dist/realpath.js +0 -33
  167. package/dist/realpath.js.map +0 -1
  168. package/dist/relative.d.ts.map +0 -1
  169. package/dist/relative.js.map +0 -1
  170. package/dist/resolve.d.ts +0 -27
  171. package/dist/resolve.d.ts.map +0 -1
  172. package/dist/resolve.js +0 -54
  173. package/dist/resolve.js.map +0 -1
  174. package/dist/resolvePath.d.ts +0 -27
  175. package/dist/resolvePath.d.ts.map +0 -1
  176. package/dist/resolvePath.js +0 -178
  177. package/dist/resolvePath.js.map +0 -1
  178. package/dist/rmdir.d.ts +0 -7
  179. package/dist/rmdir.d.ts.map +0 -1
  180. package/dist/rmdir.js +0 -41
  181. package/dist/rmdir.js.map +0 -1
  182. package/dist/stat.d.ts.map +0 -1
  183. package/dist/stat.js.map +0 -1
  184. package/dist/supdir.d.ts +0 -22
  185. package/dist/supdir.d.ts.map +0 -1
  186. package/dist/supdir.js +0 -63
  187. package/dist/supdir.js.map +0 -1
  188. package/dist/symlink.d.ts +0 -23
  189. package/dist/symlink.d.ts.map +0 -1
  190. package/dist/symlink.js +0 -40
  191. package/dist/symlink.js.map +0 -1
  192. package/dist/unlink.d.ts +0 -7
  193. package/dist/unlink.d.ts.map +0 -1
  194. package/dist/unlink.js +0 -29
  195. package/dist/unlink.js.map +0 -1
  196. package/dist/usedir.d.ts +0 -7
  197. package/dist/usedir.d.ts.map +0 -1
  198. package/dist/usedir.js +0 -25
  199. package/dist/usedir.js.map +0 -1
  200. package/dist/writeFile.d.ts +0 -34
  201. package/dist/writeFile.d.ts.map +0 -1
  202. package/dist/writeFile.js +0 -50
  203. package/dist/writeFile.js.map +0 -1
  204. package/dist/writeStream.d.ts +0 -36
  205. package/dist/writeStream.d.ts.map +0 -1
  206. package/dist/writeStream.js +0 -20
  207. package/dist/writeStream.js.map +0 -1
  208. package/src/basename.ts +0 -15
  209. package/src/copy.ts +0 -141
  210. package/src/cpdir.ts +0 -47
  211. package/src/cwd.ts +0 -15
  212. package/src/dirname.ts +0 -34
  213. package/src/extname.ts +0 -15
  214. package/src/filename.ts +0 -25
  215. package/src/find.ts +0 -106
  216. package/src/findFile.ts +0 -61
  217. package/src/finddir.ts +0 -61
  218. package/src/helpers/FileResolver.ts +0 -282
  219. package/src/helpers/compose.ts +0 -49
  220. package/src/helpers/each.ts +0 -19
  221. package/src/helpers/match.ts +0 -31
  222. package/src/helpers/normalizePath.ts +0 -51
  223. package/src/helpers/safeCall.ts +0 -21
  224. package/src/helpers/split.ts +0 -25
  225. package/src/helpers/stripBOM.ts +0 -17
  226. package/src/helpers/stripComments.ts +0 -167
  227. package/src/homedir.ts +0 -34
  228. package/src/includePaths.ts +0 -62
  229. package/src/index.ts +0 -52
  230. package/src/indir.ts +0 -45
  231. package/src/isAbsolutePath.ts +0 -25
  232. package/src/isDirectory.ts +0 -28
  233. package/src/isRelativePath.ts +0 -52
  234. package/src/json.ts +0 -62
  235. package/src/jsonc.ts +0 -70
  236. package/src/lstat.ts +0 -40
  237. package/src/mapdir.ts +0 -59
  238. package/src/mkdir.ts +0 -43
  239. package/src/parseJSON.ts +0 -40
  240. package/src/readFile.ts +0 -64
  241. package/src/readStream.ts +0 -53
  242. package/src/readdir.ts +0 -51
  243. package/src/readline.ts +0 -42
  244. package/src/realpath.ts +0 -35
  245. package/src/relative.ts +0 -43
  246. package/src/resolve.ts +0 -83
  247. package/src/resolvePath.ts +0 -234
  248. package/src/rmdir.ts +0 -44
  249. package/src/stat.ts +0 -40
  250. package/src/supdir.ts +0 -79
  251. package/src/symlink.ts +0 -67
  252. package/src/unlink.ts +0 -31
  253. package/src/usedir.ts +0 -25
  254. package/src/writeFile.ts +0 -86
  255. package/src/writeStream.ts +0 -52
@@ -1,20 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2021-05-22 11:32:52
5
- *****************************************
6
- */
7
- 'use strict';
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.writeStream = void 0;
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- const fs = require("fs");
16
- function writeStream(path, options) {
17
- return fs.createWriteStream(path, options);
18
- }
19
- exports.writeStream = writeStream;
20
- //# sourceMappingURL=writeStream.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"writeStream.js","sourceRoot":"","sources":["../src/writeStream.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,YAAY,CAAC;;;AAGb;;;;GAIG;AACH,yBAAyB;AA2BzB,SAAS,WAAW,CAAC,IAAY,EAAE,OAAkC;IACjE,OAAO,EAAE,CAAC,iBAAiB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC/C,CAAC;AAQQ,kCAAW"}
package/src/basename.ts DELETED
@@ -1,15 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2020-06-16 13:20:41
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 获取文件名
13
- *****************************************
14
- */
15
- export { basename } from 'path';
package/src/copy.ts DELETED
@@ -1,141 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2020-01-28 23:24:23
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- import * as fs from 'fs';
16
- import * as path from 'path';
17
- import { stat } from './stat';
18
- import { rmdir } from './rmdir';
19
- import { mkdir } from './mkdir';
20
-
21
-
22
- /**
23
- *****************************************
24
- * 源码转换函数
25
- *****************************************
26
- */
27
- interface Transform {
28
- (source: string, file: string, stats: fs.Stats): string;
29
- }
30
-
31
-
32
- /**
33
- *****************************************
34
- * 选项
35
- *****************************************
36
- */
37
- interface Options {
38
- mode?: 'force' | 'weak' | 'merge';
39
- ignore?: string[];
40
- transform?: Transform;
41
- }
42
-
43
-
44
- /**
45
- *****************************************
46
- * 执行复制
47
- *****************************************
48
- */
49
- function doCopy(src: string, dest: string, options: Required<Options>): void {
50
- const { mode, ignore, transform } = options;
51
- const srcStats = stat(src);
52
-
53
- // 存在目录
54
- if (srcStats) {
55
- let destStats = stat(dest),
56
- isDirectory = srcStats.isDirectory();
57
-
58
- // 存在目标文件
59
- if (destStats) {
60
- if (mode === 'force') {
61
-
62
- // 移除目标文件
63
- rmdir(dest);
64
-
65
- // 清空状态
66
- destStats = null;
67
- } else if (mode === 'merge' && isDirectory) {
68
- if (!destStats.isDirectory()) {
69
- throw new Error('can not merge a directory to file!');
70
- }
71
- } else {
72
- return;
73
- }
74
- }
75
-
76
- // 复制目录
77
- if (isDirectory) {
78
-
79
- // 创建目标目录
80
- mkdir(dest);
81
-
82
- // 复制子文件
83
- return fs.readdirSync(src).forEach(name => {
84
- if (!ignore.includes(name)) {
85
- doCopy(path.join(src, name), path.join(dest, name), options);
86
- }
87
- });
88
- }
89
-
90
- // 创建目标目录
91
- mkdir(path.dirname(dest));
92
-
93
- // 复制文件
94
- if (transform) {
95
- fs.writeFileSync(dest, transform(fs.readFileSync(src, 'utf8'), srcStats.path, srcStats));
96
- } else {
97
- fs.copyFileSync(src, dest);
98
- }
99
- }
100
- }
101
-
102
-
103
- /**
104
- *****************************************
105
- * 复制文件或目录到文件夹
106
- *****************************************
107
- */
108
- function copy(src: string, dest: string): void;
109
- function copy(src: string, dest: string, mode: Options['mode']): void;
110
- function copy(src: string, dest: string, transform: Transform): void;
111
- function copy(src: string, dest: string, { mode, ignore, transform }: Options): void;
112
- function copy(src: string, dest: string, options: Options | Transform | string = {}): void {
113
- const opts: Options = { mode: 'merge', ignore: ['node_modules', '.DS_Store'] };
114
-
115
- // 获取参数
116
- switch (typeof options) {
117
- case 'function':
118
- opts.transform = options;
119
- break;
120
- case 'string':
121
- opts.mode = options as Options['mode'];
122
- break;
123
- case 'object':
124
- Object.assign(opts, options);
125
- break;
126
- default:
127
- break;
128
- }
129
-
130
- // 执行复制
131
- doCopy(src, dest, opts as Required<Options>);
132
- }
133
-
134
-
135
- /**
136
- *****************************************
137
- * 抛出接口
138
- *****************************************
139
- */
140
- export { copy };
141
-
package/src/cpdir.ts DELETED
@@ -1,47 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2020-09-12 16:28:47
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- import * as fs from 'fs';
16
- import * as path from 'path';
17
- import { mapdir } from './mapdir';
18
- import { readFile } from './readFile';
19
- import { writeFile } from './writeFile';
20
-
21
-
22
- /**
23
- *****************************************
24
- * 复制处理函数
25
- *****************************************
26
- */
27
- export type Handler = (source: string, file: string, stats: fs.Stats) => string;
28
-
29
-
30
- /**
31
- *****************************************
32
- * 复制文件夹
33
- *****************************************
34
- */
35
- export function cpdir(src: string, dist: string, handler: Handler = f => f): string[] {
36
- return mapdir(src, (file, stats) => {
37
- if (!stats.isDirectory()) {
38
- writeFile(
39
- path.resolve(dist, path.relative(src, file)),
40
- handler(readFile(file), file, stats),
41
- );
42
- }
43
-
44
- // 返回文件路径
45
- return file;
46
- });
47
- }
package/src/cwd.ts DELETED
@@ -1,15 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2019-11-14 10:19:06
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 获取当前路径
13
- *****************************************
14
- */
15
- export { resolve as cwd } from 'path';
package/src/dirname.ts DELETED
@@ -1,34 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2019-11-07 16:37:22
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- import * as path from 'path';
16
-
17
-
18
- /**
19
- *****************************************
20
- * 获取上级目录
21
- *****************************************
22
- */
23
- export function dirname(dir: string): string {
24
- let sup: string;
25
-
26
- // 解析路径
27
- dir = path.resolve(dir);
28
-
29
- // 获取上级目录
30
- sup = path.dirname(dir);
31
-
32
- // 返回结果
33
- return sup === dir ? '' : sup;
34
- }
package/src/extname.ts DELETED
@@ -1,15 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2020-06-16 13:20:41
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 获取文件名
13
- *****************************************
14
- */
15
- export { extname } from 'path';
package/src/filename.ts DELETED
@@ -1,25 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2020-06-16 13:20:41
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- import * as path from 'path';
16
-
17
-
18
- /**
19
- *****************************************
20
- * 获取文件名
21
- *****************************************
22
- */
23
- export function filename(file: string): string {
24
- return path.basename(file, path.extname(file));
25
- }
package/src/find.ts DELETED
@@ -1,106 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2019-11-22 20:10:21
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- import { readdir } from './readdir';
16
- import { isDirectory } from './isDirectory';
17
-
18
-
19
- /**
20
- *****************************************
21
- * 选项
22
- *****************************************
23
- */
24
- interface Options {
25
- ignore?: string[];
26
- }
27
-
28
-
29
- /**
30
- *****************************************
31
- * 创建匹配函数
32
- *****************************************
33
- */
34
- export function matchsWith(name: string | RegExp): (str: string) => boolean {
35
-
36
- // 匹配正则
37
- if (name instanceof RegExp) {
38
- const reg = name;
39
-
40
- // 返回函数
41
- return (str: string) => reg.test(str);
42
- }
43
-
44
- // 匹配全部
45
- if (name === '*' || !name) {
46
- return () => true;
47
- }
48
-
49
- // 匹配开头
50
- if (name.charAt(0) === '^') {
51
- const prefix = name.slice(1);
52
-
53
- // 返回匹配函数
54
- return (str: string) => str.startsWith(prefix);
55
- }
56
-
57
- // 匹配结束
58
- if (name.charAt(name.length - 1) === '$') {
59
- const suffix = name.slice(0, -1);
60
-
61
- // 返回匹配函数
62
- return (str: string) => str.endsWith(suffix);
63
- }
64
-
65
- // 完全匹配
66
- return (str: string) => str === name;
67
- }
68
-
69
-
70
- /**
71
- *****************************************
72
- * 查找目录
73
- *****************************************
74
- */
75
- function find(name: string | RegExp, dir = '.', options: Options = {}): string[] {
76
- let match = matchsWith(name),
77
- result: string[] = [],
78
- ignore: string[] = options.ignore || ['node_modules', '.DS_Store'];
79
-
80
- // 执行查找
81
- readdir(dir).forEach(stats => {
82
- if (!ignore.includes(stats.name)) {
83
-
84
- // 匹配成功
85
- if (match(stats.name)) {
86
- return result.push(stats.path);
87
- }
88
-
89
- // 查找子目录
90
- if (isDirectory(stats.path)) {
91
- result = result.concat(find(name, stats.path, options));
92
- }
93
- }
94
- });
95
-
96
- // 返回结果
97
- return result;
98
- }
99
-
100
-
101
- /**
102
- *****************************************
103
- * 抛出接口
104
- *****************************************
105
- */
106
- export { find };
package/src/findFile.ts DELETED
@@ -1,61 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2019-11-22 20:10:21
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- import { readdir } from './readdir';
16
- import { isDirectory } from './isDirectory';
17
- import { matchsWith } from './find';
18
-
19
-
20
- /**
21
- *****************************************
22
- * 选项
23
- *****************************************
24
- */
25
- interface Options {
26
- ignore?: string[];
27
- }
28
-
29
-
30
- /**
31
- *****************************************
32
- * 查找目录
33
- *****************************************
34
- */
35
- function findFile(name: string | RegExp, dir = '.', options: Options = {}): string[] {
36
- let match = matchsWith(name),
37
- result: string[] = [],
38
- ignore: string[] = options.ignore || ['node_modules', '.DS_Store'];
39
-
40
- // 执行查找
41
- readdir(dir).forEach(find => {
42
- if (!ignore.includes(find.name)) {
43
- if (isDirectory(find.path)) {
44
- result = result.concat(findFile(name, find.path, options));
45
- } else if (match(find.name)) {
46
- result.push(find.path);
47
- }
48
- }
49
- });
50
-
51
- // 返回结果
52
- return result;
53
- }
54
-
55
-
56
- /**
57
- *****************************************
58
- * 抛出接口
59
- *****************************************
60
- */
61
- export { findFile };
package/src/finddir.ts DELETED
@@ -1,61 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2019-11-22 20:10:21
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- import { readdir } from './readdir';
16
- import { isDirectory } from './isDirectory';
17
- import { matchsWith } from './find';
18
-
19
-
20
- /**
21
- *****************************************
22
- * 选项
23
- *****************************************
24
- */
25
- interface Options {
26
- ignore?: string[];
27
- }
28
-
29
-
30
- /**
31
- *****************************************
32
- * 查找目录
33
- *****************************************
34
- */
35
- function finddir(name: string | RegExp, dir = '.', options: Options = {}): string[] {
36
- let match = matchsWith(name),
37
- result: string[] = [],
38
- ignore: string[] = options.ignore || ['node_modules', '.DS_Store'];
39
-
40
- // 执行查找
41
- readdir(dir).forEach(find => {
42
- if (!ignore.includes(find.name) && isDirectory(find.path)) {
43
- if (match(find.name)) {
44
- result.push(find.path);
45
- } else {
46
- result = result.concat(finddir(name, find.path, options));
47
- }
48
- }
49
- });
50
-
51
- // 返回结果
52
- return result;
53
- }
54
-
55
-
56
- /**
57
- *****************************************
58
- * 抛出接口
59
- *****************************************
60
- */
61
- export { finddir };