@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
|
@@ -1,80 +0,0 @@
|
|
|
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 utils_1 = require("@zwa73/utils");
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const pathe_1 = __importDefault(require("pathe"));
|
|
10
|
-
const DupMethodList = ["skip", "overwrite"];
|
|
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('|')}|[path:string]>`, `处理重名文件的方式:
|
|
20
|
-
skip 不进行处理
|
|
21
|
-
overwrite 覆盖重名
|
|
22
|
-
其他字符串 将重名部分映射到指定目录下的对应位置, 再次重复将会覆盖`, "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
|
-
.action(async (regexStr, replacement, options) => {
|
|
29
|
-
const regex = new RegExp(regexStr);
|
|
30
|
-
const excludeRegex = options.exclude ? new RegExp(options.exclude) : null;
|
|
31
|
-
if (!DupMethodList.includes(options.duplicateHandling))
|
|
32
|
-
(0, utils_1.throwError)(`${options.duplicateHandling} 不是有效的 duplicate-handling`);
|
|
33
|
-
const duplicateHandling = options.duplicateHandling;
|
|
34
|
-
const absout = options.output.length > 0;
|
|
35
|
-
const absin = options.input.length > 0;
|
|
36
|
-
const searchPath = absin ? options.input : process.cwd();
|
|
37
|
-
const outPath = absout ? options.output : process.cwd();
|
|
38
|
-
// 遍历当前目录下的所有文件
|
|
39
|
-
const filePaths = (await utils_1.UtilFT.fileSearchRegex(searchPath, regex, { relative: options.recursive }))
|
|
40
|
-
.map(fp => pathe_1.default.relative(searchPath, fp))
|
|
41
|
-
.filter(fp => excludeRegex ? (!excludeRegex.test(fp)) : true);
|
|
42
|
-
//对单个路径映射
|
|
43
|
-
const mapPath = async (source, target) => {
|
|
44
|
-
if (options.test)
|
|
45
|
-
return utils_1.SLogger.info(`${source} -> ${target}`);
|
|
46
|
-
const dir = pathe_1.default.parse(target).dir;
|
|
47
|
-
await utils_1.UtilFT.ensurePathExists(dir, { dir: true });
|
|
48
|
-
if (options.move)
|
|
49
|
-
return fs_1.default.promises.rename(source, target);
|
|
50
|
-
return fs_1.default.promises.copyFile(source, target);
|
|
51
|
-
};
|
|
52
|
-
await Promise.all(filePaths.map(async (rawfilePath) => {
|
|
53
|
-
const filePath = pathe_1.default.normalize(rawfilePath);
|
|
54
|
-
const replacedFilePath = filePath.replace(regex, replacement);
|
|
55
|
-
// 重命名文件
|
|
56
|
-
const oldFilePath = absin
|
|
57
|
-
? pathe_1.default.join(searchPath, filePath)
|
|
58
|
-
: filePath;
|
|
59
|
-
const newFilePath = absout
|
|
60
|
-
? pathe_1.default.join(outPath, replacedFilePath) //如果是绝对路径输出则拼接绝对路径
|
|
61
|
-
: replacedFilePath;
|
|
62
|
-
// 如果文件名发生了变化
|
|
63
|
-
if (newFilePath === oldFilePath)
|
|
64
|
-
return;
|
|
65
|
-
//如果文件已存在
|
|
66
|
-
if (await utils_1.UtilFT.pathExists(newFilePath)) {
|
|
67
|
-
//如果是跳过或覆盖
|
|
68
|
-
if (DupMethodList.includes(options.duplicateHandling)) {
|
|
69
|
-
return (0, utils_1.match)(duplicateHandling, {
|
|
70
|
-
'skip': () => utils_1.SLogger.info(`重名文件存在,跳过:${newFilePath}`),
|
|
71
|
-
'overwrite': () => mapPath(oldFilePath, newFilePath),
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
//如果是转移位置
|
|
75
|
-
return mapPath(oldFilePath, pathe_1.default.join(outPath, duplicateHandling, replacedFilePath));
|
|
76
|
-
}
|
|
77
|
-
return mapPath(oldFilePath, newFilePath);
|
|
78
|
-
}));
|
|
79
|
-
});
|
|
80
|
-
exports.CmdMapPath = CmdMapPath;
|
package/dist/cjs/UtilAst.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { AnyFunc } from "@zwa73/utils";
|
|
2
|
-
import { SyntaxKind, KindToNodeMappings, Node } from "ts-morph";
|
|
3
|
-
export declare namespace UtilAst {
|
|
4
|
-
/**匹配Node的类型进行处理 无法匹配时返回undefined
|
|
5
|
-
* @param node - ast节点
|
|
6
|
-
* @param funcMap - 处理函数映射表
|
|
7
|
-
*/
|
|
8
|
-
function withKind<T extends Partial<{
|
|
9
|
-
[P in SyntaxKind]: ((n: KindToNodeMappings[P]) => unknown);
|
|
10
|
-
}>>(node: Node, funcMap: T): {
|
|
11
|
-
[P in keyof T]: T[P] extends AnyFunc ? ReturnType<T[P]> : never;
|
|
12
|
-
}[keyof T] | undefined;
|
|
13
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { JObject } from '@zwa73/utils';
|
|
2
|
-
export declare namespace UtilDT {
|
|
3
|
-
/**执行js/ts的可选项 */
|
|
4
|
-
type BatchNodeOpt = Partial<{
|
|
5
|
-
/**tsconfig路径 */
|
|
6
|
-
project: string;
|
|
7
|
-
}>;
|
|
8
|
-
/**build任意ts文件的可选项 */
|
|
9
|
-
type BuildMatchOpt = Partial<{
|
|
10
|
-
/**包含的glob */
|
|
11
|
-
include: string | string[];
|
|
12
|
-
/**忽略的glob */
|
|
13
|
-
exclude: string | string[];
|
|
14
|
-
}> & BatchNodeOpt;
|
|
15
|
-
/**build schema的可选项 */
|
|
16
|
-
type BuildSchemaOpt = Partial<{
|
|
17
|
-
/**将会覆盖 definitions 对应内容的表 */
|
|
18
|
-
coverDefine: JObject;
|
|
19
|
-
/**schema输出路径目录 如 ./schema/ */
|
|
20
|
-
outDir: string;
|
|
21
|
-
/**包含的types正则匹配数组 默认 [/.*\/] */
|
|
22
|
-
includeTypes?: string[];
|
|
23
|
-
/**排除的types正则匹配数组 */
|
|
24
|
-
excludeTypes?: string[];
|
|
25
|
-
}> & BuildMatchOpt;
|
|
26
|
-
/**生成匹配的文件的所有type的schema
|
|
27
|
-
* @async
|
|
28
|
-
* @param dir - 基础目录
|
|
29
|
-
* @param opt - 可选参数
|
|
30
|
-
* @param opt.include - 包含的glob 默认 **\/\*.schema.ts
|
|
31
|
-
* @param opt.exclude - 忽略的glob
|
|
32
|
-
* @param opt.coverDefine - 将会覆盖 definitions 对应内容的表
|
|
33
|
-
* @param opt.project - tsconfig路径
|
|
34
|
-
* @param opt.outDir - schema输出路径目录 默认 ./schema/
|
|
35
|
-
* @param opt.includeTypes - 包含的types正则匹配数组 默认 [/.*\/]
|
|
36
|
-
* @param opt.excludeTypes - 排除的types正则匹配数组
|
|
37
|
-
*/
|
|
38
|
-
export function generateSchema(dir: string, opt?: BuildSchemaOpt): Promise<void>;
|
|
39
|
-
/**运行所有匹配的的js/ts文件
|
|
40
|
-
* @async
|
|
41
|
-
* @param dir - 基础目录
|
|
42
|
-
* @param opt - 可选参数
|
|
43
|
-
* @param opt.include - 包含的glob 默认 index.ts
|
|
44
|
-
* @param opt.exclude - 忽略的glob
|
|
45
|
-
* @param opt.project - tsconfig路径
|
|
46
|
-
*/
|
|
47
|
-
export function matchNode(dir: string, opt?: BuildMatchOpt): Promise<void>;
|
|
48
|
-
/**运行所有js/ts文件
|
|
49
|
-
* @async
|
|
50
|
-
* @param filepath - 需要运行的文件
|
|
51
|
-
* @param opt - 可选参数
|
|
52
|
-
* @param opt.project - tsconfig路径
|
|
53
|
-
*/
|
|
54
|
-
export function batchNode(filepath: string | string[], opt?: BatchNodeOpt): Promise<void>;
|
|
55
|
-
/**宏的可选参数 */
|
|
56
|
-
type MacroOpt = Partial<{
|
|
57
|
-
/**宏展开的目标文件 */
|
|
58
|
-
filePath: string[] | string;
|
|
59
|
-
/**使用glob匹配而非文件路径 */
|
|
60
|
-
glob: boolean;
|
|
61
|
-
}>;
|
|
62
|
-
/**codeText的参数 */
|
|
63
|
-
type CodeTextOpt = {
|
|
64
|
-
/**匹配的region/comment id */
|
|
65
|
-
matchId: string;
|
|
66
|
-
/**region/comment id正则的执行结果*/
|
|
67
|
-
execArr: RegExpExecArray;
|
|
68
|
-
/**展开宏的目标文件 */
|
|
69
|
-
filePath: string;
|
|
70
|
-
/**展开宏区域的原文本 */
|
|
71
|
-
text: string;
|
|
72
|
-
/**缩进 会自动应用 */
|
|
73
|
-
inent: string;
|
|
74
|
-
};
|
|
75
|
-
/**将codeText写入对应region
|
|
76
|
-
* @param regionId - 区域id \`//#region ${id}\`
|
|
77
|
-
* @param codeText - 文本
|
|
78
|
-
* @param opt - 可选参数
|
|
79
|
-
* @param opt.filePath - 目标文件 默认为去除".macro"的同名文件
|
|
80
|
-
* @param opt.glob - 使用glob匹配而非文件路径
|
|
81
|
-
*/
|
|
82
|
-
export function regionMacro(regionId: string | RegExp, codeText: string | ((opt: CodeTextOpt) => string | Promise<string>), opt?: MacroOpt): Promise<void>;
|
|
83
|
-
/**将codeText写入对应注释下
|
|
84
|
-
* @param commentId - 注释id \`// ${id}\`
|
|
85
|
-
* @param codeText - 文本
|
|
86
|
-
* @param opt - 可选参数
|
|
87
|
-
* @param opt.filePath - 目标文件 默认为去除".macro"的同名文件
|
|
88
|
-
* @param opt.glob - 使用glob匹配而非文件路径
|
|
89
|
-
*/
|
|
90
|
-
export function commentMacro(commentId: string | RegExp, codeText: string | ((opt: CodeTextOpt) => string | Promise<string>), opt?: MacroOpt): Promise<void>;
|
|
91
|
-
/**将codeText写入对应文件 不存在则创建
|
|
92
|
-
* @param codeText - 文本
|
|
93
|
-
* @param opt - 可选参数
|
|
94
|
-
* @param opt.filePath - 目标文件 默认为去除".macro"的同名文件
|
|
95
|
-
* @param opt.glob - 使用glob匹配而非文件路径
|
|
96
|
-
*/
|
|
97
|
-
export function fileMacro(codeText: string | ((opt: Omit<CodeTextOpt, 'ident' | 'matchId' | 'execArr'>) => string | Promise<string>), opt?: MacroOpt): Promise<void>;
|
|
98
|
-
export {};
|
|
99
|
-
}
|
package/dist/cjs/UtilMacro.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
type FileMacro = 5;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
type Test3 = 4;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
type CM1 = 3;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { UtilDT } from "../UtilDevTool.js";
|
|
2
|
-
/**构造macro */
|
|
3
|
-
export const CmdExpandMacro = (program) => program
|
|
4
|
-
.command("Expand-Macro")
|
|
5
|
-
.alias("expandmacro")
|
|
6
|
-
.description("根据macro生成代码")
|
|
7
|
-
.option("-i, --include <glob>", "包含的glob 默认 src/**/*.macro.ts", "src/**/*.macro.ts")
|
|
8
|
-
.option("-g, --exclude <glob>", "忽略的glob")
|
|
9
|
-
.option("-p, --project <path>", "tsconfig路径 默认tsconfig.json", "tsconfig.json")
|
|
10
|
-
.action(async (opt) => {
|
|
11
|
-
await UtilDT.matchNode(process.cwd(), {
|
|
12
|
-
include: opt.include,
|
|
13
|
-
exclude: opt.ignore,
|
|
14
|
-
project: opt.project,
|
|
15
|
-
});
|
|
16
|
-
});
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { SI18n, UtilFT } from "@zwa73/utils";
|
|
2
|
-
import { Project, SyntaxKind } from 'ts-morph';
|
|
3
|
-
import { UtilAst } from "../UtilAst.js";
|
|
4
|
-
import path from 'pathe';
|
|
5
|
-
function format(str) {
|
|
6
|
-
return str.replace(/\\(.)/g, '$1').replace(/%/g, '\\%');
|
|
7
|
-
}
|
|
8
|
-
async function procFile(p, filePath, funckey) {
|
|
9
|
-
const date = new Date().toISOString();
|
|
10
|
-
//const content = await fs.promises.readFile(filePath,'utf-8');
|
|
11
|
-
const b = p.addSourceFileAtPath(filePath);
|
|
12
|
-
//const b = p.createSourceFile(path.relative(process.cwd(),filePath),content,{overwrite:true});
|
|
13
|
-
const ds = b.getDescendantsOfKind(SyntaxKind.TaggedTemplateExpression);
|
|
14
|
-
const dats = [];
|
|
15
|
-
for (const d of ds) {
|
|
16
|
-
if (!funckey.includes(d.getTag().getText()))
|
|
17
|
-
continue;
|
|
18
|
-
const template = d.getTemplate();
|
|
19
|
-
let result = '';
|
|
20
|
-
let i = 0;
|
|
21
|
-
UtilAst.withKind(template, {
|
|
22
|
-
[SyntaxKind.NoSubstitutionTemplateLiteral]: (t) => result += format(t.getLiteralText()),
|
|
23
|
-
[SyntaxKind.TemplateExpression]: (t) => {
|
|
24
|
-
t.getChildren().forEach((c) => {
|
|
25
|
-
UtilAst.withKind(c, {
|
|
26
|
-
[SyntaxKind.TemplateHead]: (sc) => result += format(sc.getLiteralText()),
|
|
27
|
-
[SyntaxKind.SyntaxList]: (sc) => {
|
|
28
|
-
sc.getChildrenOfKind(SyntaxKind.TemplateSpan).forEach((span) => {
|
|
29
|
-
span.getChildren().forEach((ssc) => {
|
|
30
|
-
result += UtilAst.withKind(ssc, {
|
|
31
|
-
[SyntaxKind.TemplateMiddle]: (sssc) => format(sssc.getLiteralText()),
|
|
32
|
-
[SyntaxKind.TemplateTail]: (sssc) => format(sssc.getLiteralText()),
|
|
33
|
-
}) ?? String(`%${i++}`);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
const pos = b.getLineAndColumnAtPos(d.getStart());
|
|
42
|
-
const dat = {
|
|
43
|
-
original: result,
|
|
44
|
-
scan_time: date,
|
|
45
|
-
position: `${filePath}:${pos.line}:${pos.column}`,
|
|
46
|
-
lang_table: {},
|
|
47
|
-
source: "Ast"
|
|
48
|
-
};
|
|
49
|
-
dats.push(dat);
|
|
50
|
-
}
|
|
51
|
-
return dats;
|
|
52
|
-
}
|
|
53
|
-
async function scanI18n(i18nDataDir, include, exclude, funckey) {
|
|
54
|
-
const fixedKey = typeof funckey == 'string' ? [funckey] : funckey;
|
|
55
|
-
const filePaths = (await UtilFT.fileSearchGlob(process.cwd(), include, { ingore: exclude }))
|
|
56
|
-
.filter(p => ['.ts', '.tsx'].includes(path.parse(p).ext));
|
|
57
|
-
const project = new Project();
|
|
58
|
-
await SI18n.init(i18nDataDir, '*');
|
|
59
|
-
//console.log(filePaths);
|
|
60
|
-
(await Promise.all(filePaths.map(p => procFile(project, p, fixedKey))))
|
|
61
|
-
.flat().forEach(dat => SI18n.addOriginalText(dat));
|
|
62
|
-
await SI18n.saveTable();
|
|
63
|
-
}
|
|
64
|
-
/**生成i18n */
|
|
65
|
-
export const CmdGenI18n = (program) => program
|
|
66
|
-
.command("Gen-I18n")
|
|
67
|
-
.alias("geni18n")
|
|
68
|
-
.description("根据文件行为树生成i18n数据")
|
|
69
|
-
.option("-o, --output <path>", "输出的数据目录位置 默认 i18n", 'i18n')
|
|
70
|
-
.option("-i, --include <glob>", "包含的glob 默认 src/**/*.ts", "src/**/*.ts")
|
|
71
|
-
.option("-g, --exclude <glob>", "忽略的glob")
|
|
72
|
-
.option("-f, --funckey <string|strings>", "扫描的目标函数名, 可传入逗号分隔数组, 默认 t", (i) => i.split(','), ['t'])
|
|
73
|
-
.action(async (opt) => {
|
|
74
|
-
await scanI18n(opt.output, opt.include, opt.exclude, opt.funckey);
|
|
75
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { UtilDT } from "../UtilDevTool.js";
|
|
2
|
-
/**生成schema */
|
|
3
|
-
export const CmdGenSchema = (program) => program
|
|
4
|
-
.command("Gen-Schema")
|
|
5
|
-
.alias("genschema")
|
|
6
|
-
.description("生成匹配的文件的所有type的schema")
|
|
7
|
-
.option("-i, --include <glob>", "包含的glob 默认 src/**/*.schema.ts", "src/**/*.schema.ts")
|
|
8
|
-
.option("-g, --exclude <glob>", "忽略的glob")
|
|
9
|
-
.option("-p, --project <path>", "tsconfig路径 默认tsconfig.json", "tsconfig.json")
|
|
10
|
-
.option("-o, --out <dir>", "schema输出路径目录 默认 ./schema/")
|
|
11
|
-
.option("-it, --include-types <regexp[]>", "包含的types正则匹配数组, 传入逗号分隔数组", (i) => i.split(','))
|
|
12
|
-
.option("-et, --exclude-types <regexp[]>", "排除的types正则匹配数组, 传入逗号分隔数组", (i) => i.split(','))
|
|
13
|
-
.action(async (opt) => {
|
|
14
|
-
await UtilDT.generateSchema(process.cwd(), {
|
|
15
|
-
include: opt.include,
|
|
16
|
-
exclude: opt.exclude,
|
|
17
|
-
project: opt.project,
|
|
18
|
-
outDir: opt.out,
|
|
19
|
-
includeTypes: opt.includeTypes,
|
|
20
|
-
excludeTypes: opt.excludeTypes
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import path from 'pathe';
|
|
2
|
-
import { MIRROR_SOURCE, TEMPLATE_PATH } from "./RouteInterface.js";
|
|
3
|
-
import { SLogger, UtilFT, UtilFunc } from "@zwa73/utils";
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
/**复制基础文件 */
|
|
6
|
-
async function copyData(templatePath, projectPath) {
|
|
7
|
-
const filelist = await fs.promises.readdir(templatePath);
|
|
8
|
-
const plist = filelist.map(async (fileName) => {
|
|
9
|
-
SLogger.info(`正在复制 ${fileName}`);
|
|
10
|
-
const filePath = path.join(templatePath, fileName);
|
|
11
|
-
const targetPath = path.join(projectPath, fileName);
|
|
12
|
-
if (!await UtilFT.pathExists(targetPath))
|
|
13
|
-
await fs.promises.cp(filePath, targetPath, { recursive: true });
|
|
14
|
-
else
|
|
15
|
-
SLogger.info(`${fileName} 已存在 跳过`);
|
|
16
|
-
return null;
|
|
17
|
-
});
|
|
18
|
-
await Promise.all(plist);
|
|
19
|
-
}
|
|
20
|
-
/**安装npm包 */
|
|
21
|
-
async function installPackage(projectPath, depList, devDepList) {
|
|
22
|
-
const install = async (name) => await UtilFunc.exec(`npm i --registry ${MIRROR_SOURCE} ${name}`, { cwd: projectPath });
|
|
23
|
-
const installdev = async (name) => await UtilFunc.exec(`npm i --registry ${MIRROR_SOURCE} --save-dev ${name}`, { cwd: projectPath });
|
|
24
|
-
for (const name of depList) {
|
|
25
|
-
SLogger.info(`正在安装 ${name}`);
|
|
26
|
-
await install(name);
|
|
27
|
-
}
|
|
28
|
-
for (const name of devDepList) {
|
|
29
|
-
SLogger.info(`正在安装 ${name}`);
|
|
30
|
-
await installdev(name);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/**生成schema */
|
|
34
|
-
export const CmdGenTemplate = (program) => program
|
|
35
|
-
.command("Gen-Template")
|
|
36
|
-
.alias("gentemplate")
|
|
37
|
-
.description("生成项目模板")
|
|
38
|
-
.argument("<template>", "项目模板 可用 base|electron")
|
|
39
|
-
.requiredOption("-n, --projectName <name>", "项目名称")
|
|
40
|
-
.requiredOption("-d, --projectDescription <description>", "项目描述")
|
|
41
|
-
.requiredOption("-a, --authorName <name>", "作者名")
|
|
42
|
-
.action(async (templateName, opt) => {
|
|
43
|
-
const templatePath = path.join(TEMPLATE_PATH, templateName);
|
|
44
|
-
if (!await UtilFT.pathExists(templatePath))
|
|
45
|
-
SLogger.error(`模板 ${templateName} 不存在`);
|
|
46
|
-
const projectPath = path.join(process.cwd(), opt.projectName);
|
|
47
|
-
await UtilFT.ensurePathExists(projectPath, { dir: true });
|
|
48
|
-
await copyData(templatePath, projectPath);
|
|
49
|
-
await installPackage(projectPath, ['@zwa73/utils'], ['@types/node']);
|
|
50
|
-
if (await UtilFT.pathExists(path.join(projectPath, "gitignore")))
|
|
51
|
-
await fs.promises.rename(path.join(projectPath, "gitignore"), path.join(projectPath, ".gitignore"));
|
|
52
|
-
const packageJson = await UtilFT.loadJSONFile(path.join(projectPath, 'package.json'));
|
|
53
|
-
packageJson.name = opt.projectName;
|
|
54
|
-
packageJson.description = opt.projectDescription;
|
|
55
|
-
packageJson.author = opt.authorName;
|
|
56
|
-
await UtilFT.writeJSONFile(path.join(projectPath, 'package.json'), packageJson);
|
|
57
|
-
switch (templateName) {
|
|
58
|
-
case 'base': break;
|
|
59
|
-
case 'electron': break;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { SLogger, UtilFT, match, throwError } from "@zwa73/utils";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import path from "pathe";
|
|
4
|
-
const DupMethodList = ["skip", "overwrite"];
|
|
5
|
-
/**重命名文件或路径 */
|
|
6
|
-
export const CmdMapPath = (program) => program
|
|
7
|
-
.command("Map-Path")
|
|
8
|
-
.alias("mappath")
|
|
9
|
-
.description("根据正则表达式对文件名进行映射")
|
|
10
|
-
.argument("<regex>", "要匹配的正则表达式, posix风格路径")
|
|
11
|
-
.argument("<replacement>", "替换字符串")
|
|
12
|
-
.option("-e, --exclude <regex>", "排除文件的正则表达式")
|
|
13
|
-
.option(`-d, --duplicate-handling <${DupMethodList.join('|')}|[path:string]>`, `处理重名文件的方式:
|
|
14
|
-
skip 不进行处理
|
|
15
|
-
overwrite 覆盖重名
|
|
16
|
-
其他字符串 将重名部分映射到指定目录下的对应位置, 再次重复将会覆盖`, "skip")
|
|
17
|
-
.option("-r, --recursive", "是否处理子目录", false)
|
|
18
|
-
.option("-m, --move", "重命名而不是复制文件", false)
|
|
19
|
-
.option("-o, --output <path>", "输出到某个绝对路径而非当前目录", '')
|
|
20
|
-
.option("-i, --input <path>", "扫描某个绝对路径而非当前目录", '')
|
|
21
|
-
.option("-t, --test", "不对文件进行实际操作, 在控制台输出映射结果", false)
|
|
22
|
-
.action(async (regexStr, replacement, options) => {
|
|
23
|
-
const regex = new RegExp(regexStr);
|
|
24
|
-
const excludeRegex = options.exclude ? new RegExp(options.exclude) : null;
|
|
25
|
-
if (!DupMethodList.includes(options.duplicateHandling))
|
|
26
|
-
throwError(`${options.duplicateHandling} 不是有效的 duplicate-handling`);
|
|
27
|
-
const duplicateHandling = options.duplicateHandling;
|
|
28
|
-
const absout = options.output.length > 0;
|
|
29
|
-
const absin = options.input.length > 0;
|
|
30
|
-
const searchPath = absin ? options.input : process.cwd();
|
|
31
|
-
const outPath = absout ? options.output : process.cwd();
|
|
32
|
-
// 遍历当前目录下的所有文件
|
|
33
|
-
const filePaths = (await UtilFT.fileSearchRegex(searchPath, regex, { relative: options.recursive }))
|
|
34
|
-
.map(fp => path.relative(searchPath, fp))
|
|
35
|
-
.filter(fp => excludeRegex ? (!excludeRegex.test(fp)) : true);
|
|
36
|
-
//对单个路径映射
|
|
37
|
-
const mapPath = async (source, target) => {
|
|
38
|
-
if (options.test)
|
|
39
|
-
return SLogger.info(`${source} -> ${target}`);
|
|
40
|
-
const dir = path.parse(target).dir;
|
|
41
|
-
await UtilFT.ensurePathExists(dir, { dir: true });
|
|
42
|
-
if (options.move)
|
|
43
|
-
return fs.promises.rename(source, target);
|
|
44
|
-
return fs.promises.copyFile(source, target);
|
|
45
|
-
};
|
|
46
|
-
await Promise.all(filePaths.map(async (rawfilePath) => {
|
|
47
|
-
const filePath = path.normalize(rawfilePath);
|
|
48
|
-
const replacedFilePath = filePath.replace(regex, replacement);
|
|
49
|
-
// 重命名文件
|
|
50
|
-
const oldFilePath = absin
|
|
51
|
-
? path.join(searchPath, filePath)
|
|
52
|
-
: filePath;
|
|
53
|
-
const newFilePath = absout
|
|
54
|
-
? path.join(outPath, replacedFilePath) //如果是绝对路径输出则拼接绝对路径
|
|
55
|
-
: replacedFilePath;
|
|
56
|
-
// 如果文件名发生了变化
|
|
57
|
-
if (newFilePath === oldFilePath)
|
|
58
|
-
return;
|
|
59
|
-
//如果文件已存在
|
|
60
|
-
if (await UtilFT.pathExists(newFilePath)) {
|
|
61
|
-
//如果是跳过或覆盖
|
|
62
|
-
if (DupMethodList.includes(options.duplicateHandling)) {
|
|
63
|
-
return match(duplicateHandling, {
|
|
64
|
-
'skip': () => SLogger.info(`重名文件存在,跳过:${newFilePath}`),
|
|
65
|
-
'overwrite': () => mapPath(oldFilePath, newFilePath),
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
//如果是转移位置
|
|
69
|
-
return mapPath(oldFilePath, path.join(outPath, duplicateHandling, replacedFilePath));
|
|
70
|
-
}
|
|
71
|
-
return mapPath(oldFilePath, newFilePath);
|
|
72
|
-
}));
|
|
73
|
-
});
|
package/dist/mjs/Command/Node.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { SLogger, UtilFunc } from '@zwa73/utils';
|
|
2
|
-
/**编译并运行某个文件 */
|
|
3
|
-
export const CmdNode = (program) => program
|
|
4
|
-
.command('Node <path|path[]>')
|
|
5
|
-
.alias('node')
|
|
6
|
-
.option('-p, --project <path>', 'tsconfig的目录')
|
|
7
|
-
.description('编译并运行某个文件')
|
|
8
|
-
.action(async (arg, opt) => {
|
|
9
|
-
SLogger.info(`编译并运行: ${arg}`);
|
|
10
|
-
let cmd = `ts-node -r tsconfig-paths/register ${arg}`;
|
|
11
|
-
if (opt.project)
|
|
12
|
-
cmd += ` -P ${opt.project}`;
|
|
13
|
-
await UtilFunc.exec(cmd, { outlvl: 'info', errlvl: 'error' });
|
|
14
|
-
});
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import path from 'pathe';
|
|
2
|
-
import { memoize, SLogger, throwError, UtilFT, UtilFunc } from '@zwa73/utils';
|
|
3
|
-
import { checkProject, OFFICIAL_SOURCE, PROCESS_PATH } from './RouteInterface.js';
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
/**解析版本号为number数组 */
|
|
6
|
-
function parseVersion(version) {
|
|
7
|
-
const arr = version.split(".").map(Number);
|
|
8
|
-
if (arr.length !== 3)
|
|
9
|
-
throwError(`${version} 不是有效的版本号`, 'error');
|
|
10
|
-
for (let i = 0; i < 3; i++) {
|
|
11
|
-
if (!isFinite(arr[i]))
|
|
12
|
-
throwError(`${version} 不是有效的版本号`, 'error');
|
|
13
|
-
}
|
|
14
|
-
return arr;
|
|
15
|
-
}
|
|
16
|
-
/**判断版本号是否有效 */
|
|
17
|
-
function checkVersion(oldVersion, newVersion) {
|
|
18
|
-
const oldParts = parseVersion(oldVersion);
|
|
19
|
-
const newParts = parseVersion(newVersion);
|
|
20
|
-
for (let i = 0; i < 3; i++) {
|
|
21
|
-
if (newParts[i] < oldParts[i])
|
|
22
|
-
throwError(`${newVersion} 低于当前版本号 ${oldVersion}`, 'error');
|
|
23
|
-
if (newParts[i] > oldParts[i])
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
/**更新版本号 */
|
|
28
|
-
async function updateVersion(newVersion) {
|
|
29
|
-
const packagePath = path.join(PROCESS_PATH, "package.json");
|
|
30
|
-
const packageData = await memoize(UtilFT.loadJSONFile)(packagePath);
|
|
31
|
-
if (newVersion == 'current')
|
|
32
|
-
return packageData.version;
|
|
33
|
-
if (newVersion) {
|
|
34
|
-
checkVersion(packageData.version, newVersion);
|
|
35
|
-
packageData.version = newVersion;
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
const version = packageData.version.split(".");
|
|
39
|
-
version[2] = (parseInt(version[2]) + 1).toString();
|
|
40
|
-
packageData.version = version.join(".");
|
|
41
|
-
}
|
|
42
|
-
await UtilFT.writeJSONFile(packagePath, packageData);
|
|
43
|
-
return packageData.version;
|
|
44
|
-
}
|
|
45
|
-
/**获取包名 */
|
|
46
|
-
async function getPackName() {
|
|
47
|
-
const packagePath = path.join(PROCESS_PATH, "package.json");
|
|
48
|
-
const packageData = await memoize(UtilFT.loadJSONFile)(packagePath);
|
|
49
|
-
return packageData.name
|
|
50
|
-
.replace(/\//g, '-')
|
|
51
|
-
.replace(/^@/g, '');
|
|
52
|
-
}
|
|
53
|
-
/**更新版本号并发布npm包 */
|
|
54
|
-
export const CmdRelease = (program) => program
|
|
55
|
-
.command("Release")
|
|
56
|
-
.alias("release")
|
|
57
|
-
.description("更新版本号并发布包")
|
|
58
|
-
.option("-v, --version <version>", "指定发布的版本号, 为 `current` 时不更新版本号, 格式应为 `${number}.${number}.${number}`")
|
|
59
|
-
.option("-a, --access <access>", "npm publish 的 access 参数 默认 public", "public")
|
|
60
|
-
.option("-l, --local <path>", "仅打包到本地对印目录下 如./build/", undefined)
|
|
61
|
-
.action(async (opt) => {
|
|
62
|
-
checkProject();
|
|
63
|
-
SLogger.info(`开始发布项目`);
|
|
64
|
-
try {
|
|
65
|
-
const newVersion = await updateVersion(opt.version);
|
|
66
|
-
SLogger.info(`新版本号: ${newVersion}`);
|
|
67
|
-
if (opt.local) {
|
|
68
|
-
SLogger.info("正在打包...");
|
|
69
|
-
const fullpath = path.join(process.cwd(), opt.local);
|
|
70
|
-
await UtilFT.ensurePathExists(fullpath, { dir: true });
|
|
71
|
-
await UtilFunc.exec(`npm pack`, { errlvl: 'info' });
|
|
72
|
-
const packageName = await getPackName();
|
|
73
|
-
const filelist = await fs.promises.readdir(process.cwd());
|
|
74
|
-
await Promise.all(filelist
|
|
75
|
-
.filter(p => new RegExp(packageName).test(p))
|
|
76
|
-
.map(async (p) => {
|
|
77
|
-
const packagePath = path.join(fullpath, p);
|
|
78
|
-
await fs.promises.rename(p, packagePath);
|
|
79
|
-
}));
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
SLogger.info("正在发布...");
|
|
83
|
-
const cmd = `npm publish --registry ${OFFICIAL_SOURCE} --access ${opt.access}`;
|
|
84
|
-
await UtilFunc.exec(cmd, { errlvl: 'info' });
|
|
85
|
-
SLogger.info("发布完成");
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
SLogger.error(error);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function cliRoute(): Promise<void>;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { program } from 'commander';
|
|
2
|
-
import { CmdNode } from './Node.js';
|
|
3
|
-
import { CmdRelease } from './Release.js';
|
|
4
|
-
import { CmdMapPath } from './MapPath.js';
|
|
5
|
-
import { CmdScanDups } from './ScanDups.js';
|
|
6
|
-
import { CmdGenSchema } from './GenSchema.js';
|
|
7
|
-
import { CmdExpandMacro } from './ExpandMacro.js';
|
|
8
|
-
import { CmdGenI18n } from './GenI18n.js';
|
|
9
|
-
import { CmdGenTemplate } from './GenTemplate.js';
|
|
10
|
-
export async function cliRoute() {
|
|
11
|
-
CmdNode(program);
|
|
12
|
-
CmdRelease(program);
|
|
13
|
-
CmdMapPath(program);
|
|
14
|
-
CmdScanDups(program);
|
|
15
|
-
CmdGenSchema(program);
|
|
16
|
-
CmdExpandMacro(program);
|
|
17
|
-
CmdGenI18n(program);
|
|
18
|
-
CmdGenTemplate(program);
|
|
19
|
-
program.parse(process.argv);
|
|
20
|
-
}
|