@ainc/fs 0.1.16 → 0.1.18

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 (254) 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 +35 -0
  5. package/dist/index.d.ts +7 -38
  6. package/dist/index.js +21 -80
  7. package/dist/jsonc.d.ts +4 -20
  8. package/dist/jsonc.js +14 -32
  9. package/dist/lookup.d.ts +18 -0
  10. package/dist/lookup.js +63 -0
  11. package/dist/readFile.d.ts +1 -25
  12. package/dist/readFile.js +10 -14
  13. package/dist/relative.d.ts +12 -1
  14. package/dist/relative.js +48 -17
  15. package/dist/resolveFile.d.ts +6 -0
  16. package/dist/resolveFile.js +40 -0
  17. package/dist/{extname.d.ts → rm.d.ts} +2 -3
  18. package/dist/{isDirectory.js → rm.js} +16 -9
  19. package/dist/stat.d.ts +1 -17
  20. package/dist/stat.js +5 -13
  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 -147
  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.map +0 -1
  123. package/dist/isRelativePath.d.ts +0 -7
  124. package/dist/isRelativePath.d.ts.map +0 -1
  125. package/dist/isRelativePath.js +0 -45
  126. package/dist/isRelativePath.js.map +0 -1
  127. package/dist/json.d.ts +0 -22
  128. package/dist/json.d.ts.map +0 -1
  129. package/dist/json.js +0 -35
  130. package/dist/json.js.map +0 -1
  131. package/dist/jsonc.d.ts.map +0 -1
  132. package/dist/jsonc.js.map +0 -1
  133. package/dist/lstat.d.ts +0 -23
  134. package/dist/lstat.d.ts.map +0 -1
  135. package/dist/lstat.js +0 -31
  136. package/dist/lstat.js.map +0 -1
  137. package/dist/mapdir.d.ts +0 -23
  138. package/dist/mapdir.d.ts.map +0 -1
  139. package/dist/mapdir.js +0 -43
  140. package/dist/mapdir.js.map +0 -1
  141. package/dist/mkdir.d.ts +0 -7
  142. package/dist/mkdir.d.ts.map +0 -1
  143. package/dist/mkdir.js +0 -38
  144. package/dist/mkdir.js.map +0 -1
  145. package/dist/parseJSON.d.ts +0 -16
  146. package/dist/parseJSON.d.ts.map +0 -1
  147. package/dist/parseJSON.js +0 -29
  148. package/dist/parseJSON.js.map +0 -1
  149. package/dist/readFile.d.ts.map +0 -1
  150. package/dist/readFile.js.map +0 -1
  151. package/dist/readStream.d.ts +0 -37
  152. package/dist/readStream.d.ts.map +0 -1
  153. package/dist/readStream.js +0 -20
  154. package/dist/readStream.js.map +0 -1
  155. package/dist/readdir.d.ts +0 -17
  156. package/dist/readdir.d.ts.map +0 -1
  157. package/dist/readdir.js +0 -35
  158. package/dist/readdir.js.map +0 -1
  159. package/dist/readline.d.ts +0 -17
  160. package/dist/readline.d.ts.map +0 -1
  161. package/dist/readline.js +0 -25
  162. package/dist/readline.js.map +0 -1
  163. package/dist/realpath.d.ts +0 -13
  164. package/dist/realpath.d.ts.map +0 -1
  165. package/dist/realpath.js +0 -33
  166. package/dist/realpath.js.map +0 -1
  167. package/dist/relative.d.ts.map +0 -1
  168. package/dist/relative.js.map +0 -1
  169. package/dist/resolve.d.ts +0 -27
  170. package/dist/resolve.d.ts.map +0 -1
  171. package/dist/resolve.js +0 -54
  172. package/dist/resolve.js.map +0 -1
  173. package/dist/resolvePath.d.ts +0 -27
  174. package/dist/resolvePath.d.ts.map +0 -1
  175. package/dist/resolvePath.js +0 -178
  176. package/dist/resolvePath.js.map +0 -1
  177. package/dist/rmdir.d.ts +0 -7
  178. package/dist/rmdir.d.ts.map +0 -1
  179. package/dist/rmdir.js +0 -41
  180. package/dist/rmdir.js.map +0 -1
  181. package/dist/stat.d.ts.map +0 -1
  182. package/dist/stat.js.map +0 -1
  183. package/dist/supdir.d.ts +0 -22
  184. package/dist/supdir.d.ts.map +0 -1
  185. package/dist/supdir.js +0 -63
  186. package/dist/supdir.js.map +0 -1
  187. package/dist/symlink.d.ts +0 -23
  188. package/dist/symlink.d.ts.map +0 -1
  189. package/dist/symlink.js +0 -40
  190. package/dist/symlink.js.map +0 -1
  191. package/dist/unlink.d.ts +0 -7
  192. package/dist/unlink.d.ts.map +0 -1
  193. package/dist/unlink.js +0 -29
  194. package/dist/unlink.js.map +0 -1
  195. package/dist/usedir.d.ts +0 -7
  196. package/dist/usedir.d.ts.map +0 -1
  197. package/dist/usedir.js +0 -25
  198. package/dist/usedir.js.map +0 -1
  199. package/dist/writeFile.d.ts +0 -34
  200. package/dist/writeFile.d.ts.map +0 -1
  201. package/dist/writeFile.js +0 -50
  202. package/dist/writeFile.js.map +0 -1
  203. package/dist/writeStream.d.ts +0 -36
  204. package/dist/writeStream.d.ts.map +0 -1
  205. package/dist/writeStream.js +0 -20
  206. package/dist/writeStream.js.map +0 -1
  207. package/src/basename.ts +0 -15
  208. package/src/copy.ts +0 -141
  209. package/src/cpdir.ts +0 -47
  210. package/src/cwd.ts +0 -15
  211. package/src/dirname.ts +0 -34
  212. package/src/extname.ts +0 -15
  213. package/src/filename.ts +0 -25
  214. package/src/find.ts +0 -106
  215. package/src/findFile.ts +0 -61
  216. package/src/finddir.ts +0 -61
  217. package/src/helpers/FileResolver.ts +0 -282
  218. package/src/helpers/compose.ts +0 -49
  219. package/src/helpers/each.ts +0 -19
  220. package/src/helpers/match.ts +0 -31
  221. package/src/helpers/normalizePath.ts +0 -51
  222. package/src/helpers/safeCall.ts +0 -21
  223. package/src/helpers/split.ts +0 -25
  224. package/src/helpers/stripBOM.ts +0 -17
  225. package/src/helpers/stripComments.ts +0 -173
  226. package/src/homedir.ts +0 -34
  227. package/src/includePaths.ts +0 -62
  228. package/src/index.ts +0 -52
  229. package/src/indir.ts +0 -45
  230. package/src/isAbsolutePath.ts +0 -25
  231. package/src/isDirectory.ts +0 -28
  232. package/src/isRelativePath.ts +0 -52
  233. package/src/json.ts +0 -62
  234. package/src/jsonc.ts +0 -81
  235. package/src/lstat.ts +0 -40
  236. package/src/mapdir.ts +0 -59
  237. package/src/mkdir.ts +0 -43
  238. package/src/parseJSON.ts +0 -40
  239. package/src/readFile.ts +0 -64
  240. package/src/readStream.ts +0 -53
  241. package/src/readdir.ts +0 -51
  242. package/src/readline.ts +0 -42
  243. package/src/realpath.ts +0 -35
  244. package/src/relative.ts +0 -43
  245. package/src/resolve.ts +0 -83
  246. package/src/resolvePath.ts +0 -234
  247. package/src/rmdir.ts +0 -44
  248. package/src/stat.ts +0 -40
  249. package/src/supdir.ts +0 -79
  250. package/src/symlink.ts +0 -67
  251. package/src/unlink.ts +0 -31
  252. package/src/usedir.ts +0 -25
  253. package/src/writeFile.ts +0 -86
  254. package/src/writeStream.ts +0 -52
package/dist/relative.js CHANGED
@@ -1,39 +1,70 @@
1
1
  /**
2
2
  *****************************************
3
3
  * Created by edonet@163.com
4
- * Created on 2021-04-18 15:00:57
4
+ * Created on 2023-12-31 09:16:34
5
5
  *****************************************
6
6
  */
7
7
  'use strict';
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.relative = void 0;
9
+ exports.relativeFrom = void 0;
10
+ exports.isRelative = isRelative;
11
+ exports.relative = relative;
12
+ /**
13
+ *****************************************
14
+ * 加载依赖
15
+ *****************************************
16
+ */
17
+ const node_path_1 = require("node:path");
18
+ /**
19
+ *****************************************
20
+ * 判断是否为相对路径
21
+ *****************************************
22
+ */
23
+ function isRelative(id) {
24
+ // 判断是否以 '.' 开头
25
+ if (id.charAt(0) !== '.') {
26
+ return false;
27
+ }
28
+ // 获取字符
29
+ const c1 = id.charAt(1);
30
+ // 以 './' 开头
31
+ if (c1 === '/' || c1 === '') {
32
+ return true;
33
+ }
34
+ else if (c1 !== '.') {
35
+ return false;
36
+ }
37
+ // 获取下一字符
38
+ const c2 = id.charAt(2);
39
+ // 判断以
40
+ return c2 === '/' || c2 === '';
41
+ }
10
42
  /**
11
43
  *****************************************
12
44
  * 获取相对路径
13
45
  *****************************************
14
46
  */
15
- const path = require("path");
47
+ exports.relativeFrom = node_path_1.sep === '/'
48
+ ? node_path_1.relative
49
+ : function relativeFrom(from, to) {
50
+ return (0, node_path_1.relative)(from, to).replace(/\\/g, '/');
51
+ };
16
52
  /**
17
53
  *****************************************
18
54
  * 获取相对路径
19
55
  *****************************************
20
56
  */
21
57
  function relative(from, to) {
22
- let result = path.relative(from, to);
23
- // 替换分隔符
24
- if (path.sep === '\\') {
25
- result = result.split('\\').join('/');
26
- }
27
- // 补全相对路径
28
- if (result.charAt(0) !== '.') {
29
- return './' + result;
58
+ const result = (0, exports.relativeFrom)(from, to);
59
+ // 当前路径
60
+ if (!result) {
61
+ return './';
30
62
  }
31
- // 纯目录
32
- if (['..', '.'].includes(result) || result.endsWith('/..')) {
63
+ // 样式化路径
64
+ if (result === '.' || result === '..' || result.endsWith('/..')) {
33
65
  return result + '/';
34
66
  }
35
- // 返回结果
36
- return result;
67
+ else {
68
+ return result.charAt(0) === '.' ? result : './' + result;
69
+ }
37
70
  }
38
- exports.relative = relative;
39
- //# sourceMappingURL=relative.js.map
@@ -0,0 +1,6 @@
1
+ /**
2
+ *****************************************
3
+ * 解析文件
4
+ *****************************************
5
+ */
6
+ export declare function resolveFile(path: string, extensions?: string[]): string | undefined;
@@ -0,0 +1,40 @@
1
+ /**
2
+ *****************************************
3
+ * Created by edonet@163.com
4
+ * Created on 2023-12-31 09:29:59
5
+ *****************************************
6
+ */
7
+ 'use strict';
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.resolveFile = resolveFile;
10
+ /**
11
+ *****************************************
12
+ * 加载依赖
13
+ *****************************************
14
+ */
15
+ const stat_1 = require("./stat");
16
+ /**
17
+ *****************************************
18
+ * 解析文件
19
+ *****************************************
20
+ */
21
+ function resolveFile(path, extensions) {
22
+ const stats = (0, stat_1.stat)(path);
23
+ // 找到文件
24
+ if (stats === null || stats === void 0 ? void 0 : stats.isFile()) {
25
+ return path;
26
+ }
27
+ // 不再查找
28
+ if (!(extensions === null || extensions === void 0 ? void 0 : extensions.length)) {
29
+ return;
30
+ }
31
+ // 遍历扩展名
32
+ for (let i = 0; i < extensions.length; ++i) {
33
+ const file = path + extensions[i];
34
+ const stats = (0, stat_1.stat)(file);
35
+ // 查找到文件
36
+ if (stats === null || stats === void 0 ? void 0 : stats.isFile()) {
37
+ return file;
38
+ }
39
+ }
40
+ }
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  *****************************************
3
- * 获取文件名
3
+ * 删除文件或目录
4
4
  *****************************************
5
5
  */
6
- export { extname } from 'path';
7
- //# sourceMappingURL=extname.d.ts.map
6
+ export declare function rm(path: string): void;
@@ -1,27 +1,34 @@
1
1
  /**
2
2
  *****************************************
3
3
  * Created by edonet@163.com
4
- * Created on 2019-11-07 16:15:04
4
+ * Created on 2023-12-31 09:26:54
5
5
  *****************************************
6
6
  */
7
7
  'use strict';
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.isDirectory = void 0;
9
+ exports.rm = rm;
10
10
  /**
11
11
  *****************************************
12
12
  * 加载依赖
13
13
  *****************************************
14
14
  */
15
+ const node_fs_1 = require("node:fs");
15
16
  const stat_1 = require("./stat");
16
17
  /**
17
18
  *****************************************
18
- * 判断是否为文件夹
19
+ * 删除文件或目录
19
20
  *****************************************
20
21
  */
21
- function isDirectory(dir) {
22
- const stats = (0, stat_1.stat)(dir);
23
- // 返回状态判断
24
- return stats && stats.isDirectory() ? stats : null;
22
+ function rm(path) {
23
+ const stats = (0, stat_1.stat)(path);
24
+ // 不存在文件
25
+ if (!stats) {
26
+ return;
27
+ }
28
+ // 非目录
29
+ if (!stats.isDirectory()) {
30
+ return (0, node_fs_1.unlinkSync)(path);
31
+ }
32
+ // 遍历文件
33
+ (0, node_fs_1.rmSync)(path, { force: true, recursive: true });
25
34
  }
26
- exports.isDirectory = isDirectory;
27
- //# sourceMappingURL=isDirectory.js.map
package/dist/stat.d.ts CHANGED
@@ -1,22 +1,6 @@
1
- /// <reference types="node" />
2
- /**
3
- *****************************************
4
- * 加载依赖
5
- *****************************************
6
- */
7
- import * as fs from 'fs';
8
- /**
9
- *****************************************
10
- * 状态
11
- *****************************************
12
- */
13
- export interface State extends fs.Stats {
14
- path: string;
15
- }
16
1
  /**
17
2
  *****************************************
18
3
  * 获取文件状态
19
4
  *****************************************
20
5
  */
21
- export declare function stat(dir: string): State | null;
22
- //# sourceMappingURL=stat.d.ts.map
6
+ export declare function stat(path: string): import("fs").Stats | undefined;
package/dist/stat.js CHANGED
@@ -1,31 +1,23 @@
1
1
  /**
2
2
  *****************************************
3
3
  * Created by edonet@163.com
4
- * Created on 2019-11-07 16:06:57
4
+ * Created on 2023-12-31 09:11:28
5
5
  *****************************************
6
6
  */
7
7
  'use strict';
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.stat = void 0;
9
+ exports.stat = stat;
10
10
  /**
11
11
  *****************************************
12
12
  * 加载依赖
13
13
  *****************************************
14
14
  */
15
- const fs = require("fs");
16
- const path = require("path");
15
+ const node_fs_1 = require("node:fs");
17
16
  /**
18
17
  *****************************************
19
18
  * 获取文件状态
20
19
  *****************************************
21
20
  */
22
- function stat(dir) {
23
- try {
24
- return Object.assign(fs.statSync(dir), { path: path.resolve(dir) });
25
- }
26
- catch (err) {
27
- return null;
28
- }
21
+ function stat(path) {
22
+ return (0, node_fs_1.statSync)(path, { throwIfNoEntry: false });
29
23
  }
30
- exports.stat = stat;
31
- //# sourceMappingURL=stat.js.map
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  *****************************************
3
- * 过滤注释
3
+ * 去除注释
4
4
  *****************************************
5
5
  */
6
6
  export declare function stripComments(content: string): string;
7
- //# sourceMappingURL=stripComments.d.ts.map
@@ -0,0 +1,120 @@
1
+ /**
2
+ *****************************************
3
+ * Created by edonet@163.com
4
+ * Created on 2023-01-05 21:39:42
5
+ *****************************************
6
+ */
7
+ 'use strict';
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.stripComments = stripComments;
10
+ /**
11
+ *****************************************
12
+ * 定义注释标识
13
+ *****************************************
14
+ */
15
+ const singleComment = Symbol('singleComment');
16
+ const multiComment = Symbol('multiComment');
17
+ /**
18
+ *****************************************
19
+ * 判断是否转义
20
+ *****************************************
21
+ */
22
+ function isEscaped(content, index) {
23
+ let backslashCount = 0;
24
+ let idx = index;
25
+ // 遍历字符
26
+ while (content[idx--] === '\\') {
27
+ backslashCount++;
28
+ }
29
+ // 返回结果
30
+ return backslashCount % 2 === 1;
31
+ }
32
+ /**
33
+ *****************************************
34
+ * 去除注释
35
+ *****************************************
36
+ */
37
+ function stripComments(content) {
38
+ // 校验内容
39
+ if (typeof content !== 'string') {
40
+ throw new TypeError(`Expected argument \`content\` to be a \`string\`, got \`${typeof content}\``);
41
+ }
42
+ // 定义变量
43
+ let isInsideString = false;
44
+ let isInsideComment = false;
45
+ let offset = 0;
46
+ let buffer = '';
47
+ let result = '';
48
+ let commaIndex = -1;
49
+ // 遍历字符
50
+ for (let index = 0; index < content.length; index++) {
51
+ const curr = content[index];
52
+ // 处理字符串
53
+ if (curr === '"' && !isInsideComment && !isEscaped(content, index - 1)) {
54
+ isInsideString = !isInsideString;
55
+ }
56
+ // 跳转字符串
57
+ if (isInsideString) {
58
+ continue;
59
+ }
60
+ // 退出单行注释
61
+ if (isInsideComment === singleComment) {
62
+ if (curr === '\n') {
63
+ isInsideComment = false;
64
+ offset = index;
65
+ }
66
+ continue;
67
+ }
68
+ // 获取下一字符
69
+ const next = content[index + 1];
70
+ // 退出多行注释
71
+ if (isInsideComment === multiComment) {
72
+ if (curr === '*' && next === '/') {
73
+ isInsideComment = false;
74
+ index += 1;
75
+ offset = index + 1;
76
+ }
77
+ continue;
78
+ }
79
+ // 处理注释起始位置
80
+ if (curr === '/') {
81
+ if (next === '/') {
82
+ buffer += content.slice(offset, index);
83
+ offset = index;
84
+ isInsideComment = singleComment;
85
+ index++;
86
+ continue;
87
+ }
88
+ if (next === '*') {
89
+ buffer += content.slice(offset, index);
90
+ offset = index;
91
+ isInsideComment = multiComment;
92
+ index++;
93
+ continue;
94
+ }
95
+ }
96
+ // 处理末尾逗号
97
+ if (commaIndex !== -1) {
98
+ if (curr === '}' || curr === ']') {
99
+ buffer += content.slice(offset, index);
100
+ result += buffer.slice(1);
101
+ buffer = '';
102
+ offset = index;
103
+ commaIndex = -1;
104
+ }
105
+ else if (curr !== ' ' && curr !== '\t' && curr !== '\r' && curr !== '\n') {
106
+ buffer += content.slice(offset, index);
107
+ offset = index;
108
+ commaIndex = -1;
109
+ }
110
+ }
111
+ else if (curr === ',') {
112
+ result += buffer + content.slice(offset, index);
113
+ buffer = '';
114
+ offset = index;
115
+ commaIndex = index;
116
+ }
117
+ }
118
+ // 返回结果
119
+ return result + buffer + (isInsideComment ? '' : content.slice(offset));
120
+ }
package/package.json CHANGED
@@ -1,31 +1,34 @@
1
1
  {
2
- "name": "@ainc/fs",
3
- "version": "0.1.16",
4
- "description": "file system",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "bin": {
8
- "fs": "bin/cli.js"
9
- },
10
- "files": [
11
- "src",
12
- "bin",
13
- "dist"
14
- ],
15
- "scripts": {
16
- "start": "yarn watch",
17
- "build": "yarn compile",
18
- "watch": "yarn compile --watch",
19
- "compile": "esc -p ./src",
20
- "prepublishOnly": "yarn build",
21
- "test": "jest",
22
- "clean": "rm -rf ./dist"
23
- },
24
- "repository": "git@absock.net:repo/ainc/fs.git",
25
- "author": "edonet <edonet@163.com>",
26
- "license": "MIT",
27
- "devDependencies": {
28
- "@types/jest": "^27.4.0",
29
- "@types/node": "^17.0.5"
30
- }
31
- }
2
+ "name": "@ainc/fs",
3
+ "version": "0.1.18",
4
+ "description": "Let's do something nice with @ainc/esb!",
5
+ "types": "dist/index.d.ts",
6
+ "main": "dist/index.js",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "repository": "git@absock.net:ainc/esb.git",
11
+ "author": "edonet@163.com",
12
+ "license": "MIT",
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "dependencies": {
17
+ "typescript": "^5.8.3"
18
+ },
19
+ "devDependencies": {
20
+ "@jest/globals": "^29.7.0",
21
+ "@swc/core": "^1.11.24",
22
+ "@swc/jest": "^0.2.38",
23
+ "@types/node": "^22.15.19",
24
+ "jest": "^29.7.0"
25
+ },
26
+ "scripts": {
27
+ "start": "tsc",
28
+ "build": "yarn clean && yarn compile",
29
+ "watch": "yarn compile --watch",
30
+ "compile": "tsc -p ./tsconfig.build.json",
31
+ "test": "jest",
32
+ "clean": "rimraf ./dist"
33
+ }
34
+ }
package/bin/clean.js DELETED
@@ -1,45 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2019-11-22 20:47:19
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- const path = require('path');
16
- const { default: finddir } = require('../dist/finddir');
17
- const { default: rmdir } = require('../dist/rmdir');
18
-
19
-
20
- /**
21
- *****************************************
22
- * 获取文件系统状态
23
- *****************************************
24
- */
25
- module.exports = function clean(argv) {
26
- let i = 1,
27
- len = argv.length;
28
-
29
- // 打印目录
30
- console.log('-'.repeat(80));
31
- console.log('Clean');
32
- console.log('-'.repeat(80));
33
-
34
- // 查找目录
35
- for (; i < len; i ++) {
36
- finddir(argv[i], '.').forEach(dir => {
37
-
38
- // 清除目录
39
- rmdir(dir);
40
-
41
- // 打印日志
42
- console.log(`./${ path.relative(process.cwd(), dir) }`);
43
- });
44
- }
45
- };
package/bin/cli.js DELETED
@@ -1,42 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- *****************************************
4
- * Created by edonet@163.com
5
- * Created on 2019-11-22 20:06:09
6
- *****************************************
7
- */
8
- 'use strict';
9
-
10
-
11
- /**
12
- *****************************************
13
- * 定义脚本
14
- *****************************************
15
- */
16
- function main() {
17
- let argv = process.argv.slice(2);
18
-
19
- // 执行子命令
20
- switch (argv[0]) {
21
- case 'status':
22
- case 'pull':
23
- case 'push':
24
- return require('./git')(argv);
25
- case 'clean':
26
- case 'rm':
27
- case 'rmdir':
28
- return require('./clean')(argv);
29
- case 'run':
30
- return require('./run')('yarn', argv);
31
- default:
32
- return require('./run')(argv.shift(), argv);
33
- }
34
- }
35
-
36
-
37
- /**
38
- *****************************************
39
- * 执行脚本
40
- *****************************************
41
- */
42
- main();
package/bin/git.js DELETED
@@ -1,40 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2019-11-22 20:47:19
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- const cp = require('child_process');
16
- const path = require('path');
17
- const { default: finddir } = require('../dist/finddir');
18
-
19
-
20
- /**
21
- *****************************************
22
- * 获取文件系统状态
23
- *****************************************
24
- */
25
- module.exports = function git(argv) {
26
- finddir('.git', '.').forEach((dir, idx) => {
27
- let cwd = path.dirname(dir);
28
-
29
- // 打印空行
30
- idx && console.log('\n');
31
-
32
- // 打印目录
33
- console.log('-'.repeat(80));
34
- console.log(`Status: ./${ path.relative(process.cwd(), cwd)}`);
35
- console.log('-'.repeat(80));
36
-
37
- // 执行命令
38
- cp.spawnSync('git', argv, { stdio: 'inherit', cwd });
39
- });
40
- };
package/bin/run.js DELETED
@@ -1,41 +0,0 @@
1
- /**
2
- *****************************************
3
- * Created by edonet@163.com
4
- * Created on 2019-11-22 20:47:19
5
- *****************************************
6
- */
7
- 'use strict';
8
-
9
-
10
- /**
11
- *****************************************
12
- * 加载依赖
13
- *****************************************
14
- */
15
- const cp = require('child_process');
16
- const path = require('path');
17
- const { default: findFile } = require('../dist/findFile');
18
-
19
-
20
- /**
21
- *****************************************
22
- * 获取文件系统状态
23
- *****************************************
24
- */
25
- module.exports = function tsc(cli, argv) {
26
- findFile('package.json', '.').forEach((dir, idx) => {
27
- let cwd = path.dirname(dir);
28
-
29
- // 打印空行
30
- idx && console.log('');
31
-
32
- // 打印目录
33
- console.log('-'.repeat(80));
34
- console.log(`Status: ./${ path.relative(process.cwd(), cwd)}`);
35
- console.log('-'.repeat(80));
36
-
37
- // 执行命令
38
- cp.spawnSync(cli, argv, { stdio: 'inherit', cwd });
39
- });
40
- };
41
-
@@ -1,7 +0,0 @@
1
- /**
2
- *****************************************
3
- * 获取文件名
4
- *****************************************
5
- */
6
- export { basename } from 'path';
7
- //# sourceMappingURL=basename.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"basename.d.ts","sourceRoot":"","sources":["../src/basename.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC"}
package/dist/basename.js DELETED
@@ -1,17 +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
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.basename = void 0;
10
- /**
11
- *****************************************
12
- * 获取文件名
13
- *****************************************
14
- */
15
- var path_1 = require("path");
16
- Object.defineProperty(exports, "basename", { enumerable: true, get: function () { return path_1.basename; } });
17
- //# sourceMappingURL=basename.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"basename.js","sourceRoot":"","sources":["../src/basename.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,YAAY,CAAC;;;AAGb;;;;GAIG;AACH,6BAAgC;AAAvB,gGAAA,QAAQ,OAAA"}