@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.
- package/LICENSE +1 -1
- package/README.md +18 -42
- package/dist/findUp.d.ts +6 -0
- package/dist/findUp.js +35 -0
- package/dist/index.d.ts +7 -38
- package/dist/index.js +21 -80
- package/dist/jsonc.d.ts +4 -20
- package/dist/jsonc.js +14 -32
- package/dist/lookup.d.ts +18 -0
- package/dist/lookup.js +63 -0
- package/dist/readFile.d.ts +1 -25
- package/dist/readFile.js +10 -14
- package/dist/relative.d.ts +12 -1
- package/dist/relative.js +48 -17
- package/dist/resolveFile.d.ts +6 -0
- package/dist/resolveFile.js +40 -0
- package/dist/{extname.d.ts → rm.d.ts} +2 -3
- package/dist/{isDirectory.js → rm.js} +16 -9
- package/dist/stat.d.ts +1 -17
- package/dist/stat.js +5 -13
- package/dist/{helpers → utils}/stripComments.d.ts +1 -2
- package/dist/utils/stripComments.js +120 -0
- package/package.json +33 -30
- package/bin/clean.js +0 -45
- package/bin/cli.js +0 -42
- package/bin/git.js +0 -40
- package/bin/run.js +0 -41
- package/dist/basename.d.ts +0 -7
- package/dist/basename.d.ts.map +0 -1
- package/dist/basename.js +0 -17
- package/dist/basename.js.map +0 -1
- package/dist/copy.d.ts +0 -41
- package/dist/copy.d.ts.map +0 -1
- package/dist/copy.js +0 -90
- package/dist/copy.js.map +0 -1
- package/dist/cpdir.d.ts +0 -20
- package/dist/cpdir.d.ts.map +0 -1
- package/dist/cpdir.js +0 -29
- package/dist/cpdir.js.map +0 -1
- package/dist/cwd.d.ts +0 -7
- package/dist/cwd.d.ts.map +0 -1
- package/dist/cwd.js +0 -17
- package/dist/cwd.js.map +0 -1
- package/dist/dirname.d.ts +0 -7
- package/dist/dirname.d.ts.map +0 -1
- package/dist/dirname.js +0 -31
- package/dist/dirname.js.map +0 -1
- package/dist/extname.d.ts.map +0 -1
- package/dist/extname.js +0 -17
- package/dist/extname.js.map +0 -1
- package/dist/filename.d.ts +0 -7
- package/dist/filename.d.ts.map +0 -1
- package/dist/filename.js +0 -25
- package/dist/filename.js.map +0 -1
- package/dist/find.d.ts +0 -27
- package/dist/find.d.ts.map +0 -1
- package/dist/find.js +0 -73
- package/dist/find.js.map +0 -1
- package/dist/findFile.d.ts +0 -21
- package/dist/findFile.d.ts.map +0 -1
- package/dist/findFile.js +0 -40
- package/dist/findFile.js.map +0 -1
- package/dist/finddir.d.ts +0 -21
- package/dist/finddir.d.ts.map +0 -1
- package/dist/finddir.js +0 -40
- package/dist/finddir.js.map +0 -1
- package/dist/helpers/FileResolver.d.ts +0 -54
- package/dist/helpers/FileResolver.d.ts.map +0 -1
- package/dist/helpers/FileResolver.js +0 -184
- package/dist/helpers/FileResolver.js.map +0 -1
- package/dist/helpers/compose.d.ts +0 -14
- package/dist/helpers/compose.d.ts.map +0 -1
- package/dist/helpers/compose.js +0 -38
- package/dist/helpers/compose.js.map +0 -1
- package/dist/helpers/each.d.ts +0 -7
- package/dist/helpers/each.d.ts.map +0 -1
- package/dist/helpers/each.js +0 -21
- package/dist/helpers/each.js.map +0 -1
- package/dist/helpers/match.d.ts +0 -7
- package/dist/helpers/match.d.ts.map +0 -1
- package/dist/helpers/match.js +0 -30
- package/dist/helpers/match.js.map +0 -1
- package/dist/helpers/normalizePath.d.ts +0 -23
- package/dist/helpers/normalizePath.d.ts.map +0 -1
- package/dist/helpers/normalizePath.js +0 -37
- package/dist/helpers/normalizePath.js.map +0 -1
- package/dist/helpers/safeCall.d.ts +0 -7
- package/dist/helpers/safeCall.d.ts.map +0 -1
- package/dist/helpers/safeCall.js +0 -24
- package/dist/helpers/safeCall.js.map +0 -1
- package/dist/helpers/split.d.ts +0 -7
- package/dist/helpers/split.d.ts.map +0 -1
- package/dist/helpers/split.js +0 -25
- package/dist/helpers/split.js.map +0 -1
- package/dist/helpers/stripBOM.d.ts +0 -7
- package/dist/helpers/stripBOM.d.ts.map +0 -1
- package/dist/helpers/stripBOM.js +0 -19
- package/dist/helpers/stripBOM.js.map +0 -1
- package/dist/helpers/stripComments.d.ts.map +0 -1
- package/dist/helpers/stripComments.js +0 -147
- package/dist/helpers/stripComments.js.map +0 -1
- package/dist/homedir.d.ts +0 -7
- package/dist/homedir.d.ts.map +0 -1
- package/dist/homedir.js +0 -32
- package/dist/homedir.js.map +0 -1
- package/dist/includePaths.d.ts +0 -7
- package/dist/includePaths.d.ts.map +0 -1
- package/dist/includePaths.js +0 -54
- package/dist/includePaths.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/indir.d.ts +0 -14
- package/dist/indir.d.ts.map +0 -1
- package/dist/indir.js +0 -27
- package/dist/indir.js.map +0 -1
- package/dist/isAbsolutePath.d.ts +0 -7
- package/dist/isAbsolutePath.d.ts.map +0 -1
- package/dist/isAbsolutePath.js +0 -25
- package/dist/isAbsolutePath.js.map +0 -1
- package/dist/isDirectory.d.ts +0 -13
- package/dist/isDirectory.d.ts.map +0 -1
- package/dist/isDirectory.js.map +0 -1
- package/dist/isRelativePath.d.ts +0 -7
- package/dist/isRelativePath.d.ts.map +0 -1
- package/dist/isRelativePath.js +0 -45
- package/dist/isRelativePath.js.map +0 -1
- package/dist/json.d.ts +0 -22
- package/dist/json.d.ts.map +0 -1
- package/dist/json.js +0 -35
- package/dist/json.js.map +0 -1
- package/dist/jsonc.d.ts.map +0 -1
- package/dist/jsonc.js.map +0 -1
- package/dist/lstat.d.ts +0 -23
- package/dist/lstat.d.ts.map +0 -1
- package/dist/lstat.js +0 -31
- package/dist/lstat.js.map +0 -1
- package/dist/mapdir.d.ts +0 -23
- package/dist/mapdir.d.ts.map +0 -1
- package/dist/mapdir.js +0 -43
- package/dist/mapdir.js.map +0 -1
- package/dist/mkdir.d.ts +0 -7
- package/dist/mkdir.d.ts.map +0 -1
- package/dist/mkdir.js +0 -38
- package/dist/mkdir.js.map +0 -1
- package/dist/parseJSON.d.ts +0 -16
- package/dist/parseJSON.d.ts.map +0 -1
- package/dist/parseJSON.js +0 -29
- package/dist/parseJSON.js.map +0 -1
- package/dist/readFile.d.ts.map +0 -1
- package/dist/readFile.js.map +0 -1
- package/dist/readStream.d.ts +0 -37
- package/dist/readStream.d.ts.map +0 -1
- package/dist/readStream.js +0 -20
- package/dist/readStream.js.map +0 -1
- package/dist/readdir.d.ts +0 -17
- package/dist/readdir.d.ts.map +0 -1
- package/dist/readdir.js +0 -35
- package/dist/readdir.js.map +0 -1
- package/dist/readline.d.ts +0 -17
- package/dist/readline.d.ts.map +0 -1
- package/dist/readline.js +0 -25
- package/dist/readline.js.map +0 -1
- package/dist/realpath.d.ts +0 -13
- package/dist/realpath.d.ts.map +0 -1
- package/dist/realpath.js +0 -33
- package/dist/realpath.js.map +0 -1
- package/dist/relative.d.ts.map +0 -1
- package/dist/relative.js.map +0 -1
- package/dist/resolve.d.ts +0 -27
- package/dist/resolve.d.ts.map +0 -1
- package/dist/resolve.js +0 -54
- package/dist/resolve.js.map +0 -1
- package/dist/resolvePath.d.ts +0 -27
- package/dist/resolvePath.d.ts.map +0 -1
- package/dist/resolvePath.js +0 -178
- package/dist/resolvePath.js.map +0 -1
- package/dist/rmdir.d.ts +0 -7
- package/dist/rmdir.d.ts.map +0 -1
- package/dist/rmdir.js +0 -41
- package/dist/rmdir.js.map +0 -1
- package/dist/stat.d.ts.map +0 -1
- package/dist/stat.js.map +0 -1
- package/dist/supdir.d.ts +0 -22
- package/dist/supdir.d.ts.map +0 -1
- package/dist/supdir.js +0 -63
- package/dist/supdir.js.map +0 -1
- package/dist/symlink.d.ts +0 -23
- package/dist/symlink.d.ts.map +0 -1
- package/dist/symlink.js +0 -40
- package/dist/symlink.js.map +0 -1
- package/dist/unlink.d.ts +0 -7
- package/dist/unlink.d.ts.map +0 -1
- package/dist/unlink.js +0 -29
- package/dist/unlink.js.map +0 -1
- package/dist/usedir.d.ts +0 -7
- package/dist/usedir.d.ts.map +0 -1
- package/dist/usedir.js +0 -25
- package/dist/usedir.js.map +0 -1
- package/dist/writeFile.d.ts +0 -34
- package/dist/writeFile.d.ts.map +0 -1
- package/dist/writeFile.js +0 -50
- package/dist/writeFile.js.map +0 -1
- package/dist/writeStream.d.ts +0 -36
- package/dist/writeStream.d.ts.map +0 -1
- package/dist/writeStream.js +0 -20
- package/dist/writeStream.js.map +0 -1
- package/src/basename.ts +0 -15
- package/src/copy.ts +0 -141
- package/src/cpdir.ts +0 -47
- package/src/cwd.ts +0 -15
- package/src/dirname.ts +0 -34
- package/src/extname.ts +0 -15
- package/src/filename.ts +0 -25
- package/src/find.ts +0 -106
- package/src/findFile.ts +0 -61
- package/src/finddir.ts +0 -61
- package/src/helpers/FileResolver.ts +0 -282
- package/src/helpers/compose.ts +0 -49
- package/src/helpers/each.ts +0 -19
- package/src/helpers/match.ts +0 -31
- package/src/helpers/normalizePath.ts +0 -51
- package/src/helpers/safeCall.ts +0 -21
- package/src/helpers/split.ts +0 -25
- package/src/helpers/stripBOM.ts +0 -17
- package/src/helpers/stripComments.ts +0 -173
- package/src/homedir.ts +0 -34
- package/src/includePaths.ts +0 -62
- package/src/index.ts +0 -52
- package/src/indir.ts +0 -45
- package/src/isAbsolutePath.ts +0 -25
- package/src/isDirectory.ts +0 -28
- package/src/isRelativePath.ts +0 -52
- package/src/json.ts +0 -62
- package/src/jsonc.ts +0 -81
- package/src/lstat.ts +0 -40
- package/src/mapdir.ts +0 -59
- package/src/mkdir.ts +0 -43
- package/src/parseJSON.ts +0 -40
- package/src/readFile.ts +0 -64
- package/src/readStream.ts +0 -53
- package/src/readdir.ts +0 -51
- package/src/readline.ts +0 -42
- package/src/realpath.ts +0 -35
- package/src/relative.ts +0 -43
- package/src/resolve.ts +0 -83
- package/src/resolvePath.ts +0 -234
- package/src/rmdir.ts +0 -44
- package/src/stat.ts +0 -40
- package/src/supdir.ts +0 -79
- package/src/symlink.ts +0 -67
- package/src/unlink.ts +0 -31
- package/src/usedir.ts +0 -25
- package/src/writeFile.ts +0 -86
- 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
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
23
|
-
//
|
|
24
|
-
if (
|
|
25
|
-
|
|
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 (
|
|
63
|
+
// 样式化路径
|
|
64
|
+
if (result === '.' || result === '..' || result.endsWith('/..')) {
|
|
33
65
|
return result + '/';
|
|
34
66
|
}
|
|
35
|
-
|
|
36
|
-
|
|
67
|
+
else {
|
|
68
|
+
return result.charAt(0) === '.' ? result : './' + result;
|
|
69
|
+
}
|
|
37
70
|
}
|
|
38
|
-
exports.relative = relative;
|
|
39
|
-
//# sourceMappingURL=relative.js.map
|
|
@@ -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,27 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
2
|
*****************************************
|
|
3
3
|
* Created by edonet@163.com
|
|
4
|
-
* Created on
|
|
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.
|
|
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
|
|
22
|
-
const stats = (0, stat_1.stat)(
|
|
23
|
-
//
|
|
24
|
-
|
|
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(
|
|
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
|
|
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 =
|
|
9
|
+
exports.stat = stat;
|
|
10
10
|
/**
|
|
11
11
|
*****************************************
|
|
12
12
|
* 加载依赖
|
|
13
13
|
*****************************************
|
|
14
14
|
*/
|
|
15
|
-
const
|
|
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(
|
|
23
|
-
|
|
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
|
|
@@ -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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
package/dist/basename.d.ts
DELETED
package/dist/basename.d.ts.map
DELETED
|
@@ -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
|
package/dist/basename.js.map
DELETED
|
@@ -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"}
|