@ainc/fs 0.1.16 → 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 -20
  8. package/dist/jsonc.js +14 -31
  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 -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 +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 -173
  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 -81
  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
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 edonet <edonet@163.com>
3
+ Copyright (c) 2028 absock@163.com
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,50 +1,26 @@
1
- # @ainc/fs
2
- file system
1
+ # @ainc/esb
2
+ Let's do something nice with @ainc/esb!
3
3
 
4
4
  ## Install
5
5
  ``` shell
6
- $ yarn add @ainc/fs
6
+ $ yarn global add @ainc/esb
7
7
  ```
8
8
 
9
9
  ## Usage
10
- ``` javascript
11
- import * as fs from '@ainc/fs';
10
+ ``` shell
11
+ $ esb -p ./src
12
12
  ```
13
13
 
14
- ## API
15
- * homedir(): string;
16
- * cwd(...args: string[]): string;
17
- * stat(file: string): Stats | null;
18
- * lstat(file: string): Stats | null;
19
- * dirname(dir: string): string;
20
- * filename(file: string): string;
21
- * basename(file: string, ext?: string): string
22
- * extname(file: string): string;
23
- * readFile(path: string): string;
24
- * writeFile(path: string, content: string | Buffer): void;
25
- * unlink(path: string): boolean;
26
- * symlink(src: string, dest: string, options?: Options): void;
27
- * copy(src: string, dest: string, options?: Options): void;
28
- * isDirectory(file: string): boolean;
29
- * indir(dir: string, file: string): boolean;
30
- * indir(dir: string): (file: string) => boolean;
31
- * mkdir(dir: string): string;
32
- * rmdir(dir: string): boolean;
33
- * readdir(dir: string): State[]
34
- * cpdir(src: string, dist: string, handler: Handler): string[];
35
- * mapdir<T>(dir: string, handler: Handler<T>): T[];
36
- * usedir(...basedir: string[]): (...args: string[]) => string;
37
- * supdir<T>(dir: string, handler: Handler<T>): T | undefined;
38
- * resolve(dir: string | string[], options?: Options): Asset[];
39
- * relative(from: string, to: string): string;
40
- * find(name: string, dir = '.', options?: Options): string[];
41
- * finddir(name: string, dir = '.', options: Options): string[];
42
- * findFile(name: string, dir = '.', options?: Options): string[];
43
- * json(file: string): object | null;
44
- * json(file: string, data: object): object | null;
45
- * parseJSON<T>(source: string, options?: Options): T;
46
- * resolveFile(file: string, options?: Options): void | string;
47
- * resolveAlias(options: Options): ResolvePath;
48
- * isAbsolutePath(source: string): boolean;
49
- * isRelativePath(source: string): boolean;
50
- * includePaths(paths: string[]): (source: string) => boolean;
14
+ ## VS Code
15
+ ``` json
16
+ {
17
+ "name": "Launch Script",
18
+ "type": "node",
19
+ "request": "launch",
20
+ "autoAttachChildProcesses": true,
21
+ "runtimeExecutable": "esb",
22
+ "args": [
23
+ "${file}"
24
+ ]
25
+ }
26
+ ```
@@ -0,0 +1,6 @@
1
+ /**
2
+ *****************************************
3
+ * 向上查找
4
+ *****************************************
5
+ */
6
+ export declare function findUp<T>(from: string, handler: (path: string) => T | undefined): T | undefined;
package/dist/findUp.js ADDED
@@ -0,0 +1,36 @@
1
+ /**
2
+ *****************************************
3
+ * Created by edonet@163.com
4
+ * Created on 2023-12-31 09:32:31
5
+ *****************************************
6
+ */
7
+ 'use strict';
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.findUp = void 0;
10
+ /**
11
+ *****************************************
12
+ * 加载依赖
13
+ *****************************************
14
+ */
15
+ const node_path_1 = require("node:path");
16
+ /**
17
+ *****************************************
18
+ * 向上查找
19
+ *****************************************
20
+ */
21
+ function findUp(from, handler) {
22
+ let latest = '';
23
+ let current = from;
24
+ // 遍历目录
25
+ while (current !== latest) {
26
+ const result = handler(current);
27
+ // 存在结果
28
+ if (result !== undefined) {
29
+ return result;
30
+ }
31
+ // 获取上级目录
32
+ latest = current;
33
+ current = (0, node_path_1.dirname)(current);
34
+ }
35
+ }
36
+ exports.findUp = findUp;
package/dist/index.d.ts CHANGED
@@ -1,44 +1,13 @@
1
1
  /**
2
2
  *****************************************
3
- * 抛出模块
3
+ * 导出接口
4
4
  *****************************************
5
5
  */
6
- export { homedir } from './homedir';
7
- export { cwd } from './cwd';
8
- export { realpath } from './realpath';
9
- export { dirname } from './dirname';
10
- export { filename } from './filename';
11
- export { basename } from './basename';
12
- export { extname } from './extname';
13
6
  export { stat } from './stat';
14
- export { lstat } from './lstat';
15
- export { isDirectory } from './isDirectory';
16
- export { indir } from './indir';
17
- export { json } from './json';
18
- export { jsonc } from './jsonc';
19
- export { parseJSON } from './parseJSON';
20
- export { copy } from './copy';
21
- export { cpdir } from './cpdir';
22
- export { find } from './find';
7
+ export { isRelative, relative } from './relative';
8
+ export { resolveFile } from './resolveFile';
23
9
  export { readFile } from './readFile';
24
- export { readline } from './readline';
25
- export { readStream } from './readStream';
26
- export { writeFile } from './writeFile';
27
- export { writeStream } from './writeStream';
28
- export { findFile } from './findFile';
29
- export { resolve } from './resolve';
30
- export { relative } from './relative';
31
- export { unlink } from './unlink';
32
- export { readdir } from './readdir';
33
- export { mkdir } from './mkdir';
34
- export { finddir } from './finddir';
35
- export { rmdir } from './rmdir';
36
- export { mapdir } from './mapdir';
37
- export { symlink } from './symlink';
38
- export { usedir } from './usedir';
39
- export { supdir } from './supdir';
40
- export { resolvePath } from './resolvePath';
41
- export { includePaths } from './includePaths';
42
- export { isAbsolutePath } from './isAbsolutePath';
43
- export { isRelativePath } from './isRelativePath';
44
- //# sourceMappingURL=index.d.ts.map
10
+ export { rm } from './rm';
11
+ export { lookup } from './lookup';
12
+ export { findUp } from './findUp';
13
+ export { json, jsonc } from './jsonc';
package/dist/index.js CHANGED
@@ -1,91 +1,32 @@
1
1
  /**
2
2
  *****************************************
3
3
  * Created by edonet@163.com
4
- * Created on 2019-11-07 15:59:39
4
+ * Created on 2023-12-31 09:11:10
5
5
  *****************************************
6
6
  */
7
7
  'use strict';
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.isRelativePath = exports.isAbsolutePath = exports.includePaths = exports.resolvePath = exports.supdir = exports.usedir = exports.symlink = exports.mapdir = exports.rmdir = exports.finddir = exports.mkdir = exports.readdir = exports.unlink = exports.relative = exports.resolve = exports.findFile = exports.writeStream = exports.writeFile = exports.readStream = exports.readline = exports.readFile = exports.find = exports.cpdir = exports.copy = exports.parseJSON = exports.jsonc = exports.json = exports.indir = exports.isDirectory = exports.lstat = exports.stat = exports.extname = exports.basename = exports.filename = exports.dirname = exports.realpath = exports.cwd = exports.homedir = void 0;
9
+ exports.jsonc = exports.json = exports.findUp = exports.lookup = exports.rm = exports.readFile = exports.resolveFile = exports.relative = exports.isRelative = exports.stat = void 0;
10
10
  /**
11
11
  *****************************************
12
- * 抛出模块
12
+ * 导出接口
13
13
  *****************************************
14
14
  */
15
- var homedir_1 = function () { var __exports = require("./homedir"); homedir_1 = function () { return __exports; }; return __exports; };
16
- Object.defineProperty(exports, "homedir", { enumerable: true, get: function () { return homedir_1().homedir; } });
17
- var cwd_1 = function () { var __exports = require("./cwd"); cwd_1 = function () { return __exports; }; return __exports; };
18
- Object.defineProperty(exports, "cwd", { enumerable: true, get: function () { return cwd_1().cwd; } });
19
- var realpath_1 = function () { var __exports = require("./realpath"); realpath_1 = function () { return __exports; }; return __exports; };
20
- Object.defineProperty(exports, "realpath", { enumerable: true, get: function () { return realpath_1().realpath; } });
21
- var dirname_1 = function () { var __exports = require("./dirname"); dirname_1 = function () { return __exports; }; return __exports; };
22
- Object.defineProperty(exports, "dirname", { enumerable: true, get: function () { return dirname_1().dirname; } });
23
- var filename_1 = function () { var __exports = require("./filename"); filename_1 = function () { return __exports; }; return __exports; };
24
- Object.defineProperty(exports, "filename", { enumerable: true, get: function () { return filename_1().filename; } });
25
- var basename_1 = function () { var __exports = require("./basename"); basename_1 = function () { return __exports; }; return __exports; };
26
- Object.defineProperty(exports, "basename", { enumerable: true, get: function () { return basename_1().basename; } });
27
- var extname_1 = function () { var __exports = require("./extname"); extname_1 = function () { return __exports; }; return __exports; };
28
- Object.defineProperty(exports, "extname", { enumerable: true, get: function () { return extname_1().extname; } });
29
- var stat_1 = function () { var __exports = require("./stat"); stat_1 = function () { return __exports; }; return __exports; };
30
- Object.defineProperty(exports, "stat", { enumerable: true, get: function () { return stat_1().stat; } });
31
- var lstat_1 = function () { var __exports = require("./lstat"); lstat_1 = function () { return __exports; }; return __exports; };
32
- Object.defineProperty(exports, "lstat", { enumerable: true, get: function () { return lstat_1().lstat; } });
33
- var isDirectory_1 = function () { var __exports = require("./isDirectory"); isDirectory_1 = function () { return __exports; }; return __exports; };
34
- Object.defineProperty(exports, "isDirectory", { enumerable: true, get: function () { return isDirectory_1().isDirectory; } });
35
- var indir_1 = function () { var __exports = require("./indir"); indir_1 = function () { return __exports; }; return __exports; };
36
- Object.defineProperty(exports, "indir", { enumerable: true, get: function () { return indir_1().indir; } });
37
- var json_1 = function () { var __exports = require("./json"); json_1 = function () { return __exports; }; return __exports; };
38
- Object.defineProperty(exports, "json", { enumerable: true, get: function () { return json_1().json; } });
39
- var jsonc_1 = function () { var __exports = require("./jsonc"); jsonc_1 = function () { return __exports; }; return __exports; };
40
- Object.defineProperty(exports, "jsonc", { enumerable: true, get: function () { return jsonc_1().jsonc; } });
41
- var parseJSON_1 = function () { var __exports = require("./parseJSON"); parseJSON_1 = function () { return __exports; }; return __exports; };
42
- Object.defineProperty(exports, "parseJSON", { enumerable: true, get: function () { return parseJSON_1().parseJSON; } });
43
- var copy_1 = function () { var __exports = require("./copy"); copy_1 = function () { return __exports; }; return __exports; };
44
- Object.defineProperty(exports, "copy", { enumerable: true, get: function () { return copy_1().copy; } });
45
- var cpdir_1 = function () { var __exports = require("./cpdir"); cpdir_1 = function () { return __exports; }; return __exports; };
46
- Object.defineProperty(exports, "cpdir", { enumerable: true, get: function () { return cpdir_1().cpdir; } });
47
- var find_1 = function () { var __exports = require("./find"); find_1 = function () { return __exports; }; return __exports; };
48
- Object.defineProperty(exports, "find", { enumerable: true, get: function () { return find_1().find; } });
49
- var readFile_1 = function () { var __exports = require("./readFile"); readFile_1 = function () { return __exports; }; return __exports; };
50
- Object.defineProperty(exports, "readFile", { enumerable: true, get: function () { return readFile_1().readFile; } });
51
- var readline_1 = function () { var __exports = require("./readline"); readline_1 = function () { return __exports; }; return __exports; };
52
- Object.defineProperty(exports, "readline", { enumerable: true, get: function () { return readline_1().readline; } });
53
- var readStream_1 = function () { var __exports = require("./readStream"); readStream_1 = function () { return __exports; }; return __exports; };
54
- Object.defineProperty(exports, "readStream", { enumerable: true, get: function () { return readStream_1().readStream; } });
55
- var writeFile_1 = function () { var __exports = require("./writeFile"); writeFile_1 = function () { return __exports; }; return __exports; };
56
- Object.defineProperty(exports, "writeFile", { enumerable: true, get: function () { return writeFile_1().writeFile; } });
57
- var writeStream_1 = function () { var __exports = require("./writeStream"); writeStream_1 = function () { return __exports; }; return __exports; };
58
- Object.defineProperty(exports, "writeStream", { enumerable: true, get: function () { return writeStream_1().writeStream; } });
59
- var findFile_1 = function () { var __exports = require("./findFile"); findFile_1 = function () { return __exports; }; return __exports; };
60
- Object.defineProperty(exports, "findFile", { enumerable: true, get: function () { return findFile_1().findFile; } });
61
- var resolve_1 = function () { var __exports = require("./resolve"); resolve_1 = function () { return __exports; }; return __exports; };
62
- Object.defineProperty(exports, "resolve", { enumerable: true, get: function () { return resolve_1().resolve; } });
63
- var relative_1 = function () { var __exports = require("./relative"); relative_1 = function () { return __exports; }; return __exports; };
64
- Object.defineProperty(exports, "relative", { enumerable: true, get: function () { return relative_1().relative; } });
65
- var unlink_1 = function () { var __exports = require("./unlink"); unlink_1 = function () { return __exports; }; return __exports; };
66
- Object.defineProperty(exports, "unlink", { enumerable: true, get: function () { return unlink_1().unlink; } });
67
- var readdir_1 = function () { var __exports = require("./readdir"); readdir_1 = function () { return __exports; }; return __exports; };
68
- Object.defineProperty(exports, "readdir", { enumerable: true, get: function () { return readdir_1().readdir; } });
69
- var mkdir_1 = function () { var __exports = require("./mkdir"); mkdir_1 = function () { return __exports; }; return __exports; };
70
- Object.defineProperty(exports, "mkdir", { enumerable: true, get: function () { return mkdir_1().mkdir; } });
71
- var finddir_1 = function () { var __exports = require("./finddir"); finddir_1 = function () { return __exports; }; return __exports; };
72
- Object.defineProperty(exports, "finddir", { enumerable: true, get: function () { return finddir_1().finddir; } });
73
- var rmdir_1 = function () { var __exports = require("./rmdir"); rmdir_1 = function () { return __exports; }; return __exports; };
74
- Object.defineProperty(exports, "rmdir", { enumerable: true, get: function () { return rmdir_1().rmdir; } });
75
- var mapdir_1 = function () { var __exports = require("./mapdir"); mapdir_1 = function () { return __exports; }; return __exports; };
76
- Object.defineProperty(exports, "mapdir", { enumerable: true, get: function () { return mapdir_1().mapdir; } });
77
- var symlink_1 = function () { var __exports = require("./symlink"); symlink_1 = function () { return __exports; }; return __exports; };
78
- Object.defineProperty(exports, "symlink", { enumerable: true, get: function () { return symlink_1().symlink; } });
79
- var usedir_1 = function () { var __exports = require("./usedir"); usedir_1 = function () { return __exports; }; return __exports; };
80
- Object.defineProperty(exports, "usedir", { enumerable: true, get: function () { return usedir_1().usedir; } });
81
- var supdir_1 = function () { var __exports = require("./supdir"); supdir_1 = function () { return __exports; }; return __exports; };
82
- Object.defineProperty(exports, "supdir", { enumerable: true, get: function () { return supdir_1().supdir; } });
83
- var resolvePath_1 = function () { var __exports = require("./resolvePath"); resolvePath_1 = function () { return __exports; }; return __exports; };
84
- Object.defineProperty(exports, "resolvePath", { enumerable: true, get: function () { return resolvePath_1().resolvePath; } });
85
- var includePaths_1 = function () { var __exports = require("./includePaths"); includePaths_1 = function () { return __exports; }; return __exports; };
86
- Object.defineProperty(exports, "includePaths", { enumerable: true, get: function () { return includePaths_1().includePaths; } });
87
- var isAbsolutePath_1 = function () { var __exports = require("./isAbsolutePath"); isAbsolutePath_1 = function () { return __exports; }; return __exports; };
88
- Object.defineProperty(exports, "isAbsolutePath", { enumerable: true, get: function () { return isAbsolutePath_1().isAbsolutePath; } });
89
- var isRelativePath_1 = function () { var __exports = require("./isRelativePath"); isRelativePath_1 = function () { return __exports; }; return __exports; };
90
- Object.defineProperty(exports, "isRelativePath", { enumerable: true, get: function () { return isRelativePath_1().isRelativePath; } });
91
- //# sourceMappingURL=index.js.map
15
+ var stat_1 = require("./stat");
16
+ Object.defineProperty(exports, "stat", { enumerable: true, get: function () { return stat_1.stat; } });
17
+ var relative_1 = require("./relative");
18
+ Object.defineProperty(exports, "isRelative", { enumerable: true, get: function () { return relative_1.isRelative; } });
19
+ Object.defineProperty(exports, "relative", { enumerable: true, get: function () { return relative_1.relative; } });
20
+ var resolveFile_1 = require("./resolveFile");
21
+ Object.defineProperty(exports, "resolveFile", { enumerable: true, get: function () { return resolveFile_1.resolveFile; } });
22
+ var readFile_1 = require("./readFile");
23
+ Object.defineProperty(exports, "readFile", { enumerable: true, get: function () { return readFile_1.readFile; } });
24
+ var rm_1 = require("./rm");
25
+ Object.defineProperty(exports, "rm", { enumerable: true, get: function () { return rm_1.rm; } });
26
+ var lookup_1 = require("./lookup");
27
+ Object.defineProperty(exports, "lookup", { enumerable: true, get: function () { return lookup_1.lookup; } });
28
+ var findUp_1 = require("./findUp");
29
+ Object.defineProperty(exports, "findUp", { enumerable: true, get: function () { return findUp_1.findUp; } });
30
+ var jsonc_1 = require("./jsonc");
31
+ Object.defineProperty(exports, "json", { enumerable: true, get: function () { return jsonc_1.json; } });
32
+ Object.defineProperty(exports, "jsonc", { enumerable: true, get: function () { return jsonc_1.jsonc; } });
package/dist/jsonc.d.ts CHANGED
@@ -1,28 +1,12 @@
1
1
  /**
2
2
  *****************************************
3
- * 数据接口
3
+ * 解析 JSON
4
4
  *****************************************
5
5
  */
6
- interface Data {
7
- [key: string]: unknown;
8
- }
6
+ export declare function json<T>(content: string): T;
9
7
  /**
10
8
  *****************************************
11
- * 解析内容
9
+ * 解析 JSONC
12
10
  *****************************************
13
11
  */
14
- declare function parse<T = Data>(content: string): T | null;
15
- /**
16
- *****************************************
17
- * 读取/写入【jsonc】文件
18
- *****************************************
19
- */
20
- declare function jsonc<T = Data>(path: string): T | null;
21
- declare function jsonc<T = Data>(path: string, data: T): T;
22
- /**
23
- *****************************************
24
- * 抛出接口
25
- *****************************************
26
- */
27
- export { jsonc, parse };
28
- //# sourceMappingURL=jsonc.d.ts.map
12
+ export declare function jsonc<T>(content: string): T;
package/dist/jsonc.js CHANGED
@@ -1,50 +1,33 @@
1
1
  /**
2
2
  *****************************************
3
3
  * Created by edonet@163.com
4
- * Created on 2019-11-07 21:27:52
4
+ * Created on 2023-12-31 10:16:56
5
5
  *****************************************
6
6
  */
7
7
  'use strict';
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.parse = exports.jsonc = void 0;
9
+ exports.jsonc = exports.json = void 0;
10
10
  /**
11
11
  *****************************************
12
12
  * 加载依赖
13
13
  *****************************************
14
14
  */
15
- const stat_1 = require("./stat");
16
- const readFile_1 = require("./readFile");
17
- const writeFile_1 = require("./writeFile");
18
- const stripComments_1 = require("./helpers/stripComments");
15
+ const stripComments_1 = require("./utils/stripComments");
19
16
  /**
20
17
  *****************************************
21
- * 解析内容
18
+ * 解析 JSON
22
19
  *****************************************
23
20
  */
24
- function parse(content) {
25
- // 格式化内容
26
- content = (0, stripComments_1.stripComments)(content);
27
- // 打印输出
28
- // console.log(content);
29
- // 解析文件
30
- return content ? JSON.parse(content) : null;
21
+ function json(content) {
22
+ return JSON.parse(content);
31
23
  }
32
- exports.parse = parse;
33
- function jsonc(...args) {
34
- const [name, data] = args;
35
- // 读写数据
36
- if (args.length > 1) {
37
- (0, writeFile_1.writeFile)(name, JSON.stringify(data));
38
- }
39
- else {
40
- const stats = (0, stat_1.stat)(name);
41
- // 解析文件
42
- if (stats && stats.isFile()) {
43
- return parse((0, readFile_1.readFile)(stats.path));
44
- }
45
- }
46
- // 返回数据
47
- return data || null;
24
+ exports.json = json;
25
+ /**
26
+ *****************************************
27
+ * 解析 JSONC
28
+ *****************************************
29
+ */
30
+ function jsonc(content) {
31
+ return JSON.parse((0, stripComments_1.stripComments)(content));
48
32
  }
49
33
  exports.jsonc = jsonc;
50
- //# sourceMappingURL=jsonc.js.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ *****************************************
3
+ * 查找选项
4
+ *****************************************
5
+ */
6
+ interface Options<T> {
7
+ from?: string;
8
+ cache?: Map<string, T>;
9
+ extensions?: string[];
10
+ readFile?(path: string): T;
11
+ }
12
+ /**
13
+ *****************************************
14
+ * 向上查找
15
+ *****************************************
16
+ */
17
+ export declare function lookup<T = string>(name: string, options?: Options<T>): T | undefined;
18
+ export {};
package/dist/lookup.js ADDED
@@ -0,0 +1,64 @@
1
+ /**
2
+ *****************************************
3
+ * Created by edonet@163.com
4
+ * Created on 2023-12-31 10:38:51
5
+ *****************************************
6
+ */
7
+ 'use strict';
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.lookup = void 0;
10
+ /**
11
+ *****************************************
12
+ * 加载依赖
13
+ *****************************************
14
+ */
15
+ const node_path_1 = require("node:path");
16
+ const resolveFile_1 = require("./resolveFile");
17
+ /**
18
+ *****************************************
19
+ * 向上查找
20
+ *****************************************
21
+ */
22
+ function lookup(name, options = {}) {
23
+ const from = options.from ? (0, node_path_1.resolve)(options.from) : process.cwd();
24
+ // 解析目标
25
+ return resolveDir(from, name, options);
26
+ }
27
+ exports.lookup = lookup;
28
+ /**
29
+ *****************************************
30
+ * 解析目录文件
31
+ *****************************************
32
+ */
33
+ function resolveDir(from, name, options) {
34
+ const { cache, extensions, readFile } = options;
35
+ const id = (0, node_path_1.resolve)(from, name);
36
+ // 存在缓存
37
+ if (cache && cache.has(id)) {
38
+ return cache.get(id);
39
+ }
40
+ // 获取文件状态
41
+ const path = (0, resolveFile_1.resolveFile)(id, extensions);
42
+ // 加载配置
43
+ const result = path ?
44
+ readFile ? readFile(path) : path :
45
+ resolveParent(from, name, options);
46
+ // 添加缓存
47
+ cache && cache.set(id, result);
48
+ // 返回配置
49
+ return result;
50
+ }
51
+ /**
52
+ *****************************************
53
+ * 加载配置
54
+ *****************************************
55
+ */
56
+ function resolveParent(from, name, options) {
57
+ const parent = (0, node_path_1.dirname)(from);
58
+ // 到达根目录
59
+ if (parent === from) {
60
+ return;
61
+ }
62
+ // 加载配置
63
+ return resolveDir(parent, name, options);
64
+ }
@@ -1,30 +1,6 @@
1
- /**
2
- *****************************************
3
- * 编码类型
4
- *****************************************
5
- */
6
- declare type Encoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'latin1' | 'binary' | 'hex';
7
- /**
8
- *****************************************
9
- * 配置
10
- *****************************************
11
- */
12
- interface Options {
13
- encoding?: Encoding;
14
- flag?: string;
15
- }
16
1
  /**
17
2
  *****************************************
18
3
  * 读取文件
19
4
  *****************************************
20
5
  */
21
- declare function readFile(path: string): string;
22
- declare function readFile(path: string, encoding: Encoding): string;
23
- declare function readFile(path: string, options: Options): string;
24
- /**
25
- *****************************************
26
- *
27
- *****************************************
28
- */
29
- export { readFile };
30
- //# sourceMappingURL=readFile.d.ts.map
6
+ export declare function readFile(path: string): string;
package/dist/readFile.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  *****************************************
3
3
  * Created by edonet@163.com
4
- * Created on 2019-11-07 16:27:01
4
+ * Created on 2023-12-31 10:20:08
5
5
  *****************************************
6
6
  */
7
7
  'use strict';
@@ -12,16 +12,13 @@ exports.readFile = void 0;
12
12
  * 加载依赖
13
13
  *****************************************
14
14
  */
15
- const fs = require("fs");
16
- const stat_1 = require("./stat");
17
- function readFile(path, encoding) {
18
- let stats = (0, stat_1.stat)(path);
19
- // 存在文件
20
- if (stats && !stats.isDirectory()) {
21
- return fs.readFileSync(path, encoding || 'utf8');
22
- }
23
- // 返回空
24
- return '';
15
+ const node_fs_1 = require("node:fs");
16
+ /**
17
+ *****************************************
18
+ * 读取文件
19
+ *****************************************
20
+ */
21
+ function readFile(path) {
22
+ return (0, node_fs_1.readFileSync)(path, 'utf8');
25
23
  }
26
24
  exports.readFile = readFile;
27
- //# sourceMappingURL=readFile.js.map
@@ -1,7 +1,18 @@
1
+ /**
2
+ *****************************************
3
+ * 判断是否为相对路径
4
+ *****************************************
5
+ */
6
+ export declare function isRelative(id: string): boolean;
7
+ /**
8
+ *****************************************
9
+ * 获取相对路径
10
+ *****************************************
11
+ */
12
+ export declare const relativeFrom: (from: string, to: string) => string;
1
13
  /**
2
14
  *****************************************
3
15
  * 获取相对路径
4
16
  *****************************************
5
17
  */
6
18
  export declare function relative(from: string, to: string): string;
7
- //# sourceMappingURL=relative.d.ts.map
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.relative = exports.relativeFrom = exports.isRelative = void 0;
10
+ /**
11
+ *****************************************
12
+ * 加载依赖
13
+ *****************************************
14
+ */
15
+ const node_path_1 = require("node:path");
16
+ /**
17
+ *****************************************
18
+ * 判断是否为相对路径
19
+ *****************************************
20
+ */
21
+ function isRelative(id) {
22
+ // 判断是否以 '.' 开头
23
+ if (id.charAt(0) !== '.') {
24
+ return false;
25
+ }
26
+ // 获取字符
27
+ const c1 = id.charAt(1);
28
+ // 以 './' 开头
29
+ if (c1 === '/' || c1 === '') {
30
+ return true;
31
+ }
32
+ else if (c1 !== '.') {
33
+ return false;
34
+ }
35
+ // 获取下一字符
36
+ const c2 = id.charAt(2);
37
+ // 判断以
38
+ return c2 === '/' || c2 === '';
39
+ }
40
+ exports.isRelative = isRelative;
10
41
  /**
11
42
  *****************************************
12
43
  * 获取相对路径
13
44
  *****************************************
14
45
  */
15
- const path = require("path");
46
+ exports.relativeFrom = node_path_1.sep === '/'
47
+ ? node_path_1.relative
48
+ : function relativeFrom(from, to) {
49
+ return (0, node_path_1.relative)(from, to).replace(/\\/g, '/');
50
+ };
16
51
  /**
17
52
  *****************************************
18
53
  * 获取相对路径
19
54
  *****************************************
20
55
  */
21
56
  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;
57
+ const result = (0, exports.relativeFrom)(from, to);
58
+ // 当前路径
59
+ if (!result) {
60
+ return './';
30
61
  }
31
- // 纯目录
32
- if (['..', '.'].includes(result) || result.endsWith('/..')) {
62
+ // 样式化路径
63
+ if (result === '.' || result === '..' || result.endsWith('/..')) {
33
64
  return result + '/';
34
65
  }
35
- // 返回结果
36
- return result;
66
+ else {
67
+ return result.charAt(0) === '.' ? result : './' + result;
68
+ }
37
69
  }
38
70
  exports.relative = relative;
39
- //# sourceMappingURL=relative.js.map