@zwa73/dev-utils 1.0.88 → 1.0.89
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 +2 -2
- package/data/template/base/package.json +6 -6
- package/data/template/base/scripts/compile.ps1 +23 -6
- package/data/template/base/tsconfig.cjs.json +2 -1
- package/data/template/base/tsconfig.json +3 -5
- package/data/template/base/tsconfig.mjs.json +2 -2
- package/data/template/base/tsconfig.types.json +8 -0
- package/data/template/cjs/gitignore +3 -0
- package/data/template/cjs/package.json +19 -0
- package/data/template/cjs/scripts/compile.ps1 +6 -0
- package/data/template/cjs/scripts/expand-macro.ps1 +2 -0
- package/data/template/cjs/scripts/release.ps1 +4 -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/{cjs/Command → Command}/GenI18n.js +14 -10
- package/dist/{cjs/Command → Command}/GenTemplate.js +7 -4
- package/dist/{cjs/Command → Command}/ScanDups.js +4 -3
- package/dist/DynImport.d.ts +15 -0
- package/dist/DynImport.js +15 -0
- package/dist/{mjs/UtilAst.d.ts → UtilAst.d.ts} +1 -1
- package/dist/{cjs/UtilDevTool.js → UtilDevTool.js} +13 -34
- package/dist/UtilInterface.d.ts +8 -0
- package/dist/UtilMacro.d.ts +7 -0
- package/dist/{cjs/UtilMacro.js → UtilMacro.js} +2 -2
- package/package.json +2 -8
- package/dist/cjs/UtilAst.d.ts +0 -13
- 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.d.ts +0 -3
- 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.d.ts +0 -99
- 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.d.ts +0 -0
- /package/dist/{cjs/Command → Command}/ExpandMacro.js +0 -0
- /package/dist/{cjs/Command → Command}/GenI18n.d.ts +0 -0
- /package/dist/{cjs/Command → Command}/GenSchema.d.ts +0 -0
- /package/dist/{cjs/Command → Command}/GenSchema.js +0 -0
- /package/dist/{cjs/Command → Command}/GenTemplate.d.ts +0 -0
- /package/dist/{cjs/Command → Command}/MapPath.d.ts +0 -0
- /package/dist/{cjs/Command → Command}/MapPath.js +0 -0
- /package/dist/{cjs/Command → Command}/Node.d.ts +0 -0
- /package/dist/{cjs/Command → Command}/Node.js +0 -0
- /package/dist/{cjs/Command → Command}/Release.d.ts +0 -0
- /package/dist/{cjs/Command → Command}/Release.js +0 -0
- /package/dist/{cjs/Command → Command}/Route.d.ts +0 -0
- /package/dist/{cjs/Command → Command}/Route.js +0 -0
- /package/dist/{cjs/Command → Command}/RouteInterface.d.ts +0 -0
- /package/dist/{cjs/Command → Command}/RouteInterface.js +0 -0
- /package/dist/{cjs/Command → Command}/ScanDups.d.ts +0 -0
- /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/UtilDevTool.d.ts → UtilDevTool.d.ts} +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
package/bin/cli
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
"version": "1.0.0",
|
4
4
|
"description": "<%= projectDescription %>",
|
5
5
|
"exports": {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
".": {
|
7
|
+
"require": "./dist/cjs/index.js",
|
8
|
+
"import": "./dist/mjs/index.mjs",
|
9
|
+
"types": "./dist/types/index.d.ts"
|
10
|
+
}
|
11
|
+
},
|
12
12
|
"scripts": {
|
13
13
|
"test": "jest",
|
14
14
|
"expand-macro": "powershell scripts/expand-macro",
|
@@ -1,8 +1,25 @@
|
|
1
|
-
|
1
|
+
npm run expand-macro
|
2
|
+
Write-Output 开始删除原dist
|
2
3
|
Remove-Item -Recurse -Force dist
|
3
4
|
Write-Output 开始编译
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
|
6
|
+
$CurrentDir = Get-Location
|
7
|
+
|
8
|
+
Start-Job -Name "JobCjs" -ScriptBlock {
|
9
|
+
Set-Location $using:CurrentDir
|
10
|
+
tsc -p tsconfig.cjs.json
|
11
|
+
tsc-alias -p tsconfig.cjs.json
|
12
|
+
}
|
13
|
+
Start-Job -Name "JobMjs" -ScriptBlock {
|
14
|
+
Set-Location $using:CurrentDir
|
15
|
+
tsc -p tsconfig.mjs.json
|
16
|
+
tsc-alias -p tsconfig.mjs.json
|
17
|
+
tsc-esm-fix --tsconfig "./tsconfig.mjs.json" --ext ".mjs"
|
18
|
+
}
|
19
|
+
Start-Job -Name "JobTypes" -ScriptBlock {
|
20
|
+
Set-Location $using:CurrentDir
|
21
|
+
tsc -p tsconfig.types.json
|
22
|
+
tsc-alias -p tsconfig.types.json
|
23
|
+
}
|
24
|
+
Wait-Job -State Running
|
25
|
+
Get-Job | Receive-Job
|
@@ -2,16 +2,14 @@
|
|
2
2
|
"compilerOptions": {
|
3
3
|
"allowJs": true,
|
4
4
|
"strict": true,
|
5
|
-
"module": "commonjs",
|
6
|
-
"moduleResolution": "node",
|
7
5
|
"target": "ES2022",
|
6
|
+
"module": "node16",
|
7
|
+
"moduleResolution": "node16",
|
8
8
|
"esModuleInterop": true,
|
9
|
-
"outDir": "./dist",
|
10
|
-
"declaration": true,
|
11
|
-
"baseUrl": ".",
|
12
9
|
"emitDecoratorMetadata": true,
|
13
10
|
"experimentalDecorators": true,
|
14
11
|
"skipLibCheck": true,
|
12
|
+
"baseUrl": ".",
|
15
13
|
"paths": {
|
16
14
|
"@/src/*" : ["./src/*"],
|
17
15
|
"@/*" : ["./*"],
|
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"name": "<%= projectName %>",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "<%= projectDescription %>",
|
5
|
+
"main": "dist/index.js",
|
6
|
+
"scripts": {
|
7
|
+
"test": "jest",
|
8
|
+
"expand-macro": "powershell scripts/expand-macro",
|
9
|
+
"release": "powershell scripts/release",
|
10
|
+
"compile": "powershell scripts/compile",
|
11
|
+
"watch": "powershell scripts/watch"
|
12
|
+
},
|
13
|
+
"author": "<%= authorName %>",
|
14
|
+
"license": "ISC",
|
15
|
+
"files": [
|
16
|
+
"data",
|
17
|
+
"dist"
|
18
|
+
]
|
19
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# 定义一个函数来运行脚本
|
2
|
+
function New-Script {
|
3
|
+
param($command)
|
4
|
+
# 在后台运行命令
|
5
|
+
Start-Process -NoNewWindow -FilePath "powershell" -ArgumentList "-Command", $command
|
6
|
+
}
|
7
|
+
|
8
|
+
# 开始运行脚本
|
9
|
+
New-Script "tsc -w -p tsconfig.compile.json"
|
10
|
+
New-Script "tsc-alias -w -p tsconfig.compile.json"
|
File without changes
|
@@ -0,0 +1,12 @@
|
|
1
|
+
{
|
2
|
+
"extends": "./tsconfig.json",
|
3
|
+
"compilerOptions": {
|
4
|
+
"module": "node16",
|
5
|
+
"moduleResolution": "node16",
|
6
|
+
"outDir": "./dist",
|
7
|
+
"target": "ES2022",
|
8
|
+
"declaration": true
|
9
|
+
},
|
10
|
+
"include": ["./src/**/*.ts", "./src/**/*.js"],
|
11
|
+
"exclude": ["./node_modules/**/*","./src/**/*.macro.ts","./src/**/*.schema.ts"]
|
12
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"allowJs": true,
|
4
|
+
"strict": true,
|
5
|
+
"target": "ES2022",
|
6
|
+
"module": "node16",
|
7
|
+
"moduleResolution": "node16",
|
8
|
+
"esModuleInterop": true,
|
9
|
+
"emitDecoratorMetadata": true,
|
10
|
+
"experimentalDecorators": true,
|
11
|
+
"skipLibCheck": true,
|
12
|
+
"baseUrl": ".",
|
13
|
+
"paths": {
|
14
|
+
"@/src/*" : ["./src/*"],
|
15
|
+
"@/*" : ["./*"],
|
16
|
+
"@" : ["./src/index"]
|
17
|
+
}
|
18
|
+
},
|
19
|
+
"include": ["./src/**/*.ts", "./src/**/*.js","./jest/**/*.ts"],
|
20
|
+
"exclude": ["./node_modules/**/*"]
|
21
|
+
}
|
@@ -12,29 +12,29 @@
|
|
12
12
|
"lint": "eslint --ext .ts,.tsx ."
|
13
13
|
},
|
14
14
|
"devDependencies": {
|
15
|
-
"@babel/core": "
|
16
|
-
"@babel/preset-react": "
|
17
|
-
"@electron-forge/cli": "
|
18
|
-
"@electron-forge/maker-deb": "
|
19
|
-
"@electron-forge/maker-rpm": "
|
20
|
-
"@electron-forge/maker-squirrel": "
|
21
|
-
"@electron-forge/maker-zip": "
|
22
|
-
"@electron-forge/plugin-auto-unpack-natives": "
|
23
|
-
"@electron-forge/plugin-fuses": "
|
24
|
-
"@electron-forge/plugin-webpack": "
|
25
|
-
"@electron/fuses": "
|
15
|
+
"@babel/core": "7.25.2",
|
16
|
+
"@babel/preset-react": "7.24.7",
|
17
|
+
"@electron-forge/cli": "7.4.0",
|
18
|
+
"@electron-forge/maker-deb": "7.4.0",
|
19
|
+
"@electron-forge/maker-rpm": "7.4.0",
|
20
|
+
"@electron-forge/maker-squirrel": "7.4.0",
|
21
|
+
"@electron-forge/maker-zip": "7.4.0",
|
22
|
+
"@electron-forge/plugin-auto-unpack-natives": "7.4.0",
|
23
|
+
"@electron-forge/plugin-fuses": "7.4.0",
|
24
|
+
"@electron-forge/plugin-webpack": "7.4.0",
|
25
|
+
"@electron/fuses": "1.8.0",
|
26
26
|
"@types/node": "^22.5.2",
|
27
|
-
"@types/react": "
|
28
|
-
"@types/react-dom": "
|
29
|
-
"@vercel/webpack-asset-relocator-loader": "
|
30
|
-
"babel-loader": "
|
31
|
-
"css-loader": "
|
32
|
-
"electron": "
|
33
|
-
"fork-ts-checker-webpack-plugin": "
|
34
|
-
"node-loader": "
|
35
|
-
"style-loader": "
|
36
|
-
"ts-loader": "
|
37
|
-
"ts-node": "
|
27
|
+
"@types/react": "18.3.5",
|
28
|
+
"@types/react-dom": "18.3.0",
|
29
|
+
"@vercel/webpack-asset-relocator-loader": "1.7.3",
|
30
|
+
"babel-loader": "9.1.3",
|
31
|
+
"css-loader": "6.11.0",
|
32
|
+
"electron": "31.3.1",
|
33
|
+
"fork-ts-checker-webpack-plugin": "7.3.0",
|
34
|
+
"node-loader": "2.0.0",
|
35
|
+
"style-loader": "3.3.4",
|
36
|
+
"ts-loader": "9.5.1",
|
37
|
+
"ts-node": "10.9.2",
|
38
38
|
"tsconfig-paths-webpack-plugin": "^4.1.0",
|
39
39
|
"typescript": "~4.5.4"
|
40
40
|
},
|
@@ -46,9 +46,9 @@
|
|
46
46
|
"dependencies": {
|
47
47
|
"@zwa73/react-utils": "*",
|
48
48
|
"@zwa73/utils": "*",
|
49
|
-
"electron-squirrel-startup": "
|
50
|
-
"react": "
|
51
|
-
"react-dom": "
|
49
|
+
"electron-squirrel-startup": "1.0.1",
|
50
|
+
"react": "18.3.1",
|
51
|
+
"react-dom": "18.3.1",
|
52
52
|
"styled-components": "^6.1.13"
|
53
53
|
}
|
54
54
|
}
|
@@ -5,18 +5,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.CmdGenI18n = void 0;
|
7
7
|
const utils_1 = require("@zwa73/utils");
|
8
|
-
const ts_morph_1 = require("ts-morph");
|
9
8
|
const UtilAst_1 = require("../UtilAst");
|
10
9
|
const pathe_1 = __importDefault(require("pathe"));
|
10
|
+
const DynImport_1 = require("../DynImport");
|
11
11
|
function format(str) {
|
12
12
|
return str.replace(/\\(.)/g, '$1').replace(/%/g, '\\%');
|
13
13
|
}
|
14
14
|
async function procFile(p, filePath, funckey) {
|
15
|
+
const TsMorph = await (0, DynImport_1.importTsMorph)();
|
16
|
+
const { SyntaxKind } = TsMorph;
|
15
17
|
const date = new Date().toISOString();
|
16
18
|
//const content = await fs.promises.readFile(filePath,'utf-8');
|
17
19
|
const b = p.addSourceFileAtPath(filePath);
|
18
20
|
//const b = p.createSourceFile(path.relative(process.cwd(),filePath),content,{overwrite:true});
|
19
|
-
const ds = b.getDescendantsOfKind(
|
21
|
+
const ds = b.getDescendantsOfKind(SyntaxKind.TaggedTemplateExpression);
|
20
22
|
const dats = [];
|
21
23
|
for (const d of ds) {
|
22
24
|
if (!funckey.includes(d.getTag().getText()))
|
@@ -25,17 +27,17 @@ async function procFile(p, filePath, funckey) {
|
|
25
27
|
let result = '';
|
26
28
|
let i = 0;
|
27
29
|
UtilAst_1.UtilAst.withKind(template, {
|
28
|
-
[
|
29
|
-
[
|
30
|
+
[SyntaxKind.NoSubstitutionTemplateLiteral]: (t) => result += format(t.getLiteralText()),
|
31
|
+
[SyntaxKind.TemplateExpression]: (t) => {
|
30
32
|
t.getChildren().forEach((c) => {
|
31
33
|
UtilAst_1.UtilAst.withKind(c, {
|
32
|
-
[
|
33
|
-
[
|
34
|
-
sc.getChildrenOfKind(
|
34
|
+
[SyntaxKind.TemplateHead]: (sc) => result += format(sc.getLiteralText()),
|
35
|
+
[SyntaxKind.SyntaxList]: (sc) => {
|
36
|
+
sc.getChildrenOfKind(SyntaxKind.TemplateSpan).forEach((span) => {
|
35
37
|
span.getChildren().forEach((ssc) => {
|
36
38
|
result += UtilAst_1.UtilAst.withKind(ssc, {
|
37
|
-
[
|
38
|
-
[
|
39
|
+
[SyntaxKind.TemplateMiddle]: (sssc) => format(sssc.getLiteralText()),
|
40
|
+
[SyntaxKind.TemplateTail]: (sssc) => format(sssc.getLiteralText()),
|
39
41
|
}) ?? String(`%${i++}`);
|
40
42
|
});
|
41
43
|
});
|
@@ -57,10 +59,12 @@ async function procFile(p, filePath, funckey) {
|
|
57
59
|
return dats;
|
58
60
|
}
|
59
61
|
async function scanI18n(i18nDataDir, include, exclude, funckey) {
|
62
|
+
const TsMorph = await (0, DynImport_1.importTsMorph)();
|
63
|
+
const { Project } = TsMorph;
|
60
64
|
const fixedKey = typeof funckey == 'string' ? [funckey] : funckey;
|
61
65
|
const filePaths = (await utils_1.UtilFT.fileSearchGlob(process.cwd(), include, { ingore: exclude }))
|
62
66
|
.filter(p => ['.ts', '.tsx'].includes(pathe_1.default.parse(p).ext));
|
63
|
-
const project = new
|
67
|
+
const project = new Project();
|
64
68
|
await utils_1.SI18n.init(i18nDataDir, '*');
|
65
69
|
//console.log(filePaths);
|
66
70
|
(await Promise.all(filePaths.map(p => procFile(project, p, fixedKey))))
|
@@ -41,7 +41,7 @@ const CmdGenTemplate = (program) => program
|
|
41
41
|
.command("Gen-Template")
|
42
42
|
.alias("gentemplate")
|
43
43
|
.description("生成项目模板")
|
44
|
-
.argument("<template>", "项目模板 可用 base|electron")
|
44
|
+
.argument("<template>", "项目模板 可用 base|cjs|electron")
|
45
45
|
.requiredOption("-n, --projectName <name>", "项目名称")
|
46
46
|
.requiredOption("-d, --projectDescription <description>", "项目描述")
|
47
47
|
.requiredOption("-a, --authorName <name>", "作者名")
|
@@ -51,15 +51,18 @@ const CmdGenTemplate = (program) => program
|
|
51
51
|
utils_1.SLogger.error(`模板 ${templateName} 不存在`);
|
52
52
|
const projectPath = pathe_1.default.join(process.cwd(), opt.projectName);
|
53
53
|
await utils_1.UtilFT.ensurePathExists(projectPath, { dir: true });
|
54
|
+
//复制模板
|
54
55
|
await copyData(templatePath, projectPath);
|
55
|
-
|
56
|
-
if (await utils_1.UtilFT.pathExists(pathe_1.default.join(projectPath, "gitignore")))
|
57
|
-
await fs_1.default.promises.rename(pathe_1.default.join(projectPath, "gitignore"), pathe_1.default.join(projectPath, ".gitignore"));
|
56
|
+
//修改package.json
|
58
57
|
const packageJson = await utils_1.UtilFT.loadJSONFile(pathe_1.default.join(projectPath, 'package.json'));
|
59
58
|
packageJson.name = opt.projectName;
|
60
59
|
packageJson.description = opt.projectDescription;
|
61
60
|
packageJson.author = opt.authorName;
|
62
61
|
await utils_1.UtilFT.writeJSONFile(pathe_1.default.join(projectPath, 'package.json'), packageJson);
|
62
|
+
//安装依赖
|
63
|
+
await installPackage(projectPath, ['@zwa73/utils'], ['@types/node']);
|
64
|
+
if (await utils_1.UtilFT.pathExists(pathe_1.default.join(projectPath, "gitignore")))
|
65
|
+
await fs_1.default.promises.rename(pathe_1.default.join(projectPath, "gitignore"), pathe_1.default.join(projectPath, ".gitignore"));
|
63
66
|
switch (templateName) {
|
64
67
|
case 'base': break;
|
65
68
|
case 'electron': break;
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.CmdScanDups = void 0;
|
7
7
|
const utils_1 = require("@zwa73/utils");
|
8
8
|
const pathe_1 = __importDefault(require("pathe"));
|
9
|
-
const cli_progress_1 = __importDefault(require("cli-progress"));
|
10
9
|
const fs_1 = __importDefault(require("fs"));
|
10
|
+
const DynImport_1 = require("../DynImport");
|
11
11
|
const { tap } = utils_1.UtilFP;
|
12
12
|
/**hashlist转为dupmap */
|
13
13
|
const reduce2Dupmap = (list) => list.reduce((acc, cur) => {
|
@@ -61,10 +61,11 @@ const CmdScanDups = (program) => program
|
|
61
61
|
? [process.cwd()]
|
62
62
|
: dir.map(d => pathe_1.default.isAbsolute(d) ? d : pathe_1.default.join(process.cwd(), d));
|
63
63
|
// 添加一个多步进度条
|
64
|
-
const
|
64
|
+
const cliProgress = await (0, DynImport_1.importCliProgress)();
|
65
|
+
const progressBar = new cliProgress.MultiBar({
|
65
66
|
clearOnComplete: true, hideCursor: true,
|
66
67
|
format: " {task} [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} | {status}",
|
67
|
-
},
|
68
|
+
}, cliProgress.Presets.shades_classic);
|
68
69
|
// 文件结构进度条
|
69
70
|
const structProgress = struct ? progressBar.create(1, 0, { task: "结构扫描", status: "准备中..." }) : undefined;
|
70
71
|
// 采样哈希进度条
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import type { getProgramFromFiles, buildGenerator } from 'typescript-json-schema';
|
2
|
+
import type { Project, SyntaxKind } from 'ts-morph';
|
3
|
+
import type cliProgress from "cli-progress";
|
4
|
+
type TJSInstance = {
|
5
|
+
getProgramFromFiles: typeof getProgramFromFiles;
|
6
|
+
buildGenerator: typeof buildGenerator;
|
7
|
+
};
|
8
|
+
type TsMorphInstance = {
|
9
|
+
Project: typeof Project;
|
10
|
+
SyntaxKind: typeof SyntaxKind;
|
11
|
+
};
|
12
|
+
export declare function importTsMorph(): Promise<TsMorphInstance>;
|
13
|
+
export declare function importTJS(): Promise<TJSInstance>;
|
14
|
+
export declare function importCliProgress(): Promise<typeof cliProgress>;
|
15
|
+
export {};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.importTsMorph = importTsMorph;
|
4
|
+
exports.importTJS = importTJS;
|
5
|
+
exports.importCliProgress = importCliProgress;
|
6
|
+
const utils_1 = require("@zwa73/utils");
|
7
|
+
async function importTsMorph() {
|
8
|
+
return await utils_1.UtilFunc.dynamicImport("ts-morph");
|
9
|
+
}
|
10
|
+
async function importTJS() {
|
11
|
+
return await utils_1.UtilFunc.dynamicImport("typescript-json-schema");
|
12
|
+
}
|
13
|
+
async function importCliProgress() {
|
14
|
+
return await utils_1.UtilFunc.dynamicImport("cli-progress");
|
15
|
+
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { AnyFunc } from "@zwa73/utils";
|
2
|
-
import { SyntaxKind, KindToNodeMappings, Node } from "ts-morph";
|
2
|
+
import type { SyntaxKind, KindToNodeMappings, Node } from "ts-morph";
|
3
3
|
export declare namespace UtilAst {
|
4
4
|
/**匹配Node的类型进行处理 无法匹配时返回undefined
|
5
5
|
* @param node - ast节点
|
@@ -1,37 +1,13 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
-
}) : function(o, v) {
|
16
|
-
o["default"] = v;
|
17
|
-
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
-
if (mod && mod.__esModule) return mod;
|
20
|
-
var result = {};
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
-
__setModuleDefault(result, mod);
|
23
|
-
return result;
|
24
|
-
};
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
4
|
};
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
6
|
exports.UtilDT = void 0;
|
30
7
|
const pathe_1 = __importDefault(require("pathe"));
|
31
|
-
const
|
32
|
-
const fs = __importStar(require("fs"));
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
33
9
|
const utils_1 = require("@zwa73/utils");
|
34
|
-
const
|
10
|
+
const DynImport_1 = require("./DynImport");
|
35
11
|
var UtilDT;
|
36
12
|
(function (UtilDT) {
|
37
13
|
/**生成匹配的文件的所有type的schema
|
@@ -47,6 +23,9 @@ var UtilDT;
|
|
47
23
|
* @param opt.excludeTypes - 排除的types正则匹配数组
|
48
24
|
*/
|
49
25
|
async function generateSchema(dir, opt) {
|
26
|
+
//导入
|
27
|
+
const TJS = await (0, DynImport_1.importTJS)();
|
28
|
+
const TsMorph = await (0, DynImport_1.importTsMorph)();
|
50
29
|
//生成
|
51
30
|
const settings = {
|
52
31
|
required: true,
|
@@ -65,10 +44,10 @@ var UtilDT;
|
|
65
44
|
//const schema = TJS.generateSchema(program, opt?.typeName??"*", settings,undefined,gener) as JObject;
|
66
45
|
const it = opt?.includeTypes?.map(t => new RegExp(t)) ?? [/.*/];
|
67
46
|
const et = opt?.excludeTypes?.map(t => new RegExp(t)) ?? [];
|
68
|
-
const p = new
|
47
|
+
const p = new TsMorph.Project();
|
69
48
|
const types = files.map(fp => p
|
70
49
|
.addSourceFileAtPath(fp)
|
71
|
-
.getDescendantsOfKind(
|
50
|
+
.getDescendantsOfKind(TsMorph.SyntaxKind.TypeAliasDeclaration)
|
72
51
|
.map(d => d.getName())).flat();
|
73
52
|
const list = gener.getUserSymbols()
|
74
53
|
.filter(t => types.some(i => i === t))
|
@@ -89,8 +68,8 @@ var UtilDT;
|
|
89
68
|
function procSchema(schema, coverDefine) {
|
90
69
|
//覆盖
|
91
70
|
coverObj(schema["definitions"], coverDefine);
|
92
|
-
|
93
|
-
schema = JSON.parse(JSON.stringify(schema).replace(/\^\.\*SchemaString\$/g,
|
71
|
+
////替换SchemaString标识符
|
72
|
+
//schema = JSON.parse(JSON.stringify(schema).replace(/\^\.\*SchemaString\$/g,'^.*$'));
|
94
73
|
return schema;
|
95
74
|
}
|
96
75
|
/**展开schema以供使用 */
|
@@ -174,7 +153,7 @@ var UtilDT;
|
|
174
153
|
: opt?.filePath.map((filepath) => filepath)
|
175
154
|
: [basePath.replace(/(.+)\.macro\.(js|ts|cjs|mjs)$/, "$1.$2")];
|
176
155
|
};
|
177
|
-
const readFile = async (basePath) => (await
|
156
|
+
const readFile = async (basePath) => (await fs_1.default.promises.readFile(basePath, 'utf-8')).replaceAll("\r\n", "\n");
|
178
157
|
const parseCodeText = async (codeText, opt) => {
|
179
158
|
const strText = typeof codeText === "function" ? await codeText(opt) : codeText;
|
180
159
|
return strText.split('\n').map((line) => `${opt.inent}${line}`).join('\n');
|
@@ -229,7 +208,7 @@ var UtilDT;
|
|
229
208
|
regex.lastIndex += fileText.length - ol;
|
230
209
|
}
|
231
210
|
if (hasMatch)
|
232
|
-
await
|
211
|
+
await fs_1.default.promises.writeFile(filePath, fileText, 'utf-8');
|
233
212
|
else if (!opt?.glob)
|
234
213
|
utils_1.SLogger.error(`UtilDT.regionMacro 无法找到区域 ${regionId}`);
|
235
214
|
};
|
@@ -287,7 +266,7 @@ var UtilDT;
|
|
287
266
|
regex.lastIndex += fileText.length - ol;
|
288
267
|
}
|
289
268
|
if (hasMatch)
|
290
|
-
await
|
269
|
+
await fs_1.default.promises.writeFile(filePath, fileText, 'utf-8');
|
291
270
|
else if (!opt?.glob)
|
292
271
|
utils_1.SLogger.error(`UtilDT.commentMacro 无法找到注释 ${commentId}`);
|
293
272
|
};
|
@@ -316,7 +295,7 @@ var UtilDT;
|
|
316
295
|
inent: '',
|
317
296
|
filePath
|
318
297
|
});
|
319
|
-
await
|
298
|
+
await fs_1.default.promises.writeFile(filePath, parseCode, 'utf-8');
|
320
299
|
};
|
321
300
|
plist.push(utils_1.PromiseQueue.enqueue(pathe_1.default.normalize(filePath), queuefunc));
|
322
301
|
}
|
@@ -10,10 +10,10 @@ const pathe_1 = __importDefault(require("pathe"));
|
|
10
10
|
var UtilMacro;
|
11
11
|
(function (UtilMacro) {
|
12
12
|
/**根据注释批量生成导出
|
13
|
-
* @param glob - 应用的golb
|
13
|
+
* @param glob - 应用的golb 默认 src\/**\/index.ts
|
14
14
|
* @example
|
15
15
|
*/
|
16
|
-
function exportComment(glob) {
|
16
|
+
function exportComment(glob = 'src/**/index.ts') {
|
17
17
|
(0, QuickFunc_1.commentMacro)(/export (\S*)/, async ({ filePath, matchId, execArr }) => {
|
18
18
|
const basedir = pathe_1.default.dirname(filePath);
|
19
19
|
const result = (await utils_1.UtilFT.fileSearchGlob(basedir, execArr[1]))
|
package/package.json
CHANGED
@@ -1,14 +1,8 @@
|
|
1
1
|
{
|
2
2
|
"name": "@zwa73/dev-utils",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.89",
|
4
4
|
"description": "编译与调试工具",
|
5
|
-
"
|
6
|
-
".": {
|
7
|
-
"require": "./dist/cjs/index.js",
|
8
|
-
"import": "./dist/mjs/index.js"
|
9
|
-
}
|
10
|
-
},
|
11
|
-
"types": "./dist/mjs/index.d.ts",
|
5
|
+
"main": "dist/index.js",
|
12
6
|
"scripts": {
|
13
7
|
"test": "jest",
|
14
8
|
"release": "powershell scripts/release",
|
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
|
-
}
|
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;
|