@zwa73/dev-utils 1.0.81 → 1.0.83
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/gitignore +3 -0
- package/data/template/base/package.json +25 -0
- package/data/template/base/scripts/compile.ps1 +8 -0
- package/data/template/base/scripts/release.ps1 +4 -0
- package/data/template/base/src/macro.macro.ts +6 -0
- package/data/template/base/tsconfig.cjs.json +9 -0
- package/data/template/base/tsconfig.json +22 -0
- package/data/template/base/tsconfig.mjs.json +10 -0
- package/dist/cjs/Command/GenTemplate.d.ts +3 -0
- package/dist/cjs/Command/GenTemplate.js +59 -0
- package/dist/{Command → cjs/Command}/Route.js +2 -4
- package/dist/{Command → cjs/Command}/RouteInterface.d.ts +4 -0
- package/dist/{Command → cjs/Command}/RouteInterface.js +6 -2
- package/dist/cjs/test/testRegex.js +3 -0
- package/dist/{test → cjs/test}/testRegex.macro.js +0 -1
- package/dist/{test → cjs/test}/testRegexa.macro.js +0 -1
- package/dist/mjs/Command/ExpandMacro.d.ts +3 -0
- package/dist/mjs/Command/ExpandMacro.js +16 -0
- package/dist/mjs/Command/GenI18n.d.ts +3 -0
- package/dist/mjs/Command/GenI18n.js +75 -0
- package/dist/mjs/Command/GenSchema.d.ts +3 -0
- package/dist/mjs/Command/GenSchema.js +22 -0
- package/dist/mjs/Command/GenTemplate.d.ts +3 -0
- package/dist/mjs/Command/GenTemplate.js +52 -0
- package/dist/mjs/Command/MapPath.d.ts +3 -0
- package/dist/mjs/Command/MapPath.js +64 -0
- package/dist/mjs/Command/Node.d.ts +3 -0
- package/dist/mjs/Command/Node.js +14 -0
- package/dist/mjs/Command/Release.d.ts +3 -0
- package/dist/mjs/Command/Release.js +88 -0
- package/dist/mjs/Command/Route.d.ts +1 -0
- package/dist/mjs/Command/Route.js +20 -0
- package/dist/mjs/Command/RouteInterface.d.ts +24 -0
- package/dist/mjs/Command/RouteInterface.js +58 -0
- package/dist/mjs/Command/ScanDups.d.ts +3 -0
- package/dist/mjs/Command/ScanDups.js +43 -0
- package/dist/mjs/Command/index.d.ts +1 -0
- package/dist/mjs/Command/index.js +1 -0
- package/dist/mjs/Macro.macro.d.ts +1 -0
- package/dist/mjs/Macro.macro.js +2 -0
- package/dist/mjs/QuickFunc.d.ts +2 -0
- package/dist/mjs/QuickFunc.js +2 -0
- package/dist/mjs/UtilAst.d.ts +13 -0
- package/dist/mjs/UtilAst.js +15 -0
- package/dist/mjs/UtilDevTool.d.ts +99 -0
- package/dist/mjs/UtilDevTool.js +296 -0
- package/dist/mjs/UtilInterface.d.ts +4 -0
- package/dist/mjs/UtilInterface.js +1 -0
- package/dist/mjs/UtilMacro.d.ts +7 -0
- package/dist/mjs/UtilMacro.js +23 -0
- package/dist/mjs/index.d.ts +5 -0
- package/dist/mjs/index.js +5 -0
- package/dist/mjs/test/testFileMacro.d.ts +1 -0
- package/dist/mjs/test/testFileMacro.js +1 -0
- package/dist/mjs/test/testGlobMacro.d.ts +1 -0
- package/dist/mjs/test/testGlobMacro.js +2 -0
- package/dist/mjs/test/testRegex.d.ts +1 -0
- package/dist/mjs/test/testRegex.js +2 -0
- package/dist/mjs/test/testRegex.macro.d.ts +1 -0
- package/dist/mjs/test/testRegex.macro.js +9 -0
- package/dist/mjs/test/testRegexa.d.ts +1 -0
- package/dist/mjs/test/testRegexa.js +1 -0
- package/dist/mjs/test/testRegexa.macro.d.ts +1 -0
- package/dist/mjs/test/testRegexa.macro.js +2 -0
- package/package.json +8 -3
- package/data/init/index.d.ts +0 -1
- package/data/init/index.js +0 -1
- package/data/init/scripts/compile.ps1 +0 -5
- package/data/init/tsconfig.compile.json +0 -4
- package/data/init/tsconfig.json +0 -22
- package/dist/Command/Init.d.ts +0 -3
- package/dist/Command/Init.js +0 -82
- package/dist/Command/InitElectron.d.ts +0 -3
- package/dist/Command/InitElectron.js +0 -64
- package/dist/test/testRegex.js +0 -10
- package/index.d.ts +0 -1
- package/index.js +0 -1
- /package/data/{init → template/base}/scripts/watch.ps1 +0 -0
- /package/data/{init → template/base}/src/index.ts +0 -0
- /package/data/{InitElectron → template/electron}/.eslintrc.js +0 -0
- /package/data/{InitElectron → template/electron}/forge.config.ts +0 -0
- /package/data/{InitElectron → template/electron}/gitignore +0 -0
- /package/data/{InitElectron → template/electron}/package-lock.json +0 -0
- /package/data/{InitElectron → template/electron}/package.json +0 -0
- /package/data/{InitElectron → template/electron}/src/Backend/BridgeBackend.ts +0 -0
- /package/data/{InitElectron → template/electron}/src/Backend/index.ts +0 -0
- /package/data/{InitElectron → template/electron}/src/Frontend/Base.tsx +0 -0
- /package/data/{InitElectron → template/electron}/src/Frontend/ContextProxy.ts +0 -0
- /package/data/{InitElectron → template/electron}/src/Frontend/index.ts +0 -0
- /package/data/{InitElectron → template/electron}/src/app.tsx +0 -0
- /package/data/{InitElectron → template/electron}/src/index.html +0 -0
- /package/data/{InitElectron → template/electron}/src/index.ts +0 -0
- /package/data/{InitElectron → template/electron}/src/preload.ts +0 -0
- /package/data/{InitElectron → template/electron}/src/renderer.ts +0 -0
- /package/data/{InitElectron → template/electron}/tsconfig.json +0 -0
- /package/data/{InitElectron → template/electron}/webpack.main.config.ts +0 -0
- /package/data/{InitElectron → template/electron}/webpack.plugins.ts +0 -0
- /package/data/{InitElectron → template/electron}/webpack.renderer.config.ts +0 -0
- /package/data/{InitElectron → template/electron}/webpack.rules.ts +0 -0
- /package/dist/{Command → cjs/Command}/ExpandMacro.d.ts +0 -0
- /package/dist/{Command → cjs/Command}/ExpandMacro.js +0 -0
- /package/dist/{Command → cjs/Command}/GenI18n.d.ts +0 -0
- /package/dist/{Command → cjs/Command}/GenI18n.js +0 -0
- /package/dist/{Command → cjs/Command}/GenSchema.d.ts +0 -0
- /package/dist/{Command → cjs/Command}/GenSchema.js +0 -0
- /package/dist/{Command → cjs/Command}/MapPath.d.ts +0 -0
- /package/dist/{Command → cjs/Command}/MapPath.js +0 -0
- /package/dist/{Command → cjs/Command}/Node.d.ts +0 -0
- /package/dist/{Command → cjs/Command}/Node.js +0 -0
- /package/dist/{Command → cjs/Command}/Release.d.ts +0 -0
- /package/dist/{Command → cjs/Command}/Release.js +0 -0
- /package/dist/{Command → cjs/Command}/Route.d.ts +0 -0
- /package/dist/{Command → cjs/Command}/ScanDups.d.ts +0 -0
- /package/dist/{Command → cjs/Command}/ScanDups.js +0 -0
- /package/dist/{Command → cjs/Command}/index.d.ts +0 -0
- /package/dist/{Command → cjs/Command}/index.js +0 -0
- /package/dist/{Macro.macro.d.ts → cjs/Macro.macro.d.ts} +0 -0
- /package/dist/{Macro.macro.js → cjs/Macro.macro.js} +0 -0
- /package/dist/{QuickFunc.d.ts → cjs/QuickFunc.d.ts} +0 -0
- /package/dist/{QuickFunc.js → cjs/QuickFunc.js} +0 -0
- /package/dist/{UtilAst.d.ts → cjs/UtilAst.d.ts} +0 -0
- /package/dist/{UtilAst.js → cjs/UtilAst.js} +0 -0
- /package/dist/{UtilDevTool.d.ts → cjs/UtilDevTool.d.ts} +0 -0
- /package/dist/{UtilDevTool.js → cjs/UtilDevTool.js} +0 -0
- /package/dist/{UtilInterface.d.ts → cjs/UtilInterface.d.ts} +0 -0
- /package/dist/{UtilInterface.js → cjs/UtilInterface.js} +0 -0
- /package/dist/{UtilMacro.d.ts → cjs/UtilMacro.d.ts} +0 -0
- /package/dist/{UtilMacro.js → cjs/UtilMacro.js} +0 -0
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{index.js → cjs/index.js} +0 -0
- /package/dist/{test → cjs/test}/testFileMacro.d.ts +0 -0
- /package/dist/{test → cjs/test}/testFileMacro.js +0 -0
- /package/dist/{test → cjs/test}/testGlobMacro.d.ts +0 -0
- /package/dist/{test → cjs/test}/testGlobMacro.js +0 -0
- /package/dist/{test → cjs/test}/testRegex.d.ts +0 -0
- /package/dist/{test → cjs/test}/testRegex.macro.d.ts +0 -0
- /package/dist/{test → cjs/test}/testRegexa.d.ts +0 -0
- /package/dist/{test → cjs/test}/testRegexa.js +0 -0
- /package/dist/{test → cjs/test}/testRegexa.macro.d.ts +0 -0
package/bin/cli
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
{
|
2
|
+
"name": "<%= projectName %>",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "<%= projectDescription %>",
|
5
|
+
"type": "module",
|
6
|
+
"exports": {
|
7
|
+
".": {
|
8
|
+
"require": "./dist/cjs/index.js",
|
9
|
+
"import": "./dist/mjs/index.js"
|
10
|
+
}
|
11
|
+
},
|
12
|
+
"scripts": {
|
13
|
+
"release": "powershell scripts/release",
|
14
|
+
"compile": "powershell scripts/compile",
|
15
|
+
"watch": "powershell scripts/watch"
|
16
|
+
},
|
17
|
+
"author": "<%= authorName %>",
|
18
|
+
"license": "ISC",
|
19
|
+
"files": [
|
20
|
+
"data",
|
21
|
+
"dist",
|
22
|
+
"index.js",
|
23
|
+
"index.d.ts"
|
24
|
+
]
|
25
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"allowJs": true,
|
4
|
+
"strict": true,
|
5
|
+
"module": "commonjs",
|
6
|
+
"moduleResolution": "node",
|
7
|
+
"esModuleInterop": true,
|
8
|
+
"outDir": "./dist",
|
9
|
+
"declaration": true,
|
10
|
+
"baseUrl": ".",
|
11
|
+
"emitDecoratorMetadata": true,
|
12
|
+
"experimentalDecorators": true,
|
13
|
+
"skipLibCheck": true,
|
14
|
+
"paths": {
|
15
|
+
"@/src/*" : ["./src/*"],
|
16
|
+
"@/*" : ["./*"],
|
17
|
+
"@" : ["./src/index"]
|
18
|
+
}
|
19
|
+
},
|
20
|
+
"include": ["./src/**/*.ts", "./src/**/*.js","./jest/**/*.ts"],
|
21
|
+
"exclude": ["./node_modules/**/*"]
|
22
|
+
}
|
@@ -0,0 +1,59 @@
|
|
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.CmdGenTemplate = void 0;
|
7
|
+
const pathe_1 = __importDefault(require("pathe"));
|
8
|
+
const RouteInterface_1 = require("./RouteInterface");
|
9
|
+
const utils_1 = require("@zwa73/utils");
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
11
|
+
/**复制基础文件 */
|
12
|
+
async function copyData(templatePath) {
|
13
|
+
const filelist = await fs_1.default.promises.readdir(templatePath);
|
14
|
+
const plist = filelist.map(async (fileName) => {
|
15
|
+
utils_1.SLogger.info(`正在复制 ${fileName}`);
|
16
|
+
const filePath = pathe_1.default.join(templatePath, fileName);
|
17
|
+
const targetPath = pathe_1.default.join(RouteInterface_1.PROJECT_PATH, fileName);
|
18
|
+
if (!await utils_1.UtilFT.pathExists(targetPath))
|
19
|
+
await fs_1.default.promises.cp(filePath, targetPath, { recursive: true });
|
20
|
+
else
|
21
|
+
utils_1.SLogger.info(`${fileName} 已存在 跳过`);
|
22
|
+
return null;
|
23
|
+
});
|
24
|
+
await Promise.all(plist);
|
25
|
+
}
|
26
|
+
/**安装npm包 */
|
27
|
+
async function installPackage(dep, devDep) {
|
28
|
+
const install = async (name) => await utils_1.UtilFunc.exec(`npm i --registry ${RouteInterface_1.MIRROR_SOURCE} ${name}`);
|
29
|
+
const installdev = async (name) => await utils_1.UtilFunc.exec(`npm i --registry ${RouteInterface_1.MIRROR_SOURCE} --save-dev ${name}`);
|
30
|
+
const packageList = ['@zwa73/utils'];
|
31
|
+
const devPackList = ['@types/node'];
|
32
|
+
for (const name of packageList) {
|
33
|
+
utils_1.SLogger.info(`正在安装 ${name}`);
|
34
|
+
await install(name);
|
35
|
+
}
|
36
|
+
for (const name of devPackList) {
|
37
|
+
utils_1.SLogger.info(`正在安装 ${name}`);
|
38
|
+
await installdev(name);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
/**生成schema */
|
42
|
+
const CmdGenTemplate = (program) => program
|
43
|
+
.command("Gen-Template")
|
44
|
+
.alias("gentemplate")
|
45
|
+
.description("生成项目模板")
|
46
|
+
.argument("<template>", "项目模板 可用 base|electron")
|
47
|
+
.action(async (templateName) => {
|
48
|
+
await (0, RouteInterface_1.checkProject)();
|
49
|
+
const templatePath = pathe_1.default.join(RouteInterface_1.ROOT_PATH, 'template', templateName);
|
50
|
+
if (!await utils_1.UtilFT.pathExists(templatePath))
|
51
|
+
utils_1.SLogger.error(`模板 ${templateName} 不存在`);
|
52
|
+
await copyData(pathe_1.default.join(RouteInterface_1.ROOT_PATH, 'template', templateName));
|
53
|
+
await installPackage(['@zwa73/utils'], ['@types/node']);
|
54
|
+
switch (templateName) {
|
55
|
+
case 'base': break;
|
56
|
+
case 'electron': break;
|
57
|
+
}
|
58
|
+
});
|
59
|
+
exports.CmdGenTemplate = CmdGenTemplate;
|
@@ -2,7 +2,6 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.cliRoute = cliRoute;
|
4
4
|
const commander_1 = require("commander");
|
5
|
-
const Init_1 = require("./Init");
|
6
5
|
const Node_1 = require("./Node");
|
7
6
|
const Release_1 = require("./Release");
|
8
7
|
const MapPath_1 = require("./MapPath");
|
@@ -10,10 +9,8 @@ const ScanDups_1 = require("./ScanDups");
|
|
10
9
|
const GenSchema_1 = require("./GenSchema");
|
11
10
|
const ExpandMacro_1 = require("./ExpandMacro");
|
12
11
|
const GenI18n_1 = require("./GenI18n");
|
13
|
-
const
|
12
|
+
const GenTemplate_1 = require("./GenTemplate");
|
14
13
|
async function cliRoute() {
|
15
|
-
(0, Init_1.CmdInit)(commander_1.program);
|
16
|
-
(0, InitElectron_1.CmdInitElectron)(commander_1.program);
|
17
14
|
(0, Node_1.CmdNode)(commander_1.program);
|
18
15
|
(0, Release_1.CmdRelease)(commander_1.program);
|
19
16
|
(0, MapPath_1.CmdMapPath)(commander_1.program);
|
@@ -21,5 +18,6 @@ async function cliRoute() {
|
|
21
18
|
(0, GenSchema_1.CmdGenSchema)(commander_1.program);
|
22
19
|
(0, ExpandMacro_1.CmdExpandMacro)(commander_1.program);
|
23
20
|
(0, GenI18n_1.CmdGenI18n)(commander_1.program);
|
21
|
+
(0, GenTemplate_1.CmdGenTemplate)(commander_1.program);
|
24
22
|
commander_1.program.parse(process.argv);
|
25
23
|
}
|
@@ -2,8 +2,12 @@
|
|
2
2
|
export declare const MIRROR_SOURCE = "https://registry.npmmirror.com/";
|
3
3
|
/**npm官方源 */
|
4
4
|
export declare const OFFICIAL_SOURCE = "https://registry.npmjs.org/";
|
5
|
+
/**根目录 */
|
6
|
+
export declare const ROOT_PATH: string;
|
5
7
|
/**data文件夹路径 */
|
6
8
|
export declare const DATA_PATH: string;
|
9
|
+
/**template文件夹路径 */
|
10
|
+
export declare const TEMPLATE_PATH: string;
|
7
11
|
/**项目路径 */
|
8
12
|
export declare const PROJECT_PATH: string;
|
9
13
|
/** 检测非浮点的整数类型 */
|
@@ -3,7 +3,7 @@ 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.PROJECT_PATH = exports.DATA_PATH = exports.OFFICIAL_SOURCE = exports.MIRROR_SOURCE = void 0;
|
6
|
+
exports.PROJECT_PATH = exports.TEMPLATE_PATH = exports.DATA_PATH = exports.ROOT_PATH = exports.OFFICIAL_SOURCE = exports.MIRROR_SOURCE = void 0;
|
7
7
|
exports.parseInteger = parseInteger;
|
8
8
|
exports.parseNumber = parseNumber;
|
9
9
|
exports.parseBoolean = parseBoolean;
|
@@ -16,8 +16,12 @@ const utils_1 = require("@zwa73/utils");
|
|
16
16
|
exports.MIRROR_SOURCE = "https://registry.npmmirror.com/";
|
17
17
|
/**npm官方源 */
|
18
18
|
exports.OFFICIAL_SOURCE = "https://registry.npmjs.org/";
|
19
|
+
/**根目录 */
|
20
|
+
exports.ROOT_PATH = pathe_1.default.join(__dirname, '..', '..', '..');
|
19
21
|
/**data文件夹路径 */
|
20
|
-
exports.DATA_PATH = pathe_1.default.join(
|
22
|
+
exports.DATA_PATH = pathe_1.default.join(exports.ROOT_PATH, 'data');
|
23
|
+
/**template文件夹路径 */
|
24
|
+
exports.TEMPLATE_PATH = pathe_1.default.join(exports.DATA_PATH, 'template');
|
21
25
|
/**项目路径 */
|
22
26
|
exports.PROJECT_PATH = process.cwd();
|
23
27
|
/** 检测非浮点的整数类型 */
|
@@ -1,7 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
const QuickFunc_1 = require("../QuickFunc");
|
4
|
-
console.log(__filename);
|
5
4
|
(0, QuickFunc_1.regionMacro)('macroTest1', "type Test1 = 1");
|
6
5
|
(0, QuickFunc_1.regionMacro)('macroTest2', "type Test2 = 2");
|
7
6
|
(0, QuickFunc_1.regionMacro)('macroTest3', "type Test3 = 3");
|
@@ -0,0 +1,16 @@
|
|
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
|
+
});
|
@@ -0,0 +1,75 @@
|
|
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
|
+
});
|
@@ -0,0 +1,22 @@
|
|
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
|
+
});
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import path from 'pathe';
|
2
|
+
import { checkProject, MIRROR_SOURCE, PROJECT_PATH, ROOT_PATH } from "./RouteInterface.js";
|
3
|
+
import { SLogger, UtilFT, UtilFunc } from "@zwa73/utils";
|
4
|
+
import fs from 'fs';
|
5
|
+
/**复制基础文件 */
|
6
|
+
async function copyData(templatePath) {
|
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(PROJECT_PATH, 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(dep, devDep) {
|
22
|
+
const install = async (name) => await UtilFunc.exec(`npm i --registry ${MIRROR_SOURCE} ${name}`);
|
23
|
+
const installdev = async (name) => await UtilFunc.exec(`npm i --registry ${MIRROR_SOURCE} --save-dev ${name}`);
|
24
|
+
const packageList = ['@zwa73/utils'];
|
25
|
+
const devPackList = ['@types/node'];
|
26
|
+
for (const name of packageList) {
|
27
|
+
SLogger.info(`正在安装 ${name}`);
|
28
|
+
await install(name);
|
29
|
+
}
|
30
|
+
for (const name of devPackList) {
|
31
|
+
SLogger.info(`正在安装 ${name}`);
|
32
|
+
await installdev(name);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
/**生成schema */
|
36
|
+
export const CmdGenTemplate = (program) => program
|
37
|
+
.command("Gen-Template")
|
38
|
+
.alias("gentemplate")
|
39
|
+
.description("生成项目模板")
|
40
|
+
.argument("<template>", "项目模板 可用 base|electron")
|
41
|
+
.action(async (templateName) => {
|
42
|
+
await checkProject();
|
43
|
+
const templatePath = path.join(ROOT_PATH, 'template', templateName);
|
44
|
+
if (!await UtilFT.pathExists(templatePath))
|
45
|
+
SLogger.error(`模板 ${templateName} 不存在`);
|
46
|
+
await copyData(path.join(ROOT_PATH, 'template', templateName));
|
47
|
+
await installPackage(['@zwa73/utils'], ['@types/node']);
|
48
|
+
switch (templateName) {
|
49
|
+
case 'base': break;
|
50
|
+
case 'electron': break;
|
51
|
+
}
|
52
|
+
});
|
@@ -0,0 +1,64 @@
|
|
1
|
+
import { SLogger, UtilFT, matchProc, throwError } from "@zwa73/utils";
|
2
|
+
import fs from "fs";
|
3
|
+
import path from "pathe";
|
4
|
+
const DupMethodList = ["skip", "overwrite", "move"];
|
5
|
+
const DupMethodWithoutMove = DupMethodList.filter(t => t != 'move');
|
6
|
+
/**重命名文件或路径 */
|
7
|
+
export const CmdMapPath = (program) => program
|
8
|
+
.command("Map-Path")
|
9
|
+
.alias("mappath")
|
10
|
+
.description("根据正则表达式对文件名进行映射")
|
11
|
+
.argument("<regex>", "要匹配的正则表达式, posix风格路径")
|
12
|
+
.argument("<replacement>", "替换字符串")
|
13
|
+
.option("-e, --exclude <regex>", "排除文件的正则表达式")
|
14
|
+
.option(`-d, --duplicate-handling <${DupMethodWithoutMove.join('|')}|[path:string]>`, `处理重名文件的方式:
|
15
|
+
skip 不进行处理
|
16
|
+
overwrite 覆盖重名
|
17
|
+
其他字符串 将重名部分映射到指定目录下的对应位置, 再次重复将会覆盖`, "skip")
|
18
|
+
.option("-r, --recursive", "是否处理子目录", false)
|
19
|
+
.option("-m, --move", "重命名而不是复制文件", false)
|
20
|
+
.option("-t, --test", "不对文件进行实际操作, 在控制台输出映射结果", false)
|
21
|
+
.action(async (regexStr, replacement, options) => {
|
22
|
+
const regex = new RegExp(regexStr);
|
23
|
+
const excludeRegex = options.exclude ? new RegExp(options.exclude) : null;
|
24
|
+
if (!DupMethodList.includes(options.duplicateHandling))
|
25
|
+
throwError(`${options.duplicateHandling} 不是有效的 duplicate-handling`);
|
26
|
+
const duplicateHandling = options.duplicateHandling;
|
27
|
+
const basePath = process.cwd();
|
28
|
+
// 遍历当前目录下的所有文件
|
29
|
+
const filePaths = (await UtilFT.fileSearchRegex(basePath, regex.source, { relative: options.recursive }))
|
30
|
+
.map((filePath) => path.relative(basePath, filePath))
|
31
|
+
.filter((filePath) => excludeRegex ? (!excludeRegex.test(filePath)) : true);
|
32
|
+
//对单个路径映射
|
33
|
+
const mapPath = async (source, target) => {
|
34
|
+
const dir = path.parse(target).dir;
|
35
|
+
await UtilFT.ensurePathExists(dir, { dir: true });
|
36
|
+
if (options.test)
|
37
|
+
return SLogger.info(`${source} -> ${target}`);
|
38
|
+
if (options.move)
|
39
|
+
await fs.promises.rename(source, target);
|
40
|
+
else
|
41
|
+
await fs.promises.copyFile(source, target);
|
42
|
+
};
|
43
|
+
for (const filePath of filePaths) {
|
44
|
+
// 重命名文件
|
45
|
+
const newFilePath = filePath.replace(regex, replacement);
|
46
|
+
// 如果文件名发生了变化
|
47
|
+
if (newFilePath === filePath)
|
48
|
+
continue;
|
49
|
+
//如果文件已存在
|
50
|
+
if (await UtilFT.pathExists(newFilePath)) {
|
51
|
+
if (DupMethodWithoutMove.includes(options.duplicateHandling)) {
|
52
|
+
const fixhd = duplicateHandling;
|
53
|
+
await matchProc(fixhd, {
|
54
|
+
'skip': () => SLogger.info(`重名文件存在,跳过:${newFilePath}`),
|
55
|
+
'overwrite': () => mapPath(filePath, newFilePath),
|
56
|
+
});
|
57
|
+
}
|
58
|
+
else
|
59
|
+
await mapPath(filePath, path.join(duplicateHandling, newFilePath));
|
60
|
+
}
|
61
|
+
else
|
62
|
+
await mapPath(filePath, newFilePath);
|
63
|
+
}
|
64
|
+
});
|
@@ -0,0 +1,14 @@
|
|
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
|
+
});
|
@@ -0,0 +1,88 @@
|
|
1
|
+
import path from 'pathe';
|
2
|
+
import { memoize, SLogger, throwError, UtilFT, UtilFunc } from '@zwa73/utils';
|
3
|
+
import { checkProject, OFFICIAL_SOURCE, PROJECT_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(PROJECT_PATH, "package.json");
|
30
|
+
const packageData = await memoize(UtilFT.loadJSONFile)(packagePath);
|
31
|
+
if (newVersion) {
|
32
|
+
checkVersion(packageData.version, newVersion);
|
33
|
+
packageData.version = newVersion;
|
34
|
+
}
|
35
|
+
else {
|
36
|
+
const version = packageData.version.split(".");
|
37
|
+
version[2] = (parseInt(version[2]) + 1).toString();
|
38
|
+
packageData.version = version.join(".");
|
39
|
+
}
|
40
|
+
await UtilFT.writeJSONFile(packagePath, packageData);
|
41
|
+
return packageData.version;
|
42
|
+
}
|
43
|
+
/**获取包名 */
|
44
|
+
async function getPackName() {
|
45
|
+
const packagePath = path.join(PROJECT_PATH, "package.json");
|
46
|
+
const packageData = await memoize(UtilFT.loadJSONFile)(packagePath);
|
47
|
+
return packageData.name
|
48
|
+
.replace(/\//g, '-')
|
49
|
+
.replace(/^@/g, '');
|
50
|
+
}
|
51
|
+
/**更新版本号并发布npm包 */
|
52
|
+
export const CmdRelease = (program) => program
|
53
|
+
.command("Release")
|
54
|
+
.alias("release")
|
55
|
+
.description("更新版本号并发布包")
|
56
|
+
.option("-v, --version <version>", "指定发布的版本号 格式应为 `${number}.${number}.${number}`")
|
57
|
+
.option("-a, --access <access>", "npm publish 的 access 参数 默认 public", "public")
|
58
|
+
.option("-l, --local <path>", "仅打包到本地对印目录下 如./build/", undefined)
|
59
|
+
.action(async (opt) => {
|
60
|
+
checkProject();
|
61
|
+
SLogger.info(`开始发布项目`);
|
62
|
+
try {
|
63
|
+
const newVersion = await updateVersion(opt.version);
|
64
|
+
SLogger.info(`新版本号: ${newVersion}`);
|
65
|
+
if (opt.local) {
|
66
|
+
SLogger.info("正在打包...");
|
67
|
+
const fullpath = path.join(process.cwd(), opt.local);
|
68
|
+
await UtilFT.ensurePathExists(fullpath, { dir: true });
|
69
|
+
await UtilFunc.exec(`npm pack`, { errlvl: 'info' });
|
70
|
+
const packageName = await getPackName();
|
71
|
+
const filelist = await fs.promises.readdir(process.cwd());
|
72
|
+
await Promise.all(filelist
|
73
|
+
.filter(p => new RegExp(packageName).test(p))
|
74
|
+
.map(async (p) => {
|
75
|
+
const packagePath = path.join(fullpath, p);
|
76
|
+
await fs.promises.rename(p, packagePath);
|
77
|
+
}));
|
78
|
+
return;
|
79
|
+
}
|
80
|
+
SLogger.info("正在发布...");
|
81
|
+
const cmd = `npm publish --registry ${OFFICIAL_SOURCE} --access ${opt.access}`;
|
82
|
+
await UtilFunc.exec(cmd, { errlvl: 'info' });
|
83
|
+
SLogger.info("发布完成");
|
84
|
+
}
|
85
|
+
catch (error) {
|
86
|
+
SLogger.error(error);
|
87
|
+
}
|
88
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function cliRoute(): Promise<void>;
|