@zwa73/dev-utils 1.0.58 → 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 +1 -1
- 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.js +5 -6
- package/package.json +4 -3
- package/scripts/postinstall.js +7 -7
- package/src/Command/GenSchema.ts +1 -1
- package/src/Command/Init.ts +11 -0
- package/src/Command/MapPath.ts +18 -13
- package/src/UtilDevTool.ts +6 -6
- package/dist/b.schema.d.ts +0 -4
- package/dist/b.schema.js +0 -3
- package/src/b.schema.ts +0 -5
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.js
CHANGED
@@ -66,11 +66,10 @@ var UtilDT;
|
|
66
66
|
const it = opt?.includeTypes?.map(t => new RegExp(t)) ?? [/.*/];
|
67
67
|
const et = opt?.excludeTypes?.map(t => new RegExp(t)) ?? [];
|
68
68
|
const p = new ts_morph_1.Project();
|
69
|
-
const types = files.map(fp =>
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
}).flat();
|
69
|
+
const types = files.map(fp => p
|
70
|
+
.addSourceFileAtPath(fp)
|
71
|
+
.getDescendantsOfKind(ts_morph_1.SyntaxKind.TypeAliasDeclaration)
|
72
|
+
.map(d => d.getName())).flat();
|
74
73
|
//console.log(types)
|
75
74
|
const list = gener.getUserSymbols()
|
76
75
|
.filter(t => types.some(i => i === t))
|
@@ -84,7 +83,7 @@ var UtilDT;
|
|
84
83
|
//预处理
|
85
84
|
const proced = procSchema(schema, opt?.coverDefine ?? {});
|
86
85
|
await Promise.all([
|
87
|
-
utils_1.UtilFT.writeJSONFile(schemasPath,
|
86
|
+
utils_1.UtilFT.writeJSONFile(schemasPath, proced),
|
88
87
|
//展开
|
89
88
|
expandSchema(proced, schemasPath),
|
90
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
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
@@ -69,11 +69,11 @@ export async function generateSchema(dir:string,opt?:BuildSchemaOpt){
|
|
69
69
|
const it = opt?.includeTypes?.map(t=>new RegExp(t))??[/.*/];
|
70
70
|
const et = opt?.excludeTypes?.map(t=>new RegExp(t))??[];
|
71
71
|
const p = new Project();
|
72
|
-
const types = files.map(fp=>
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
const types = files.map(fp => p
|
73
|
+
.addSourceFileAtPath(fp)
|
74
|
+
.getDescendantsOfKind(SyntaxKind.TypeAliasDeclaration)
|
75
|
+
.map(d=>d.getName())
|
76
|
+
).flat();
|
77
77
|
//console.log(types)
|
78
78
|
const list = gener.getUserSymbols()
|
79
79
|
.filter(t=>types.some(i=>i===t))
|
@@ -87,7 +87,7 @@ export async function generateSchema(dir:string,opt?:BuildSchemaOpt){
|
|
87
87
|
//预处理
|
88
88
|
const proced = procSchema(schema,opt?.coverDefine??{});
|
89
89
|
await Promise.all([
|
90
|
-
UtilFT.writeJSONFile(schemasPath,
|
90
|
+
UtilFT.writeJSONFile(schemasPath,proced),
|
91
91
|
//展开
|
92
92
|
expandSchema(proced,schemasPath),
|
93
93
|
]);
|
package/dist/b.schema.d.ts
DELETED
package/dist/b.schema.js
DELETED