@zwa73/dev-utils 1.0.88 → 1.0.90
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/bin/cli +1 -1
- package/data/template/base/package.json +7 -6
- package/data/template/base/scripts/compile.ps1 +25 -8
- package/data/template/base/scripts/release.ps1 +5 -2
- package/data/template/base/tsconfig.json +3 -5
- package/data/template/base/tsup.config.js +35 -0
- package/data/template/cjs/gitignore +3 -0
- package/data/template/cjs/package.json +19 -0
- package/data/template/cjs/scripts/compile.ps1 +13 -0
- package/data/template/cjs/scripts/expand-macro.ps1 +2 -0
- package/data/template/cjs/scripts/release.ps1 +8 -0
- package/data/template/cjs/scripts/watch.ps1 +10 -0
- package/data/template/cjs/src/index.ts +0 -0
- package/data/template/cjs/src/macro.macro.ts +6 -0
- package/data/template/cjs/tsconfig.compile.json +12 -0
- package/data/template/cjs/tsconfig.json +21 -0
- package/data/template/electron/package.json +25 -25
- package/dist/Command/Bump.d.ts +6 -0
- package/dist/Command/Bump.js +70 -0
- package/dist/Command/CheckToken.d.ts +10 -0
- package/dist/Command/CheckToken.js +52 -0
- package/dist/{mjs/Command → Command}/ExpandMacro.d.ts +1 -1
- package/dist/{cjs/Command → Command}/GenI18n.d.ts +1 -1
- package/dist/{cjs/Command → Command}/GenI18n.js +20 -12
- package/dist/{cjs/Command → Command}/GenSchema.d.ts +1 -1
- package/dist/{cjs/Command → Command}/GenTemplate.d.ts +1 -1
- package/dist/{cjs/Command → Command}/GenTemplate.js +9 -6
- package/dist/{cjs/Command → Command}/MapPath.d.ts +1 -1
- package/dist/Command/MapPath.js +115 -0
- package/dist/{cjs/Command → Command}/Node.d.ts +1 -1
- package/dist/{cjs/Command → Command}/Node.js +1 -1
- package/dist/{cjs/Command → Command}/Release.d.ts +1 -1
- package/dist/{cjs/Command → Command}/Release.js +9 -45
- package/dist/{cjs/Command → Command}/Route.js +7 -5
- package/dist/{cjs/Command → Command}/ScanDups.d.ts +1 -1
- package/dist/{cjs/Command → Command}/ScanDups.js +15 -13
- package/dist/DynImport.d.ts +15 -0
- package/dist/DynImport.js +15 -0
- package/dist/{mjs/UtilAst.d.ts → UtilAst.d.ts} +2 -2
- package/dist/{mjs/UtilDevTool.d.ts → UtilDevTool.d.ts} +1 -1
- package/dist/{cjs/UtilDevTool.js → UtilDevTool.js} +21 -38
- package/dist/UtilInterface.d.ts +8 -0
- package/dist/UtilMacro.d.ts +7 -0
- package/dist/{cjs/UtilMacro.js → UtilMacro.js} +4 -4
- package/package.json +2 -10
- package/data/template/base/tsconfig.cjs.json +0 -8
- package/data/template/base/tsconfig.mjs.json +0 -9
- package/dist/cjs/Command/ExpandMacro.d.ts +0 -3
- package/dist/cjs/Command/MapPath.js +0 -80
- package/dist/cjs/UtilAst.d.ts +0 -13
- package/dist/cjs/UtilDevTool.d.ts +0 -99
- package/dist/cjs/UtilInterface.d.ts +0 -4
- package/dist/cjs/UtilMacro.d.ts +0 -7
- package/dist/cjs/test/testFileMacro.d.ts +0 -1
- package/dist/cjs/test/testFileMacro.js +0 -1
- package/dist/cjs/test/testGlobMacro.d.ts +0 -1
- package/dist/cjs/test/testGlobMacro.js +0 -2
- package/dist/cjs/test/testRegex.d.ts +0 -1
- package/dist/cjs/test/testRegex.js +0 -3
- package/dist/cjs/test/testRegexa.d.ts +0 -1
- package/dist/cjs/test/testRegexa.js +0 -1
- package/dist/mjs/Command/ExpandMacro.js +0 -16
- package/dist/mjs/Command/GenI18n.d.ts +0 -3
- package/dist/mjs/Command/GenI18n.js +0 -75
- package/dist/mjs/Command/GenSchema.d.ts +0 -3
- package/dist/mjs/Command/GenSchema.js +0 -22
- package/dist/mjs/Command/GenTemplate.d.ts +0 -3
- package/dist/mjs/Command/GenTemplate.js +0 -61
- package/dist/mjs/Command/MapPath.d.ts +0 -3
- package/dist/mjs/Command/MapPath.js +0 -73
- package/dist/mjs/Command/Node.d.ts +0 -3
- package/dist/mjs/Command/Node.js +0 -14
- package/dist/mjs/Command/Release.d.ts +0 -3
- package/dist/mjs/Command/Release.js +0 -90
- package/dist/mjs/Command/Route.d.ts +0 -1
- package/dist/mjs/Command/Route.js +0 -20
- package/dist/mjs/Command/RouteInterface.d.ts +0 -24
- package/dist/mjs/Command/RouteInterface.js +0 -58
- package/dist/mjs/Command/ScanDups.d.ts +0 -3
- package/dist/mjs/Command/ScanDups.js +0 -114
- package/dist/mjs/Command/index.d.ts +0 -1
- package/dist/mjs/Command/index.js +0 -1
- package/dist/mjs/QuickFunc.d.ts +0 -2
- package/dist/mjs/QuickFunc.js +0 -2
- package/dist/mjs/UtilAst.js +0 -15
- package/dist/mjs/UtilDevTool.js +0 -297
- package/dist/mjs/UtilInterface.d.ts +0 -4
- package/dist/mjs/UtilInterface.js +0 -1
- package/dist/mjs/UtilMacro.d.ts +0 -7
- package/dist/mjs/UtilMacro.js +0 -23
- package/dist/mjs/index.d.ts +0 -5
- package/dist/mjs/index.js +0 -5
- package/dist/mjs/test/testFileMacro.d.ts +0 -1
- package/dist/mjs/test/testFileMacro.js +0 -1
- package/dist/mjs/test/testGlobMacro.d.ts +0 -1
- package/dist/mjs/test/testGlobMacro.js +0 -2
- package/dist/mjs/test/testRegex.d.ts +0 -1
- package/dist/mjs/test/testRegex.js +0 -2
- package/dist/mjs/test/testRegexa.d.ts +0 -1
- package/dist/mjs/test/testRegexa.js +0 -1
- package/dist/{cjs/Command → Command}/ExpandMacro.js +0 -0
- package/dist/{cjs/Command → Command}/GenSchema.js +0 -0
- package/dist/{cjs/Command → Command}/Route.d.ts +0 -0
- package/dist/{cjs/Command → Command}/RouteInterface.d.ts +0 -0
- package/dist/{cjs/Command → Command}/RouteInterface.js +1 -1
- /package/dist/{cjs/Command → Command}/index.d.ts +0 -0
- /package/dist/{cjs/Command → Command}/index.js +0 -0
- /package/dist/{cjs/QuickFunc.d.ts → QuickFunc.d.ts} +0 -0
- /package/dist/{cjs/QuickFunc.js → QuickFunc.js} +0 -0
- /package/dist/{cjs/UtilAst.js → UtilAst.js} +0 -0
- /package/dist/{cjs/UtilInterface.js → UtilInterface.js} +0 -0
- /package/dist/{cjs/index.d.ts → index.d.ts} +0 -0
- /package/dist/{cjs/index.js → index.js} +0 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CmdMapPath = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const utils_1 = require("@zwa73/utils");
|
|
9
|
+
const pathe_1 = __importDefault(require("pathe"));
|
|
10
|
+
const DupMethodList = ["skip", "overwrite", "rename"];
|
|
11
|
+
/**重命名文件或路径 */
|
|
12
|
+
const CmdMapPath = (program) => program
|
|
13
|
+
.command("Map-Path")
|
|
14
|
+
.alias("mappath")
|
|
15
|
+
.description(`根据正则表达式对文件名进行映射`)
|
|
16
|
+
.argument("<regex>", "要匹配的正则表达式, posix风格路径")
|
|
17
|
+
.argument("<replacement>", "替换字符串")
|
|
18
|
+
.option("-e, --exclude <regex>", "排除文件的正则表达式")
|
|
19
|
+
.option(`-d, --duplicate-handling <${DupMethodList.join('|')}>`, `处理重名文件的方式:
|
|
20
|
+
skip 不进行处理
|
|
21
|
+
overwrite 覆盖重名
|
|
22
|
+
rename 以 [name]_idx[.ext?] 的形式重命名`, "skip")
|
|
23
|
+
.option("-r, --recursive", "递归的处理子目录", false)
|
|
24
|
+
.option("-m, --move", "重命名而不是复制文件", false)
|
|
25
|
+
.option("-o, --output <path>", "输出到某个绝对路径而非当前目录", '')
|
|
26
|
+
.option("-i, --input <path>", "扫描某个绝对路径而非当前目录", '')
|
|
27
|
+
.option("-t, --test", "不对文件进行实际操作, 在控制台输出映射结果", false)
|
|
28
|
+
.option("-@, --extend", `使用@占位符扩展语法, 可用占位符:
|
|
29
|
+
@i 表示处理顺序下标 (从0开始)
|
|
30
|
+
@c 表示处理计数 (从1开始)
|
|
31
|
+
@name 表示文件名 (不含扩展名)
|
|
32
|
+
@ext 表示文件扩展名 (带.)
|
|
33
|
+
@base 表示文件名 (含扩展名)
|
|
34
|
+
@dir 表示文件所在目录的路径
|
|
35
|
+
@path[n] 获取路径中的第 n 段 (从 0 开始, 负数表示倒数)
|
|
36
|
+
@@ 表示对@的转义
|
|
37
|
+
exmaple:
|
|
38
|
+
match: "/data/archive/project/file.txt"
|
|
39
|
+
@name -> "file"
|
|
40
|
+
@ext -> ".txt"
|
|
41
|
+
@base -> "file.txt"
|
|
42
|
+
@dir -> "/data/archive/project"
|
|
43
|
+
@path[0] -> "data"
|
|
44
|
+
@path[-1] -> "file.txt"
|
|
45
|
+
@path[-2] -> "project"
|
|
46
|
+
`, false)
|
|
47
|
+
.action(async (regexStr, replacement, options) => {
|
|
48
|
+
const regex = new RegExp(regexStr);
|
|
49
|
+
const excludeRegex = options.exclude ? new RegExp(options.exclude) : null;
|
|
50
|
+
if (!DupMethodList.includes(options.duplicateHandling))
|
|
51
|
+
(0, utils_1.throwError)(`${options.duplicateHandling} 不是有效的 duplicate-handling`);
|
|
52
|
+
const duplicateHandling = options.duplicateHandling;
|
|
53
|
+
const searchPath = options.input.length > 0
|
|
54
|
+
? options.input : process.cwd();
|
|
55
|
+
const outPath = options.output.length > 0
|
|
56
|
+
? options.output : process.cwd();
|
|
57
|
+
// 遍历当前目录下的所有文件
|
|
58
|
+
const filePaths = (await utils_1.UtilFT.fileSearchRegex(searchPath, regex, { recursive: options.recursive }))
|
|
59
|
+
.map(fp => pathe_1.default.relative(searchPath, fp))
|
|
60
|
+
.filter(fp => excludeRegex ? (!excludeRegex.test(fp)) : true);
|
|
61
|
+
//对单个路径映射
|
|
62
|
+
const mapPath = async (source, target) => {
|
|
63
|
+
if (options.test)
|
|
64
|
+
return utils_1.SLogger.info(`${source} -> ${target}`);
|
|
65
|
+
const dir = pathe_1.default.parse(target).dir;
|
|
66
|
+
await utils_1.UtilFT.ensurePathExists(dir, { dir: true });
|
|
67
|
+
if (options.move)
|
|
68
|
+
return fs_1.default.promises.rename(source, target);
|
|
69
|
+
return fs_1.default.promises.copyFile(source, target);
|
|
70
|
+
};
|
|
71
|
+
// 先生成带编号的文件映射
|
|
72
|
+
const indexedFiles = filePaths.map((rawfilePath, idx) => {
|
|
73
|
+
const filePath = pathe_1.default.normalize(rawfilePath);
|
|
74
|
+
const segments = filePath.split(pathe_1.default.sep).filter(Boolean); // 提取路径片段
|
|
75
|
+
const replacedFilePath = filePath
|
|
76
|
+
.replace(regex, replacement); //替换
|
|
77
|
+
const processedFilePath = options.extend
|
|
78
|
+
? replacedFilePath
|
|
79
|
+
.replace(/(?<!@)@name/g, pathe_1.default.parse(filePath).name)
|
|
80
|
+
.replace(/(?<!@)@ext/g, pathe_1.default.parse(filePath).ext)
|
|
81
|
+
.replace(/(?<!@)@base/g, pathe_1.default.parse(filePath).base)
|
|
82
|
+
.replace(/(?<!@)@dir/g, pathe_1.default.dirname(filePath))
|
|
83
|
+
.replace(/(?<!@)@i/g, `${idx}`) //数字下标
|
|
84
|
+
.replace(/(?<!@)@c/g, `${idx + 1}`)
|
|
85
|
+
.replace(/(?<!@)@path\[(\-?\d+)\]/g, (_, rawIndex) => {
|
|
86
|
+
const index = Number(rawIndex);
|
|
87
|
+
const resolved = index < 0
|
|
88
|
+
? segments[segments.length + index]
|
|
89
|
+
: segments[index];
|
|
90
|
+
return resolved ?? '';
|
|
91
|
+
})
|
|
92
|
+
.replace(/@@/g, `@`) //转义
|
|
93
|
+
: replacedFilePath;
|
|
94
|
+
return {
|
|
95
|
+
idx,
|
|
96
|
+
oldFilePath: pathe_1.default.join(searchPath, filePath),
|
|
97
|
+
newFilePath: pathe_1.default.join(outPath, processedFilePath),
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
await Promise.all(indexedFiles.map(async ({ idx, oldFilePath, newFilePath, }) => {
|
|
101
|
+
// 如果文件名无变化则不操作
|
|
102
|
+
if (newFilePath === oldFilePath)
|
|
103
|
+
return;
|
|
104
|
+
//如果文件已存在
|
|
105
|
+
if (await utils_1.UtilFT.pathExists(newFilePath))
|
|
106
|
+
return (0, utils_1.match)(duplicateHandling, {
|
|
107
|
+
'skip': () => utils_1.SLogger.info(`重名文件存在,跳过:${newFilePath}`),
|
|
108
|
+
'overwrite': async () => mapPath(oldFilePath, newFilePath),
|
|
109
|
+
'rename': async () => mapPath(oldFilePath, newFilePath.replace(/((\.[^/.]+)?$)/, `_${idx}$1`)),
|
|
110
|
+
});
|
|
111
|
+
//如果文件不存在, 直接映射
|
|
112
|
+
return mapPath(oldFilePath, newFilePath);
|
|
113
|
+
}));
|
|
114
|
+
});
|
|
115
|
+
exports.CmdMapPath = CmdMapPath;
|
|
@@ -13,6 +13,6 @@ const CmdNode = (program) => program
|
|
|
13
13
|
let cmd = `ts-node -r tsconfig-paths/register ${arg}`;
|
|
14
14
|
if (opt.project)
|
|
15
15
|
cmd += ` -P ${opt.project}`;
|
|
16
|
-
await utils_1.UtilFunc.exec(cmd, { outlvl:
|
|
16
|
+
await utils_1.UtilFunc.exec(cmd, { outlvl: console.info, errlvl: console.error });
|
|
17
17
|
});
|
|
18
18
|
exports.CmdNode = CmdNode;
|
|
@@ -4,50 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.CmdRelease = void 0;
|
|
7
|
-
const
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const utils_1 = require("@zwa73/utils");
|
|
9
|
+
const pathe_1 = __importDefault(require("pathe"));
|
|
10
|
+
const Bump_1 = require("./Bump");
|
|
11
|
+
const CheckToken_1 = require("./CheckToken");
|
|
9
12
|
const RouteInterface_1 = require("./RouteInterface");
|
|
10
|
-
const fs_1 = __importDefault(require("fs"));
|
|
11
|
-
/**解析版本号为number数组 */
|
|
12
|
-
function parseVersion(version) {
|
|
13
|
-
const arr = version.split(".").map(Number);
|
|
14
|
-
if (arr.length !== 3)
|
|
15
|
-
(0, utils_1.throwError)(`${version} 不是有效的版本号`, 'error');
|
|
16
|
-
for (let i = 0; i < 3; i++) {
|
|
17
|
-
if (!isFinite(arr[i]))
|
|
18
|
-
(0, utils_1.throwError)(`${version} 不是有效的版本号`, 'error');
|
|
19
|
-
}
|
|
20
|
-
return arr;
|
|
21
|
-
}
|
|
22
|
-
/**判断版本号是否有效 */
|
|
23
|
-
function checkVersion(oldVersion, newVersion) {
|
|
24
|
-
const oldParts = parseVersion(oldVersion);
|
|
25
|
-
const newParts = parseVersion(newVersion);
|
|
26
|
-
for (let i = 0; i < 3; i++) {
|
|
27
|
-
if (newParts[i] < oldParts[i])
|
|
28
|
-
(0, utils_1.throwError)(`${newVersion} 低于当前版本号 ${oldVersion}`, 'error');
|
|
29
|
-
if (newParts[i] > oldParts[i])
|
|
30
|
-
break;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/**更新版本号 */
|
|
34
|
-
async function updateVersion(newVersion) {
|
|
35
|
-
const packagePath = pathe_1.default.join(RouteInterface_1.PROCESS_PATH, "package.json");
|
|
36
|
-
const packageData = await (0, utils_1.memoize)(utils_1.UtilFT.loadJSONFile)(packagePath);
|
|
37
|
-
if (newVersion == 'current')
|
|
38
|
-
return packageData.version;
|
|
39
|
-
if (newVersion) {
|
|
40
|
-
checkVersion(packageData.version, newVersion);
|
|
41
|
-
packageData.version = newVersion;
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
const version = packageData.version.split(".");
|
|
45
|
-
version[2] = (parseInt(version[2]) + 1).toString();
|
|
46
|
-
packageData.version = version.join(".");
|
|
47
|
-
}
|
|
48
|
-
await utils_1.UtilFT.writeJSONFile(packagePath, packageData);
|
|
49
|
-
return packageData.version;
|
|
50
|
-
}
|
|
51
13
|
/**获取包名 */
|
|
52
14
|
async function getPackName() {
|
|
53
15
|
const packagePath = pathe_1.default.join(RouteInterface_1.PROCESS_PATH, "package.json");
|
|
@@ -65,11 +27,10 @@ const CmdRelease = (program) => program
|
|
|
65
27
|
.option("-a, --access <access>", "npm publish 的 access 参数 默认 public", "public")
|
|
66
28
|
.option("-l, --local <path>", "仅打包到本地对印目录下 如./build/", undefined)
|
|
67
29
|
.action(async (opt) => {
|
|
68
|
-
(0,
|
|
30
|
+
await (0, Bump_1.bump)(opt);
|
|
69
31
|
utils_1.SLogger.info(`开始发布项目`);
|
|
70
32
|
try {
|
|
71
|
-
const
|
|
72
|
-
utils_1.SLogger.info(`新版本号: ${newVersion}`);
|
|
33
|
+
const chkPromise = (0, CheckToken_1.checkNpmToken)({ loglvl: 'none' });
|
|
73
34
|
if (opt.local) {
|
|
74
35
|
utils_1.SLogger.info("正在打包...");
|
|
75
36
|
const fullpath = pathe_1.default.join(process.cwd(), opt.local);
|
|
@@ -89,6 +50,9 @@ const CmdRelease = (program) => program
|
|
|
89
50
|
const cmd = `npm publish --registry ${RouteInterface_1.OFFICIAL_SOURCE} --access ${opt.access}`;
|
|
90
51
|
await utils_1.UtilFunc.exec(cmd, { errlvl: 'info' });
|
|
91
52
|
utils_1.SLogger.info("发布完成");
|
|
53
|
+
const chkResult = await chkPromise;
|
|
54
|
+
if (chkResult)
|
|
55
|
+
utils_1.SLogger.warn(chkResult);
|
|
92
56
|
}
|
|
93
57
|
catch (error) {
|
|
94
58
|
utils_1.SLogger.error(error);
|
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cliRoute = cliRoute;
|
|
4
4
|
const commander_1 = require("commander");
|
|
5
|
-
const
|
|
6
|
-
const Release_1 = require("./Release");
|
|
7
|
-
const MapPath_1 = require("./MapPath");
|
|
8
|
-
const ScanDups_1 = require("./ScanDups");
|
|
9
|
-
const GenSchema_1 = require("./GenSchema");
|
|
5
|
+
const CheckToken_1 = require("./CheckToken");
|
|
10
6
|
const ExpandMacro_1 = require("./ExpandMacro");
|
|
11
7
|
const GenI18n_1 = require("./GenI18n");
|
|
8
|
+
const GenSchema_1 = require("./GenSchema");
|
|
12
9
|
const GenTemplate_1 = require("./GenTemplate");
|
|
10
|
+
const MapPath_1 = require("./MapPath");
|
|
11
|
+
const Node_1 = require("./Node");
|
|
12
|
+
const Release_1 = require("./Release");
|
|
13
|
+
const ScanDups_1 = require("./ScanDups");
|
|
13
14
|
async function cliRoute() {
|
|
14
15
|
(0, Node_1.CmdNode)(commander_1.program);
|
|
15
16
|
(0, Release_1.CmdRelease)(commander_1.program);
|
|
@@ -19,5 +20,6 @@ async function cliRoute() {
|
|
|
19
20
|
(0, ExpandMacro_1.CmdExpandMacro)(commander_1.program);
|
|
20
21
|
(0, GenI18n_1.CmdGenI18n)(commander_1.program);
|
|
21
22
|
(0, GenTemplate_1.CmdGenTemplate)(commander_1.program);
|
|
23
|
+
(0, CheckToken_1.CmdCheckToken)(commander_1.program);
|
|
22
24
|
commander_1.program.parse(process.argv);
|
|
23
25
|
}
|
|
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.CmdScanDups = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
8
|
const utils_1 = require("@zwa73/utils");
|
|
8
9
|
const pathe_1 = __importDefault(require("pathe"));
|
|
9
|
-
const
|
|
10
|
-
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const DynImport_1 = require("../DynImport");
|
|
11
11
|
const { tap } = utils_1.UtilFP;
|
|
12
12
|
/**hashlist转为dupmap */
|
|
13
13
|
const reduce2Dupmap = (list) => list.reduce((acc, cur) => {
|
|
@@ -61,10 +61,13 @@ const CmdScanDups = (program) => program
|
|
|
61
61
|
? [process.cwd()]
|
|
62
62
|
: dir.map(d => pathe_1.default.isAbsolute(d) ? d : pathe_1.default.join(process.cwd(), d));
|
|
63
63
|
// 添加一个多步进度条
|
|
64
|
-
const
|
|
64
|
+
const cliProgress = await (0, DynImport_1.importCliProgress)();
|
|
65
|
+
if (!cliProgress)
|
|
66
|
+
(0, utils_1.throwError)('cli-progress 未安装');
|
|
67
|
+
const progressBar = new cliProgress.MultiBar({
|
|
65
68
|
clearOnComplete: true, hideCursor: true,
|
|
66
69
|
format: " {task} [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} | {status}",
|
|
67
|
-
},
|
|
70
|
+
}, cliProgress.Presets.shades_classic);
|
|
68
71
|
// 文件结构进度条
|
|
69
72
|
const structProgress = struct ? progressBar.create(1, 0, { task: "结构扫描", status: "准备中..." }) : undefined;
|
|
70
73
|
// 采样哈希进度条
|
|
@@ -81,9 +84,8 @@ const CmdScanDups = (program) => program
|
|
|
81
84
|
return await utils_1.UtilFT.fileSearchRegex(p, regex.source, { recursive });
|
|
82
85
|
})), stacklist => stacklist.flat(), // 扁平化文件路径列表
|
|
83
86
|
// 如果是结构模式则先筛选相同结构
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
structProgress.update(0, { status: `结构扫描检出 ${dupFpList.length} 个可能的相等项` }))), list => utils_1.Stream.from(list, 8)
|
|
87
|
+
async (list) => struct ? (0, utils_1.pipe)(list, tap(dupFpList => (structProgress.setTotal(dupFpList.length),
|
|
88
|
+
structProgress.update(0, { status: `结构扫描检出 ${dupFpList.length} 个可能的相等项` }))), async (list) => utils_1.Stream.from(list, 8)
|
|
87
89
|
.map(async (filePath) => ({
|
|
88
90
|
filePath,
|
|
89
91
|
hash: await struct2hash(await scanDirStruct(filePath), cpath => pathe_1.default.relative(filePath, cpath)).then(tap(() => structProgress.increment()))
|
|
@@ -91,11 +93,11 @@ const CmdScanDups = (program) => program
|
|
|
91
93
|
.toArray(), reduce2Dupmap, reduce2DupFpList) : list,
|
|
92
94
|
// 第二步:快速扫描,计算采样哈希
|
|
93
95
|
tap(list => (sampledProgress.setTotal(list.length),
|
|
94
|
-
sampledProgress.update(0, { status: `总计 ${list.length} 个文件` }))), list => utils_1.Stream.from(list, 8)
|
|
96
|
+
sampledProgress.update(0, { status: `总计 ${list.length} 个文件` }))), async (list) => utils_1.Stream.from(list, 8)
|
|
95
97
|
.map(async (filePath) => ({
|
|
96
98
|
filePath,
|
|
97
99
|
hash: struct
|
|
98
|
-
? await struct2hash(await scanDirStruct(filePath), (str) => utils_1.UtilFT.calculateHash(str, { sampled: true })).then(tap(() => sampledProgress.increment()))
|
|
100
|
+
? await struct2hash(await scanDirStruct(filePath), async (str) => utils_1.UtilFT.calculateHash(str, { sampled: true })).then(tap(() => sampledProgress.increment()))
|
|
99
101
|
: await utils_1.UtilFT.calculateHash(filePath, { sampled: true }).then(tap(() => sampledProgress.increment())),
|
|
100
102
|
}))
|
|
101
103
|
.toArray(),
|
|
@@ -103,19 +105,19 @@ const CmdScanDups = (program) => program
|
|
|
103
105
|
reduce2Dupmap, reduce2DupFpList,
|
|
104
106
|
// 第四步:对筛选出的重复文件路径并发计算完整哈希
|
|
105
107
|
tap(dupFpList => (fullHashProgress.setTotal(dupFpList.length),
|
|
106
|
-
fullHashProgress.update(0, { status: `快速扫描检出 ${dupFpList.length} 个可能的相等项` }))), dupFpList => utils_1.Stream.from(dupFpList, 8)
|
|
108
|
+
fullHashProgress.update(0, { status: `快速扫描检出 ${dupFpList.length} 个可能的相等项` }))), async (dupFpList) => utils_1.Stream.from(dupFpList, 8)
|
|
107
109
|
.map(async (filePath) => ({
|
|
108
110
|
filePath,
|
|
109
111
|
hash: struct
|
|
110
|
-
? await struct2hash(await scanDirStruct(filePath), (str) => utils_1.UtilFT.calculateHash(str)).then(tap(() => sampledProgress.increment()))
|
|
112
|
+
? await struct2hash(await scanDirStruct(filePath), async (str) => utils_1.UtilFT.calculateHash(str)).then(tap(() => sampledProgress.increment()))
|
|
111
113
|
: await utils_1.UtilFT.calculateHash(filePath).then(tap(() => fullHashProgress.increment())), // 计算完整哈希
|
|
112
114
|
}))
|
|
113
115
|
.toArray(),
|
|
114
116
|
// 第五步:重新整理完整哈希结果, 过滤唯一哈希
|
|
115
117
|
reduce2Dupmap, map => Object.entries(map).reduce((acc, [hash, files]) => files.length <= 1 ? acc : { ...acc, [hash]: files }, {}),
|
|
116
118
|
// 第六步:输出结果
|
|
117
|
-
tap(() => progressBar.stop()), out => (0, utils_1.match)(outtype, {
|
|
119
|
+
tap(() => progressBar.stop()), async (out) => (0, utils_1.match)(outtype, {
|
|
118
120
|
"console": () => utils_1.SLogger.info(out),
|
|
119
|
-
}, () => utils_1.UtilFT.writeJSONFile(pathe_1.default.join(basePath, outtype), out)));
|
|
121
|
+
}, async () => utils_1.UtilFT.writeJSONFile(pathe_1.default.join(basePath, outtype), out)));
|
|
120
122
|
});
|
|
121
123
|
exports.CmdScanDups = CmdScanDups;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type cliProgress from "cli-progress";
|
|
2
|
+
import type { Project, SyntaxKind } from 'ts-morph';
|
|
3
|
+
import type { getProgramFromFiles, buildGenerator } from 'typescript-json-schema';
|
|
4
|
+
type TJSInstance = {
|
|
5
|
+
getProgramFromFiles: typeof getProgramFromFiles;
|
|
6
|
+
buildGenerator: typeof buildGenerator;
|
|
7
|
+
};
|
|
8
|
+
export type TsMorphInstance = {
|
|
9
|
+
Project: typeof Project;
|
|
10
|
+
SyntaxKind: typeof SyntaxKind;
|
|
11
|
+
};
|
|
12
|
+
export declare function importTsMorph(): Promise<TsMorphInstance | undefined>;
|
|
13
|
+
export declare function importTJS(): Promise<TJSInstance | undefined>;
|
|
14
|
+
export declare function importCliProgress(): Promise<typeof cliProgress | undefined>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.importTsMorph = importTsMorph;
|
|
4
|
+
exports.importTJS = importTJS;
|
|
5
|
+
exports.importCliProgress = importCliProgress;
|
|
6
|
+
const utils_1 = require("@zwa73/utils");
|
|
7
|
+
async function importTsMorph() {
|
|
8
|
+
return await utils_1.UtilFunc.dynamicImport("ts-morph");
|
|
9
|
+
}
|
|
10
|
+
async function importTJS() {
|
|
11
|
+
return await utils_1.UtilFunc.dynamicImport("typescript-json-schema");
|
|
12
|
+
}
|
|
13
|
+
async function importCliProgress() {
|
|
14
|
+
return await utils_1.UtilFunc.dynamicImport("cli-progress");
|
|
15
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AnyFunc } from "@zwa73/utils";
|
|
2
|
-
import { SyntaxKind, KindToNodeMappings, Node } from "ts-morph";
|
|
1
|
+
import type { AnyFunc } from "@zwa73/utils";
|
|
2
|
+
import type { SyntaxKind, KindToNodeMappings, Node } from "ts-morph";
|
|
3
3
|
export declare namespace UtilAst {
|
|
4
4
|
/**匹配Node的类型进行处理 无法匹配时返回undefined
|
|
5
5
|
* @param node - ast节点
|
|
@@ -1,37 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
6
|
exports.UtilDT = void 0;
|
|
30
|
-
const
|
|
31
|
-
const TJS = __importStar(require("typescript-json-schema"));
|
|
32
|
-
const fs = __importStar(require("fs"));
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
33
8
|
const utils_1 = require("@zwa73/utils");
|
|
34
|
-
const
|
|
9
|
+
const pathe_1 = __importDefault(require("pathe"));
|
|
10
|
+
const DynImport_1 = require("./DynImport");
|
|
35
11
|
var UtilDT;
|
|
36
12
|
(function (UtilDT) {
|
|
37
13
|
/**生成匹配的文件的所有type的schema
|
|
@@ -47,6 +23,13 @@ var UtilDT;
|
|
|
47
23
|
* @param opt.excludeTypes - 排除的types正则匹配数组
|
|
48
24
|
*/
|
|
49
25
|
async function generateSchema(dir, opt) {
|
|
26
|
+
//导入
|
|
27
|
+
const TJS = await (0, DynImport_1.importTJS)();
|
|
28
|
+
if (!TJS)
|
|
29
|
+
(0, utils_1.throwError)('typescript-json-schema 未安装');
|
|
30
|
+
const TsMorph = await (0, DynImport_1.importTsMorph)();
|
|
31
|
+
if (!TsMorph)
|
|
32
|
+
(0, utils_1.throwError)('ts-morph 未安装');
|
|
50
33
|
//生成
|
|
51
34
|
const settings = {
|
|
52
35
|
required: true,
|
|
@@ -65,10 +48,10 @@ var UtilDT;
|
|
|
65
48
|
//const schema = TJS.generateSchema(program, opt?.typeName??"*", settings,undefined,gener) as JObject;
|
|
66
49
|
const it = opt?.includeTypes?.map(t => new RegExp(t)) ?? [/.*/];
|
|
67
50
|
const et = opt?.excludeTypes?.map(t => new RegExp(t)) ?? [];
|
|
68
|
-
const p = new
|
|
51
|
+
const p = new TsMorph.Project();
|
|
69
52
|
const types = files.map(fp => p
|
|
70
53
|
.addSourceFileAtPath(fp)
|
|
71
|
-
.getDescendantsOfKind(
|
|
54
|
+
.getDescendantsOfKind(TsMorph.SyntaxKind.TypeAliasDeclaration)
|
|
72
55
|
.map(d => d.getName())).flat();
|
|
73
56
|
const list = gener.getUserSymbols()
|
|
74
57
|
.filter(t => types.some(i => i === t))
|
|
@@ -89,8 +72,8 @@ var UtilDT;
|
|
|
89
72
|
function procSchema(schema, coverDefine) {
|
|
90
73
|
//覆盖
|
|
91
74
|
coverObj(schema["definitions"], coverDefine);
|
|
92
|
-
|
|
93
|
-
schema = JSON.parse(JSON.stringify(schema).replace(/\^\.\*SchemaString\$/g,
|
|
75
|
+
////替换SchemaString标识符
|
|
76
|
+
//schema = JSON.parse(JSON.stringify(schema).replace(/\^\.\*SchemaString\$/g,'^.*$'));
|
|
94
77
|
return schema;
|
|
95
78
|
}
|
|
96
79
|
/**展开schema以供使用 */
|
|
@@ -155,12 +138,12 @@ var UtilDT;
|
|
|
155
138
|
// 创建一个字符串,其中包含所有文件的 require 语句
|
|
156
139
|
const requires = absolutePaths.map(fp => `require('${fp}')`).join(';');
|
|
157
140
|
// 创建并执行 ts-node 命令
|
|
158
|
-
const cmd = `ts-node -r tsconfig-paths/register -e "${requires}" ${opt?.project ? `-P "${opt.project}"` : ""}`;
|
|
159
|
-
await utils_1.UtilFunc.exec(cmd, { outlvl:
|
|
141
|
+
const cmd = `ts-node --transpile-only -r tsconfig-paths/register -e "${requires}" ${opt?.project ? `-P "${opt.project}"` : ""}`;
|
|
142
|
+
await utils_1.UtilFunc.exec(cmd, { outlvl: console.log, errlvl: console.warn });
|
|
160
143
|
}
|
|
161
144
|
UtilDT.batchNode = batchNode;
|
|
162
145
|
//#region macro工具
|
|
163
|
-
const parseMacroPaths = (opt) => {
|
|
146
|
+
const parseMacroPaths = async (opt) => {
|
|
164
147
|
// JsFunc -> ComposeFunc -> xxxmacro -> parseMacroPaths -> sourceTS
|
|
165
148
|
const loc = utils_1.UtilFunc.getFuncLoc(4);
|
|
166
149
|
if (!loc && !opt?.filePath)
|
|
@@ -174,7 +157,7 @@ var UtilDT;
|
|
|
174
157
|
: opt?.filePath.map((filepath) => filepath)
|
|
175
158
|
: [basePath.replace(/(.+)\.macro\.(js|ts|cjs|mjs)$/, "$1.$2")];
|
|
176
159
|
};
|
|
177
|
-
const readFile = async (basePath) => (await
|
|
160
|
+
const readFile = async (basePath) => (await fs_1.default.promises.readFile(basePath, 'utf-8')).replaceAll("\r\n", "\n");
|
|
178
161
|
const parseCodeText = async (codeText, opt) => {
|
|
179
162
|
const strText = typeof codeText === "function" ? await codeText(opt) : codeText;
|
|
180
163
|
return strText.split('\n').map((line) => `${opt.inent}${line}`).join('\n');
|
|
@@ -229,7 +212,7 @@ var UtilDT;
|
|
|
229
212
|
regex.lastIndex += fileText.length - ol;
|
|
230
213
|
}
|
|
231
214
|
if (hasMatch)
|
|
232
|
-
await
|
|
215
|
+
await fs_1.default.promises.writeFile(filePath, fileText, 'utf-8');
|
|
233
216
|
else if (!opt?.glob)
|
|
234
217
|
utils_1.SLogger.error(`UtilDT.regionMacro 无法找到区域 ${regionId}`);
|
|
235
218
|
};
|
|
@@ -287,7 +270,7 @@ var UtilDT;
|
|
|
287
270
|
regex.lastIndex += fileText.length - ol;
|
|
288
271
|
}
|
|
289
272
|
if (hasMatch)
|
|
290
|
-
await
|
|
273
|
+
await fs_1.default.promises.writeFile(filePath, fileText, 'utf-8');
|
|
291
274
|
else if (!opt?.glob)
|
|
292
275
|
utils_1.SLogger.error(`UtilDT.commentMacro 无法找到注释 ${commentId}`);
|
|
293
276
|
};
|
|
@@ -316,7 +299,7 @@ var UtilDT;
|
|
|
316
299
|
inent: '',
|
|
317
300
|
filePath
|
|
318
301
|
});
|
|
319
|
-
await
|
|
302
|
+
await fs_1.default.promises.writeFile(filePath, parseCode, 'utf-8');
|
|
320
303
|
};
|
|
321
304
|
plist.push(utils_1.PromiseQueue.enqueue(pathe_1.default.normalize(filePath), queuefunc));
|
|
322
305
|
}
|
|
@@ -5,16 +5,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.UtilMacro = void 0;
|
|
7
7
|
const utils_1 = require("@zwa73/utils");
|
|
8
|
-
const QuickFunc_1 = require("./QuickFunc");
|
|
9
8
|
const pathe_1 = __importDefault(require("pathe"));
|
|
9
|
+
const UtilDevTool_1 = require("./UtilDevTool");
|
|
10
10
|
var UtilMacro;
|
|
11
11
|
(function (UtilMacro) {
|
|
12
12
|
/**根据注释批量生成导出
|
|
13
|
-
* @param glob - 应用的golb
|
|
13
|
+
* @param glob - 应用的golb 默认 src\/**\/index.ts
|
|
14
14
|
* @example
|
|
15
15
|
*/
|
|
16
|
-
function exportComment(glob) {
|
|
17
|
-
|
|
16
|
+
async function exportComment(glob = 'src/**/index.ts') {
|
|
17
|
+
await UtilDevTool_1.UtilDT.commentMacro(/export (\S*)/, async ({ filePath, matchId, execArr }) => {
|
|
18
18
|
const basedir = pathe_1.default.dirname(filePath);
|
|
19
19
|
const result = (await utils_1.UtilFT.fileSearchGlob(basedir, execArr[1]))
|
|
20
20
|
.map((file) => pathe_1.default.relative(basedir, file))
|
package/package.json
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zwa73/dev-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.90",
|
|
4
4
|
"description": "编译与调试工具",
|
|
5
|
-
"
|
|
6
|
-
".": {
|
|
7
|
-
"require": "./dist/cjs/index.js",
|
|
8
|
-
"import": "./dist/mjs/index.js"
|
|
9
|
-
}
|
|
10
|
-
},
|
|
11
|
-
"types": "./dist/mjs/index.d.ts",
|
|
5
|
+
"main": "dist/index.js",
|
|
12
6
|
"scripts": {
|
|
13
7
|
"test": "jest",
|
|
14
8
|
"release": "powershell scripts/release",
|
|
@@ -36,8 +30,6 @@
|
|
|
36
30
|
"@types/cli-progress": "^3.11.6",
|
|
37
31
|
"@types/jest": "^29.5.12",
|
|
38
32
|
"@types/node": "^20.14.11",
|
|
39
|
-
"jest": "^29.7.0",
|
|
40
|
-
"ts-jest": "^29.1.2",
|
|
41
33
|
"tsc-alias": "^1.8.8",
|
|
42
34
|
"typescript": "^5.3.3"
|
|
43
35
|
},
|