@zwa73/dev-utils 1.0.57 → 1.0.59
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/dist/Command/GenSchema.js +3 -3
- package/dist/Command/Init.js +10 -0
- package/dist/Command/MapPath.js +19 -12
- package/dist/Command/Route.js +1 -2
- package/dist/Command/RouteInterface.js +7 -7
- package/dist/UtilDevTool.d.ts +4 -4
- package/dist/UtilDevTool.js +13 -4
- package/package.json +4 -3
- package/scripts/postinstall.js +7 -7
- package/src/Command/GenSchema.ts +3 -3
- package/src/Command/Init.ts +11 -0
- package/src/Command/MapPath.ts +18 -13
- package/src/UtilDevTool.ts +16 -6
- package/i18n/base_lang.json +0 -23
- package/i18n/lang/en.json +0 -10
- package/i18n/template.json +0 -10
@@ -11,14 +11,14 @@ const CmdGenSchema = (program) => program
|
|
11
11
|
.option("-g, --exclude <glob>", "忽略的glob")
|
12
12
|
.option("-p, --project <path>", "tsconfig路径 默认tsconfig.json", "tsconfig.json")
|
13
13
|
.option("-o, --out <dir>", "schema输出路径目录 默认 ./schema/")
|
14
|
-
.option("-it, --include-types <
|
15
|
-
.option("-et, --exclude-types <
|
14
|
+
.option("-it, --include-types <regexp[]>", "包含的types正则匹配数组, 传入逗号分隔数组", (i) => i.split(','))
|
15
|
+
.option("-et, --exclude-types <regexp[]>", "排除的types正则匹配数组, 传入逗号分隔数组", (i) => i.split(','))
|
16
16
|
.action(async (opt) => {
|
17
17
|
await UtilDevTool_1.UtilDT.generateSchema(process.cwd(), {
|
18
18
|
include: opt.include,
|
19
19
|
exclude: opt.exclude,
|
20
20
|
project: opt.project,
|
21
|
-
outDir: opt.
|
21
|
+
outDir: opt.out,
|
22
22
|
includeTypes: opt.includeTypes,
|
23
23
|
excludeTypes: opt.excludeTypes
|
24
24
|
});
|
package/dist/Command/Init.js
CHANGED
@@ -49,11 +49,21 @@ async function copyData() {
|
|
49
49
|
/**安装npm包 */
|
50
50
|
async function installPackage() {
|
51
51
|
const install = async (name) => await utils_1.UtilFunc.exec(`npm i --registry ${RouteInterface_1.MIRROR_SOURCE} ${name}`);
|
52
|
+
const installdev = async (name) => await utils_1.UtilFunc.exec(`npm i --registry ${RouteInterface_1.MIRROR_SOURCE} --save-dev ${name}`);
|
52
53
|
const packageList = ['@zwa73/utils'];
|
54
|
+
const devPackList = [
|
55
|
+
'@zwa73/dev-utils',
|
56
|
+
'@types/fluent-ffmpeg',
|
57
|
+
'@types/node',
|
58
|
+
];
|
53
59
|
for (const name of packageList) {
|
54
60
|
utils_1.SLogger.info(`正在安装 ${name}`);
|
55
61
|
await install(name);
|
56
62
|
}
|
63
|
+
for (const name of devPackList) {
|
64
|
+
utils_1.SLogger.info(`正在安装 ${name}`);
|
65
|
+
await installdev(name);
|
66
|
+
}
|
57
67
|
}
|
58
68
|
/**对项目进行初始化 */
|
59
69
|
const CmdInit = (program) => program
|
package/dist/Command/MapPath.js
CHANGED
@@ -7,7 +7,8 @@ exports.CmdMapPath = void 0;
|
|
7
7
|
const utils_1 = require("@zwa73/utils");
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
9
9
|
const pathe_1 = __importDefault(require("pathe"));
|
10
|
-
const DupMethodList = ["
|
10
|
+
const DupMethodList = ["skip", "overwrite", "move"];
|
11
|
+
const DupMethodWithoutMove = DupMethodList.filter(t => t != 'move');
|
11
12
|
/**重命名文件或路径 */
|
12
13
|
const CmdMapPath = (program) => program
|
13
14
|
.command("Map-Path")
|
@@ -16,10 +17,12 @@ const CmdMapPath = (program) => program
|
|
16
17
|
.argument("<regex>", "要匹配的正则表达式, posix风格路径")
|
17
18
|
.argument("<replacement>", "替换字符串")
|
18
19
|
.option("-e, --exclude <regex>", "排除文件的正则表达式")
|
19
|
-
.option(`-d, --duplicate-handling <${
|
20
|
-
|
20
|
+
.option(`-d, --duplicate-handling <${DupMethodWithoutMove.join('|')}|[path:string]>`, `处理重名文件的方式:
|
21
|
+
skip 不进行处理
|
22
|
+
overwrite 覆盖重名
|
23
|
+
其他字符串 将重名部分映射到指定目录下的对应位置, 再次重复将会覆盖`, "skip")
|
21
24
|
.option("-r, --recursive", "是否处理子目录", false)
|
22
|
-
.option("-
|
25
|
+
.option("-m, --move", "重命名而不是复制文件", false)
|
23
26
|
.option("-t, --test", "不对文件进行实际操作, 在控制台输出映射结果", false)
|
24
27
|
.action(async (regexStr, replacement, options) => {
|
25
28
|
const regex = new RegExp(regexStr);
|
@@ -38,10 +41,10 @@ const CmdMapPath = (program) => program
|
|
38
41
|
await utils_1.UtilFT.ensurePathExists(dir, { dir: true });
|
39
42
|
if (options.test)
|
40
43
|
return utils_1.SLogger.info(`${source} -> ${target}`);
|
41
|
-
if (options.
|
42
|
-
await fs_1.default.promises.copyFile(source, target);
|
43
|
-
else
|
44
|
+
if (options.move)
|
44
45
|
await fs_1.default.promises.rename(source, target);
|
46
|
+
else
|
47
|
+
await fs_1.default.promises.copyFile(source, target);
|
45
48
|
};
|
46
49
|
for (const filePath of filePaths) {
|
47
50
|
// 重命名文件
|
@@ -51,11 +54,15 @@ const CmdMapPath = (program) => program
|
|
51
54
|
continue;
|
52
55
|
//如果文件已存在
|
53
56
|
if (await utils_1.UtilFT.pathExists(newFilePath)) {
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
57
|
+
if (DupMethodWithoutMove.includes(options.duplicateHandling)) {
|
58
|
+
const fixhd = duplicateHandling;
|
59
|
+
await (0, utils_1.matchProc)(fixhd, {
|
60
|
+
'skip': () => utils_1.SLogger.info(`重名文件存在,跳过:${newFilePath}`),
|
61
|
+
'overwrite': () => mapPath(filePath, newFilePath),
|
62
|
+
});
|
63
|
+
}
|
64
|
+
else
|
65
|
+
await mapPath(filePath, pathe_1.default.join(duplicateHandling, newFilePath));
|
59
66
|
}
|
60
67
|
else
|
61
68
|
await mapPath(filePath, newFilePath);
|
package/dist/Command/Route.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.cliRoute =
|
3
|
+
exports.cliRoute = cliRoute;
|
4
4
|
const commander_1 = require("commander");
|
5
5
|
const Init_1 = require("./Init");
|
6
6
|
const Node_1 = require("./Node");
|
@@ -21,4 +21,3 @@ async function cliRoute() {
|
|
21
21
|
(0, GenI18n_1.CmdGenI18n)(commander_1.program);
|
22
22
|
commander_1.program.parse(process.argv);
|
23
23
|
}
|
24
|
-
exports.cliRoute = cliRoute;
|
@@ -3,7 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.
|
6
|
+
exports.PROJECT_PATH = exports.DATA_PATH = exports.OFFICIAL_SOURCE = exports.MIRROR_SOURCE = void 0;
|
7
|
+
exports.parseInteger = parseInteger;
|
8
|
+
exports.parseNumber = parseNumber;
|
9
|
+
exports.parseBoolean = parseBoolean;
|
10
|
+
exports.withMirrorSource = withMirrorSource;
|
11
|
+
exports.withOfficialSource = withOfficialSource;
|
12
|
+
exports.checkProject = checkProject;
|
7
13
|
const pathe_1 = __importDefault(require("pathe"));
|
8
14
|
const utils_1 = require("@zwa73/utils");
|
9
15
|
/**npm镜像源 */
|
@@ -21,7 +27,6 @@ function parseInteger(value) {
|
|
21
27
|
(0, utils_1.throwError)(`${value} 不是有效的整数数字`);
|
22
28
|
return num;
|
23
29
|
}
|
24
|
-
exports.parseInteger = parseInteger;
|
25
30
|
/** 检测任意数字类型 */
|
26
31
|
function parseNumber(value) {
|
27
32
|
const num = Number(value);
|
@@ -29,12 +34,10 @@ function parseNumber(value) {
|
|
29
34
|
(0, utils_1.throwError)(`${value} 不是有效的数字`);
|
30
35
|
return num;
|
31
36
|
}
|
32
|
-
exports.parseNumber = parseNumber;
|
33
37
|
/** 检测布尔类型 */
|
34
38
|
function parseBoolean(value) {
|
35
39
|
return value ? true : false;
|
36
40
|
}
|
37
|
-
exports.parseBoolean = parseBoolean;
|
38
41
|
/**在镜像源内镜像操作 */
|
39
42
|
async function withMirrorSource(func) {
|
40
43
|
const out = await utils_1.UtilFunc.exec('npm config get registry');
|
@@ -45,7 +48,6 @@ async function withMirrorSource(func) {
|
|
45
48
|
utils_1.SLogger.info(`正在修改npm源为 原始源: ${OriginSource}`);
|
46
49
|
await utils_1.UtilFunc.exec(`npm config set registry ${OriginSource}`);
|
47
50
|
}
|
48
|
-
exports.withMirrorSource = withMirrorSource;
|
49
51
|
/**在官方源内镜像操作 */
|
50
52
|
async function withOfficialSource(func) {
|
51
53
|
const out = await utils_1.UtilFunc.exec('npm config get registry');
|
@@ -56,11 +58,9 @@ async function withOfficialSource(func) {
|
|
56
58
|
utils_1.SLogger.info(`正在修改npm源为 原始源: ${OriginSource}`);
|
57
59
|
await utils_1.UtilFunc.exec(`npm config set registry ${OriginSource}`);
|
58
60
|
}
|
59
|
-
exports.withOfficialSource = withOfficialSource;
|
60
61
|
/**检查目录是否为项目 */
|
61
62
|
async function checkProject() {
|
62
63
|
const filePath = pathe_1.default.join(exports.PROJECT_PATH, "package.json");
|
63
64
|
if (!(await utils_1.UtilFT.pathExists(filePath)))
|
64
65
|
(0, utils_1.throwError)(`当前目录: ${exports.PROJECT_PATH} 不是npm项目目录, 请先使用 npm init`);
|
65
66
|
}
|
66
|
-
exports.checkProject = checkProject;
|
package/dist/UtilDevTool.d.ts
CHANGED
@@ -18,9 +18,9 @@ export declare namespace UtilDT {
|
|
18
18
|
coverDefine: JObject;
|
19
19
|
/**schema输出路径目录 如 ./schema/ */
|
20
20
|
outDir: string;
|
21
|
-
/**包含的types
|
21
|
+
/**包含的types正则匹配数组 默认 [/.*\/] */
|
22
22
|
includeTypes?: string[];
|
23
|
-
/**排除的types
|
23
|
+
/**排除的types正则匹配数组 */
|
24
24
|
excludeTypes?: string[];
|
25
25
|
}> & BuildMatchOpt;
|
26
26
|
/**生成匹配的文件的所有type的schema
|
@@ -32,8 +32,8 @@ export declare namespace UtilDT {
|
|
32
32
|
* @param opt.coverDefine - 将会覆盖 definitions 对应内容的表
|
33
33
|
* @param opt.project - tsconfig路径
|
34
34
|
* @param opt.outDir - schema输出路径目录 默认 ./schema/
|
35
|
-
* @param opt.includeTypes - 包含的types
|
36
|
-
* @param opt.excludeTypes - 排除的types
|
35
|
+
* @param opt.includeTypes - 包含的types正则匹配数组 默认 [/.*\/]
|
36
|
+
* @param opt.excludeTypes - 排除的types正则匹配数组
|
37
37
|
*/
|
38
38
|
export function generateSchema(dir: string, opt?: BuildSchemaOpt): Promise<void>;
|
39
39
|
/**运行所有匹配的的js/ts文件
|
package/dist/UtilDevTool.js
CHANGED
@@ -31,6 +31,7 @@ const pathe_1 = __importDefault(require("pathe"));
|
|
31
31
|
const TJS = __importStar(require("typescript-json-schema"));
|
32
32
|
const fs = __importStar(require("fs"));
|
33
33
|
const utils_1 = require("@zwa73/utils");
|
34
|
+
const ts_morph_1 = require("ts-morph");
|
34
35
|
var UtilDT;
|
35
36
|
(function (UtilDT) {
|
36
37
|
/**生成匹配的文件的所有type的schema
|
@@ -42,8 +43,8 @@ var UtilDT;
|
|
42
43
|
* @param opt.coverDefine - 将会覆盖 definitions 对应内容的表
|
43
44
|
* @param opt.project - tsconfig路径
|
44
45
|
* @param opt.outDir - schema输出路径目录 默认 ./schema/
|
45
|
-
* @param opt.includeTypes - 包含的types
|
46
|
-
* @param opt.excludeTypes - 排除的types
|
46
|
+
* @param opt.includeTypes - 包含的types正则匹配数组 默认 [/.*\/]
|
47
|
+
* @param opt.excludeTypes - 排除的types正则匹配数组
|
47
48
|
*/
|
48
49
|
async function generateSchema(dir, opt) {
|
49
50
|
//生成
|
@@ -62,11 +63,19 @@ var UtilDT;
|
|
62
63
|
const program = TJS.getProgramFromFiles(files, compilerOptions);
|
63
64
|
const gener = TJS.buildGenerator(program, settings);
|
64
65
|
//const schema = TJS.generateSchema(program, opt?.typeName??"*", settings,undefined,gener) as JObject;
|
65
|
-
const it = opt?.includeTypes?.map(t => new RegExp(t)) ?? [];
|
66
|
+
const it = opt?.includeTypes?.map(t => new RegExp(t)) ?? [/.*/];
|
66
67
|
const et = opt?.excludeTypes?.map(t => new RegExp(t)) ?? [];
|
68
|
+
const p = new ts_morph_1.Project();
|
69
|
+
const types = files.map(fp => p
|
70
|
+
.addSourceFileAtPath(fp)
|
71
|
+
.getDescendantsOfKind(ts_morph_1.SyntaxKind.TypeAliasDeclaration)
|
72
|
+
.map(d => d.getName())).flat();
|
73
|
+
//console.log(types)
|
67
74
|
const list = gener.getUserSymbols()
|
75
|
+
.filter(t => types.some(i => i === t))
|
68
76
|
.filter(t => it.some(i => i.test(t)))
|
69
77
|
.filter(t => !et.some(i => i.test(t)));
|
78
|
+
//console.log(list)
|
70
79
|
//await UtilFT.writeJSONFile('testout',list);
|
71
80
|
const schema = gener.getSchemaForSymbols(list);
|
72
81
|
const outDir = opt?.outDir ?? pathe_1.default.join(process.cwd(), 'schema');
|
@@ -74,7 +83,7 @@ var UtilDT;
|
|
74
83
|
//预处理
|
75
84
|
const proced = procSchema(schema, opt?.coverDefine ?? {});
|
76
85
|
await Promise.all([
|
77
|
-
utils_1.UtilFT.writeJSONFile(schemasPath,
|
86
|
+
utils_1.UtilFT.writeJSONFile(schemasPath, proced),
|
78
87
|
//展开
|
79
88
|
expandSchema(proced, schemasPath),
|
80
89
|
]);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@zwa73/dev-utils",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.59",
|
4
4
|
"description": "编译与调试工具",
|
5
5
|
"main": "index.js",
|
6
6
|
"scripts": {
|
@@ -16,7 +16,8 @@
|
|
16
16
|
"author": "zwa73",
|
17
17
|
"license": "ISC",
|
18
18
|
"dependencies": {
|
19
|
-
"@
|
19
|
+
"@deepkit/type-compiler": "^1.0.1-alpha.150",
|
20
|
+
"@zwa73/utils": "^1.0.146",
|
20
21
|
"commander": "^11.1.0",
|
21
22
|
"pathe": "^1.1.2",
|
22
23
|
"ts-morph": "^23.0.0",
|
@@ -27,7 +28,7 @@
|
|
27
28
|
"devDependencies": {
|
28
29
|
"@types/fluent-ffmpeg": "^2.1.24",
|
29
30
|
"@types/jest": "^29.5.12",
|
30
|
-
"@types/node": "^20.11
|
31
|
+
"@types/node": "^20.14.11",
|
31
32
|
"jest": "^29.7.0",
|
32
33
|
"ts-jest": "^29.1.2",
|
33
34
|
"tsc-alias": "^1.8.8",
|
package/scripts/postinstall.js
CHANGED
@@ -10,6 +10,8 @@ const INFO_TABLE = {
|
|
10
10
|
"1.0.36":"$macro 更名为 regionMacro"
|
11
11
|
}
|
12
12
|
|
13
|
+
const PKG_NAME = "dev-utils";
|
14
|
+
|
13
15
|
// 将版本号转换为可以比较的数字
|
14
16
|
function versionToNumber(version) {
|
15
17
|
if(version==undefined) return 0;
|
@@ -24,6 +26,7 @@ function showUpgradeMessages(prevVersion, currentVersion) {
|
|
24
26
|
// 遍历infoTable中的所有版本
|
25
27
|
for (const version in INFO_TABLE) {
|
26
28
|
const versionNumber = versionToNumber(version);
|
29
|
+
//console.log(versionNumber,prevVersionNumber,currentVersionNumber)
|
27
30
|
// 如果用户的上一个版本低于这个版本,而当前版本高于或等于这个版本
|
28
31
|
if (versionNumber > prevVersionNumber && versionNumber <= currentVersionNumber) {
|
29
32
|
// 显示这个版本的提示信息
|
@@ -35,22 +38,19 @@ function showUpgradeMessages(prevVersion, currentVersion) {
|
|
35
38
|
}
|
36
39
|
|
37
40
|
|
38
|
-
|
39
41
|
async function main(){
|
40
42
|
const packageTable = await UtilFT.loadJSONFile(PACKAGE_PATH);
|
41
43
|
const currentVersion = packageTable.version;
|
42
44
|
await UtilFT.ensurePathExists(VERSION_PATH);
|
43
|
-
const versionTable =
|
44
|
-
|
45
|
-
{"dev-utils":{version:currentVersion}});
|
46
|
-
const prevVersion = versionTable.utils.version;
|
45
|
+
const versionTable = await UtilFT.loadJSONFile(VERSION_PATH,{default:{}});
|
46
|
+
const prevVersion = versionTable[PKG_NAME]?.version ?? "0.0.0";
|
47
47
|
|
48
48
|
console.log(`${currentVersion} 版本已安装`);
|
49
49
|
// 使用这个函数来显示升级信息
|
50
50
|
const hasOut = showUpgradeMessages(prevVersion, currentVersion);
|
51
51
|
|
52
|
-
|
53
|
-
await UtilFT.writeJSONFile(VERSION_PATH,
|
52
|
+
const ntable = Object.assign({},versionTable,{[PKG_NAME]:{version:currentVersion}});
|
53
|
+
await UtilFT.writeJSONFile(VERSION_PATH, ntable);
|
54
54
|
|
55
55
|
if(!hasOut) return;
|
56
56
|
const rl = readline.createInterface({
|
package/src/Command/GenSchema.ts
CHANGED
@@ -10,14 +10,14 @@ export const CmdGenSchema = (program:Command) => program
|
|
10
10
|
.option("-g, --exclude <glob>", "忽略的glob")
|
11
11
|
.option("-p, --project <path>", "tsconfig路径 默认tsconfig.json","tsconfig.json")
|
12
12
|
.option("-o, --out <dir>", "schema输出路径目录 默认 ./schema/")
|
13
|
-
.option("-it, --include-types <
|
14
|
-
.option("-et, --exclude-types <
|
13
|
+
.option("-it, --include-types <regexp[]>", "包含的types正则匹配数组, 传入逗号分隔数组",(i:string)=>i.split(','))
|
14
|
+
.option("-et, --exclude-types <regexp[]>", "排除的types正则匹配数组, 传入逗号分隔数组",(i:string)=>i.split(','))
|
15
15
|
.action(async (opt) => {
|
16
16
|
await UtilDT.generateSchema(process.cwd(), {
|
17
17
|
include : opt.include,
|
18
18
|
exclude : opt.exclude,
|
19
19
|
project : opt.project,
|
20
|
-
outDir : opt.
|
20
|
+
outDir : opt.out,
|
21
21
|
includeTypes: opt.includeTypes,
|
22
22
|
excludeTypes: opt.excludeTypes
|
23
23
|
});
|
package/src/Command/Init.ts
CHANGED
@@ -26,11 +26,22 @@ async function copyData() {
|
|
26
26
|
async function installPackage() {
|
27
27
|
const install = async (name:string)=>
|
28
28
|
await UtilFunc.exec(`npm i --registry ${MIRROR_SOURCE} ${name}`);
|
29
|
+
const installdev = async (name:string)=>
|
30
|
+
await UtilFunc.exec(`npm i --registry ${MIRROR_SOURCE} --save-dev ${name}`);
|
29
31
|
const packageList = ['@zwa73/utils'];
|
32
|
+
const devPackList = [
|
33
|
+
'@zwa73/dev-utils',
|
34
|
+
'@types/fluent-ffmpeg',
|
35
|
+
'@types/node',
|
36
|
+
];
|
30
37
|
for(const name of packageList){
|
31
38
|
SLogger.info(`正在安装 ${name}`);
|
32
39
|
await install(name);
|
33
40
|
}
|
41
|
+
for(const name of devPackList){
|
42
|
+
SLogger.info(`正在安装 ${name}`);
|
43
|
+
await installdev(name);
|
44
|
+
}
|
34
45
|
}
|
35
46
|
|
36
47
|
/**对项目进行初始化 */
|
package/src/Command/MapPath.ts
CHANGED
@@ -3,8 +3,9 @@ import { Command } from "commander";
|
|
3
3
|
import fs from "fs";
|
4
4
|
import path from "pathe";
|
5
5
|
|
6
|
-
const DupMethodList = ["
|
6
|
+
const DupMethodList = ["skip","overwrite","move"] as const;
|
7
7
|
type DupMethod = typeof DupMethodList[number];
|
8
|
+
const DupMethodWithoutMove = DupMethodList.filter(t=>t!='move') as Exclude<DupMethod,'move'>[];
|
8
9
|
|
9
10
|
/**重命名文件或路径 */
|
10
11
|
export const CmdMapPath = (program: Command) => program
|
@@ -14,10 +15,14 @@ export const CmdMapPath = (program: Command) => program
|
|
14
15
|
.argument("<regex>", "要匹配的正则表达式, posix风格路径")
|
15
16
|
.argument("<replacement>", "替换字符串")
|
16
17
|
.option("-e, --exclude <regex>", "排除文件的正则表达式")
|
17
|
-
.option(`-d, --duplicate-handling <${
|
18
|
-
|
18
|
+
.option(`-d, --duplicate-handling <${DupMethodWithoutMove.join('|')}|[path:string]>`,
|
19
|
+
`处理重名文件的方式:
|
20
|
+
skip 不进行处理
|
21
|
+
overwrite 覆盖重名
|
22
|
+
其他字符串 将重名部分映射到指定目录下的对应位置, 再次重复将会覆盖`,
|
23
|
+
"skip")
|
19
24
|
.option("-r, --recursive", "是否处理子目录", false)
|
20
|
-
.option("-
|
25
|
+
.option("-m, --move", "重命名而不是复制文件", false)
|
21
26
|
.option("-t, --test", "不对文件进行实际操作, 在控制台输出映射结果", false)
|
22
27
|
.action(async (regexStr, replacement, options) => {
|
23
28
|
const regex = new RegExp(regexStr);
|
@@ -36,10 +41,8 @@ export const CmdMapPath = (program: Command) => program
|
|
36
41
|
const dir = path.parse(target).dir;
|
37
42
|
await UtilFT.ensurePathExists(dir,{dir:true});
|
38
43
|
if(options.test) return SLogger.info(`${source} -> ${target}`);
|
39
|
-
if (options.
|
40
|
-
|
41
|
-
else
|
42
|
-
await fs.promises.rename(source, target);
|
44
|
+
if (options.move) await fs.promises.rename(source, target);
|
45
|
+
else await fs.promises.copyFile(source, target);
|
43
46
|
}
|
44
47
|
|
45
48
|
for(const filePath of filePaths){
|
@@ -49,11 +52,13 @@ export const CmdMapPath = (program: Command) => program
|
|
49
52
|
if (newFilePath === filePath) continue;
|
50
53
|
//如果文件已存在
|
51
54
|
if(await UtilFT.pathExists(newFilePath)){
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
if(DupMethodWithoutMove.includes(options.duplicateHandling)){
|
56
|
+
const fixhd = duplicateHandling as Exclude<DupMethod,'move'>;
|
57
|
+
await matchProc(fixhd,{
|
58
|
+
'skip': ()=> SLogger.info(`重名文件存在,跳过:${newFilePath}`),
|
59
|
+
'overwrite': ()=> mapPath(filePath,newFilePath),
|
60
|
+
});
|
61
|
+
}else await mapPath(filePath, path.join(duplicateHandling, newFilePath));
|
57
62
|
} else await mapPath(filePath,newFilePath);
|
58
63
|
}
|
59
64
|
});
|
package/src/UtilDevTool.ts
CHANGED
@@ -2,6 +2,7 @@ import path from 'pathe';
|
|
2
2
|
import * as TJS from 'typescript-json-schema';
|
3
3
|
import * as fs from 'fs';
|
4
4
|
import { JObject, SLogger, UtilFT, UtilFunc, dedent, throwError } from '@zwa73/utils';
|
5
|
+
import { Project, SyntaxKind } from 'ts-morph';
|
5
6
|
|
6
7
|
export namespace UtilDT{
|
7
8
|
|
@@ -25,9 +26,9 @@ type BuildSchemaOpt = Partial<{
|
|
25
26
|
coverDefine:JObject;
|
26
27
|
/**schema输出路径目录 如 ./schema/ */
|
27
28
|
outDir:string;
|
28
|
-
/**包含的types
|
29
|
+
/**包含的types正则匹配数组 默认 [/.*\/] */
|
29
30
|
includeTypes?:string[];
|
30
|
-
/**排除的types
|
31
|
+
/**排除的types正则匹配数组 */
|
31
32
|
excludeTypes?:string[];
|
32
33
|
}>&BuildMatchOpt;
|
33
34
|
|
@@ -42,8 +43,8 @@ type BuildSchemaOpt = Partial<{
|
|
42
43
|
* @param opt.coverDefine - 将会覆盖 definitions 对应内容的表
|
43
44
|
* @param opt.project - tsconfig路径
|
44
45
|
* @param opt.outDir - schema输出路径目录 默认 ./schema/
|
45
|
-
* @param opt.includeTypes - 包含的types
|
46
|
-
* @param opt.excludeTypes - 排除的types
|
46
|
+
* @param opt.includeTypes - 包含的types正则匹配数组 默认 [/.*\/]
|
47
|
+
* @param opt.excludeTypes - 排除的types正则匹配数组
|
47
48
|
*/
|
48
49
|
export async function generateSchema(dir:string,opt?:BuildSchemaOpt){
|
49
50
|
//生成
|
@@ -65,11 +66,20 @@ export async function generateSchema(dir:string,opt?:BuildSchemaOpt){
|
|
65
66
|
);
|
66
67
|
const gener = TJS.buildGenerator(program,settings)!;
|
67
68
|
//const schema = TJS.generateSchema(program, opt?.typeName??"*", settings,undefined,gener) as JObject;
|
68
|
-
const it = opt?.includeTypes?.map(t=>new RegExp(t))??[];
|
69
|
+
const it = opt?.includeTypes?.map(t=>new RegExp(t))??[/.*/];
|
69
70
|
const et = opt?.excludeTypes?.map(t=>new RegExp(t))??[];
|
71
|
+
const p = new Project();
|
72
|
+
const types = files.map(fp => p
|
73
|
+
.addSourceFileAtPath(fp)
|
74
|
+
.getDescendantsOfKind(SyntaxKind.TypeAliasDeclaration)
|
75
|
+
.map(d=>d.getName())
|
76
|
+
).flat();
|
77
|
+
//console.log(types)
|
70
78
|
const list = gener.getUserSymbols()
|
79
|
+
.filter(t=>types.some(i=>i===t))
|
71
80
|
.filter(t=>it.some(i=>i.test(t)))
|
72
81
|
.filter(t=>!et.some(i=>i.test(t)));
|
82
|
+
//console.log(list)
|
73
83
|
//await UtilFT.writeJSONFile('testout',list);
|
74
84
|
const schema = gener.getSchemaForSymbols(list) as JObject;
|
75
85
|
const outDir = opt?.outDir ?? path.join(process.cwd(),'schema');
|
@@ -77,7 +87,7 @@ export async function generateSchema(dir:string,opt?:BuildSchemaOpt){
|
|
77
87
|
//预处理
|
78
88
|
const proced = procSchema(schema,opt?.coverDefine??{});
|
79
89
|
await Promise.all([
|
80
|
-
UtilFT.writeJSONFile(schemasPath,
|
90
|
+
UtilFT.writeJSONFile(schemasPath,proced),
|
81
91
|
//展开
|
82
92
|
expandSchema(proced,schemasPath),
|
83
93
|
]);
|
package/i18n/base_lang.json
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"base_lang": "zh-CN",
|
3
|
-
"texts": [
|
4
|
-
{
|
5
|
-
"original": "你好?%0,吗?",
|
6
|
-
"scan_time": "2024-07-22T04:08:33.552Z",
|
7
|
-
"position": "F:/Sosarciel/SosarcielCore/NodeJs/dev-utils/jest/UtilI18n/test.ts:6:13",
|
8
|
-
"source": "Ast"
|
9
|
-
},
|
10
|
-
{
|
11
|
-
"original": "abcdefg %0rst",
|
12
|
-
"scan_time": "2024-07-22T04:08:33.552Z",
|
13
|
-
"position": "F:/Sosarciel/SosarcielCore/NodeJs/dev-utils/jest/UtilI18n/test.ts:7:13",
|
14
|
-
"source": "Ast"
|
15
|
-
},
|
16
|
-
{
|
17
|
-
"original": "higklmn%0",
|
18
|
-
"scan_time": "2024-07-22T04:08:33.552Z",
|
19
|
-
"position": "F:/Sosarciel/SosarcielCore/NodeJs/dev-utils/jest/UtilI18n/test.ts:7:25",
|
20
|
-
"source": "Ast"
|
21
|
-
}
|
22
|
-
]
|
23
|
-
}
|
package/i18n/lang/en.json
DELETED