@zwa73/dev-utils 1.0.80 → 1.0.82

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.
Files changed (176) hide show
  1. package/bin/cli +1 -1
  2. package/data/template/base/gitignore +3 -0
  3. package/data/template/base/package.json +25 -0
  4. package/data/template/base/scripts/compile.ps1 +8 -0
  5. package/data/template/base/src/macro.macro.ts +6 -0
  6. package/data/template/base/tsconfig.cjs.json +9 -0
  7. package/{tsconfig.json → data/template/base/tsconfig.json} +2 -2
  8. package/data/template/base/tsconfig.mjs.json +10 -0
  9. package/dist/cjs/Command/GenTemplate.d.ts +3 -0
  10. package/dist/cjs/Command/GenTemplate.js +25 -0
  11. package/dist/{Command → cjs/Command}/Route.js +2 -4
  12. package/dist/{Command → cjs/Command}/RouteInterface.d.ts +4 -0
  13. package/dist/{Command → cjs/Command}/RouteInterface.js +6 -2
  14. package/dist/cjs/Generator/Common.d.ts +2 -0
  15. package/dist/cjs/Generator/Common.js +65 -0
  16. package/dist/cjs/Generator/base/index.d.ts +3 -0
  17. package/dist/cjs/Generator/base/index.js +4 -0
  18. package/dist/cjs/Generator/electron/index.d.ts +3 -0
  19. package/dist/cjs/Generator/electron/index.js +4 -0
  20. package/dist/cjs/test/testFileMacro.d.ts +1 -0
  21. package/dist/cjs/test/testFileMacro.js +1 -0
  22. package/dist/cjs/test/testGlobMacro.d.ts +1 -0
  23. package/dist/cjs/test/testGlobMacro.js +2 -0
  24. package/dist/cjs/test/testRegex.d.ts +1 -0
  25. package/dist/cjs/test/testRegex.js +3 -0
  26. package/dist/cjs/test/testRegex.macro.d.ts +1 -0
  27. package/dist/cjs/test/testRegex.macro.js +11 -0
  28. package/dist/cjs/test/testRegexa.d.ts +1 -0
  29. package/dist/cjs/test/testRegexa.js +1 -0
  30. package/dist/cjs/test/testRegexa.macro.d.ts +1 -0
  31. package/dist/cjs/test/testRegexa.macro.js +4 -0
  32. package/dist/mjs/Command/ExpandMacro.d.ts +3 -0
  33. package/dist/mjs/Command/ExpandMacro.js +16 -0
  34. package/dist/mjs/Command/GenI18n.d.ts +3 -0
  35. package/dist/mjs/Command/GenI18n.js +75 -0
  36. package/dist/mjs/Command/GenSchema.d.ts +3 -0
  37. package/dist/mjs/Command/GenSchema.js +22 -0
  38. package/dist/mjs/Command/GenTemplate.d.ts +3 -0
  39. package/dist/mjs/Command/GenTemplate.js +18 -0
  40. package/dist/mjs/Command/MapPath.d.ts +3 -0
  41. package/dist/mjs/Command/MapPath.js +64 -0
  42. package/dist/mjs/Command/Node.d.ts +3 -0
  43. package/dist/mjs/Command/Node.js +14 -0
  44. package/dist/mjs/Command/Release.d.ts +3 -0
  45. package/dist/mjs/Command/Release.js +88 -0
  46. package/dist/mjs/Command/Route.d.ts +1 -0
  47. package/dist/mjs/Command/Route.js +20 -0
  48. package/dist/mjs/Command/RouteInterface.d.ts +24 -0
  49. package/{src/Command/RouteInterface.ts → dist/mjs/Command/RouteInterface.js} +58 -63
  50. package/dist/mjs/Command/ScanDups.d.ts +3 -0
  51. package/dist/mjs/Command/ScanDups.js +43 -0
  52. package/dist/mjs/Command/index.d.ts +1 -0
  53. package/dist/mjs/Command/index.js +1 -0
  54. package/dist/mjs/Generator/Common.d.ts +2 -0
  55. package/dist/mjs/Generator/Common.js +58 -0
  56. package/dist/mjs/Generator/base/index.d.ts +3 -0
  57. package/dist/mjs/Generator/base/index.js +2 -0
  58. package/dist/mjs/Generator/electron/index.d.ts +3 -0
  59. package/dist/mjs/Generator/electron/index.js +2 -0
  60. package/dist/mjs/Macro.macro.d.ts +1 -0
  61. package/dist/mjs/Macro.macro.js +2 -0
  62. package/dist/mjs/QuickFunc.d.ts +2 -0
  63. package/dist/mjs/QuickFunc.js +2 -0
  64. package/dist/mjs/UtilAst.d.ts +13 -0
  65. package/dist/mjs/UtilAst.js +15 -0
  66. package/dist/mjs/UtilDevTool.d.ts +99 -0
  67. package/dist/mjs/UtilDevTool.js +296 -0
  68. package/dist/mjs/UtilInterface.d.ts +4 -0
  69. package/dist/mjs/UtilInterface.js +1 -0
  70. package/dist/mjs/UtilMacro.d.ts +7 -0
  71. package/dist/mjs/UtilMacro.js +23 -0
  72. package/dist/mjs/index.d.ts +5 -0
  73. package/dist/mjs/index.js +5 -0
  74. package/dist/mjs/test/testFileMacro.d.ts +1 -0
  75. package/dist/mjs/test/testFileMacro.js +1 -0
  76. package/dist/mjs/test/testGlobMacro.d.ts +1 -0
  77. package/dist/mjs/test/testGlobMacro.js +2 -0
  78. package/dist/mjs/test/testRegex.d.ts +1 -0
  79. package/dist/mjs/test/testRegex.js +2 -0
  80. package/dist/mjs/test/testRegex.macro.d.ts +1 -0
  81. package/dist/mjs/test/testRegex.macro.js +9 -0
  82. package/dist/mjs/test/testRegexa.d.ts +1 -0
  83. package/dist/mjs/test/testRegexa.js +1 -0
  84. package/dist/mjs/test/testRegexa.macro.d.ts +1 -0
  85. package/dist/mjs/test/testRegexa.macro.js +2 -0
  86. package/package.json +18 -5
  87. package/UnableTypes.txt +0 -1
  88. package/data/init/index.d.ts +0 -1
  89. package/data/init/index.js +0 -1
  90. package/data/init/scripts/compile.ps1 +0 -5
  91. package/data/init/tsconfig.compile.json +0 -4
  92. package/data/init/tsconfig.json +0 -22
  93. package/dist/Command/Init.d.ts +0 -3
  94. package/dist/Command/Init.js +0 -82
  95. package/dist/Command/InitElectron.d.ts +0 -3
  96. package/dist/Command/InitElectron.js +0 -64
  97. package/index.d.ts +0 -1
  98. package/index.js +0 -1
  99. package/jest.config.js +0 -16
  100. package/scripts/compile.ps1 +0 -5
  101. package/scripts/postinstall.js +0 -54
  102. package/scripts/watch.ps1 +0 -10
  103. package/src/Command/ExpandMacro.ts +0 -18
  104. package/src/Command/GenI18n.ts +0 -85
  105. package/src/Command/GenSchema.ts +0 -24
  106. package/src/Command/Init.ts +0 -65
  107. package/src/Command/InitElectron.ts +0 -42
  108. package/src/Command/MapPath.ts +0 -64
  109. package/src/Command/Node.ts +0 -16
  110. package/src/Command/Release.ts +0 -96
  111. package/src/Command/Route.ts +0 -24
  112. package/src/Command/ScanDups.ts +0 -47
  113. package/src/Command/index.ts +0 -1
  114. package/src/Macro.macro.ts +0 -4
  115. package/src/QuickFunc.ts +0 -7
  116. package/src/UtilAst.ts +0 -25
  117. package/src/UtilDevTool.ts +0 -345
  118. package/src/UtilInterface.ts +0 -5
  119. package/src/UtilMacro.ts +0 -23
  120. package/src/index.ts +0 -5
  121. package/test.js +0 -29
  122. package/tsconfig.compile.json +0 -4
  123. /package/{scripts → data/template/base/scripts}/release.ps1 +0 -0
  124. /package/data/{init → template/base}/scripts/watch.ps1 +0 -0
  125. /package/data/{init → template/base}/src/index.ts +0 -0
  126. /package/data/{InitElectron → template/electron}/.eslintrc.js +0 -0
  127. /package/data/{InitElectron → template/electron}/forge.config.ts +0 -0
  128. /package/data/{InitElectron → template/electron}/gitignore +0 -0
  129. /package/data/{InitElectron → template/electron}/package-lock.json +0 -0
  130. /package/data/{InitElectron → template/electron}/package.json +0 -0
  131. /package/data/{InitElectron → template/electron}/src/Backend/BridgeBackend.ts +0 -0
  132. /package/data/{InitElectron → template/electron}/src/Backend/index.ts +0 -0
  133. /package/data/{InitElectron → template/electron}/src/Frontend/Base.tsx +0 -0
  134. /package/data/{InitElectron → template/electron}/src/Frontend/ContextProxy.ts +0 -0
  135. /package/data/{InitElectron → template/electron}/src/Frontend/index.ts +0 -0
  136. /package/data/{InitElectron → template/electron}/src/app.tsx +0 -0
  137. /package/data/{InitElectron → template/electron}/src/index.html +0 -0
  138. /package/data/{InitElectron → template/electron}/src/index.ts +0 -0
  139. /package/data/{InitElectron → template/electron}/src/preload.ts +0 -0
  140. /package/data/{InitElectron → template/electron}/src/renderer.ts +0 -0
  141. /package/data/{InitElectron → template/electron}/tsconfig.json +0 -0
  142. /package/data/{InitElectron → template/electron}/webpack.main.config.ts +0 -0
  143. /package/data/{InitElectron → template/electron}/webpack.plugins.ts +0 -0
  144. /package/data/{InitElectron → template/electron}/webpack.renderer.config.ts +0 -0
  145. /package/data/{InitElectron → template/electron}/webpack.rules.ts +0 -0
  146. /package/dist/{Command → cjs/Command}/ExpandMacro.d.ts +0 -0
  147. /package/dist/{Command → cjs/Command}/ExpandMacro.js +0 -0
  148. /package/dist/{Command → cjs/Command}/GenI18n.d.ts +0 -0
  149. /package/dist/{Command → cjs/Command}/GenI18n.js +0 -0
  150. /package/dist/{Command → cjs/Command}/GenSchema.d.ts +0 -0
  151. /package/dist/{Command → cjs/Command}/GenSchema.js +0 -0
  152. /package/dist/{Command → cjs/Command}/MapPath.d.ts +0 -0
  153. /package/dist/{Command → cjs/Command}/MapPath.js +0 -0
  154. /package/dist/{Command → cjs/Command}/Node.d.ts +0 -0
  155. /package/dist/{Command → cjs/Command}/Node.js +0 -0
  156. /package/dist/{Command → cjs/Command}/Release.d.ts +0 -0
  157. /package/dist/{Command → cjs/Command}/Release.js +0 -0
  158. /package/dist/{Command → cjs/Command}/Route.d.ts +0 -0
  159. /package/dist/{Command → cjs/Command}/ScanDups.d.ts +0 -0
  160. /package/dist/{Command → cjs/Command}/ScanDups.js +0 -0
  161. /package/dist/{Command → cjs/Command}/index.d.ts +0 -0
  162. /package/dist/{Command → cjs/Command}/index.js +0 -0
  163. /package/dist/{Macro.macro.d.ts → cjs/Macro.macro.d.ts} +0 -0
  164. /package/dist/{Macro.macro.js → cjs/Macro.macro.js} +0 -0
  165. /package/dist/{QuickFunc.d.ts → cjs/QuickFunc.d.ts} +0 -0
  166. /package/dist/{QuickFunc.js → cjs/QuickFunc.js} +0 -0
  167. /package/dist/{UtilAst.d.ts → cjs/UtilAst.d.ts} +0 -0
  168. /package/dist/{UtilAst.js → cjs/UtilAst.js} +0 -0
  169. /package/dist/{UtilDevTool.d.ts → cjs/UtilDevTool.d.ts} +0 -0
  170. /package/dist/{UtilDevTool.js → cjs/UtilDevTool.js} +0 -0
  171. /package/dist/{UtilInterface.d.ts → cjs/UtilInterface.d.ts} +0 -0
  172. /package/dist/{UtilInterface.js → cjs/UtilInterface.js} +0 -0
  173. /package/dist/{UtilMacro.d.ts → cjs/UtilMacro.d.ts} +0 -0
  174. /package/dist/{UtilMacro.js → cjs/UtilMacro.js} +0 -0
  175. /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
  176. /package/dist/{index.js → cjs/index.js} +0 -0
package/jest.config.js DELETED
@@ -1,16 +0,0 @@
1
-
2
-
3
-
4
-
5
- module.exports = {
6
- roots: ['./jest'],
7
- transform: {
8
- '^.+\\.tsx?$': 'ts-jest',
9
- },
10
- moduleNameMapper: {
11
- '^@src/(.*)$': '<rootDir>/dist/$1',
12
- '^@/(.*)$': '<rootDir>/$1',
13
- '^@$': '<rootDir>/index'
14
- },
15
- moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
16
- };
@@ -1,5 +0,0 @@
1
- Write-Output 开始删除原dist
2
- Remove-Item -Recurse -Force dist
3
- Write-Output 开始编译
4
- tsc -p tsconfig.compile.json
5
- tsc-alias -p tsconfig.compile.json
@@ -1,54 +0,0 @@
1
- const path = require('path');
2
- const { UtilFT } = require("@zwa73/utils");
3
-
4
- const PACKAGE_PATH = path.join(__dirname,'..','package.json');
5
- const VERSION_PATH = path.join(__dirname,"..","..","version.json");
6
- //提示表
7
- const INFO_TABLE = {
8
- "1.0.33":"zcli Build-Macro Build-Schema 更名为 Expand-Macro Gen-Schema",
9
- "1.0.36":"$macro 更名为 regionMacro"
10
- }
11
-
12
- const PKG_NAME = "dev-utils";
13
-
14
- // 将版本号转换为可以比较的数字
15
- function versionToNumber(version) {
16
- if(version==undefined) return 0;
17
- return version.split('.').map(Number).reduce((acc, val) => acc * 1000 + val);
18
- }
19
-
20
- //显示提示
21
- function showUpgradeMessages(prevVersion, currentVersion) {
22
- const prevVersionNumber = versionToNumber(prevVersion);
23
- const currentVersionNumber = versionToNumber(currentVersion);
24
- let hasOut = false;
25
- // 遍历infoTable中的所有版本
26
- for (const version in INFO_TABLE) {
27
- const versionNumber = versionToNumber(version);
28
- // 如果用户的上一个版本低于这个版本,而当前版本高于或等于这个版本
29
- if (versionNumber > prevVersionNumber && versionNumber <= currentVersionNumber) {
30
- // 显示这个版本的提示信息
31
- log(INFO_TABLE[version]);
32
- hasOut=true;
33
- }
34
- }
35
- return hasOut;
36
- }
37
-
38
- const log = ()=>undefined;
39
-
40
- async function main(){
41
- const packageTable = await UtilFT.loadJSONFile(PACKAGE_PATH);
42
- const currentVersion = packageTable.version;
43
- await UtilFT.ensurePathExists(VERSION_PATH);
44
- const versionTable = await UtilFT.loadJSONFile(VERSION_PATH,{default:{}});
45
- const prevVersion = versionTable[PKG_NAME]?.version ?? "10000.0.0";
46
-
47
- log(`${currentVersion} 版本已安装`);
48
- // 使用这个函数来显示升级信息
49
- const hasOut = showUpgradeMessages(prevVersion, currentVersion);
50
-
51
- const ntable = Object.assign({},versionTable,{[PKG_NAME]:{version:currentVersion}});
52
- await UtilFT.writeJSONFile(VERSION_PATH, ntable);
53
- }
54
- main()
package/scripts/watch.ps1 DELETED
@@ -1,10 +0,0 @@
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"
@@ -1,18 +0,0 @@
1
- import { Command } from "commander";
2
- import { UtilDT } from "@/src/UtilDevTool";
3
-
4
- /**构造macro */
5
- export const CmdExpandMacro = (program:Command) => program
6
- .command("Expand-Macro")
7
- .alias("expandmacro")
8
- .description("根据macro生成代码")
9
- .option("-i, --include <glob>", "包含的glob 默认 src/**/*.macro.ts","src/**/*.macro.ts")
10
- .option("-g, --exclude <glob>", "忽略的glob")
11
- .option("-p, --project <path>", "tsconfig路径 默认tsconfig.json","tsconfig.json")
12
- .action(async (opt) => {
13
- await UtilDT.matchNode(process.cwd(), {
14
- include: opt.include,
15
- exclude: opt.ignore,
16
- project: opt.project,
17
- });
18
- });
@@ -1,85 +0,0 @@
1
- import { Command } from "commander";
2
- import { AnyFunc, I18nTextData, SI18n, UtilFT, ivk } from "@zwa73/utils";
3
- import { Project,SyntaxKind } from 'ts-morph';
4
- import { UtilAst } from "@/src/UtilAst";
5
- import path from 'pathe';
6
-
7
- function format(str:string){
8
- return str.replace(/\\(.)/g,'$1').replace(/%/g,'\\%');
9
- }
10
-
11
- async function procFile(p:Project,filePath:string,funckey:string[]){
12
- const date = new Date().toISOString();
13
- //const content = await fs.promises.readFile(filePath,'utf-8');
14
- const b = p.addSourceFileAtPath(filePath);
15
- //const b = p.createSourceFile(path.relative(process.cwd(),filePath),content,{overwrite:true});
16
- const ds = b.getDescendantsOfKind(SyntaxKind.TaggedTemplateExpression);
17
- const dats:I18nTextData[] = [];
18
- for(const d of ds){
19
- if(!funckey.includes(d.getTag().getText())) continue;
20
- const template = d.getTemplate();
21
- let result = '';
22
- let i=0;
23
- UtilAst.withKind(template,{
24
- [SyntaxKind.NoSubstitutionTemplateLiteral]:(t)=>result+=format(t.getLiteralText()),
25
- [SyntaxKind.TemplateExpression]:(t)=>{
26
- t.getChildren().forEach((c)=>{
27
- UtilAst.withKind(c,{
28
- [SyntaxKind.TemplateHead]:(sc)=>result += format(sc.getLiteralText()),
29
- [SyntaxKind.SyntaxList]:(sc)=>{
30
- sc.getChildrenOfKind(SyntaxKind.TemplateSpan).forEach((span)=>{
31
- span.getChildren().forEach((ssc)=>{
32
- result += UtilAst.withKind(ssc,{
33
- [SyntaxKind.TemplateMiddle]:(sssc)=>format(sssc.getLiteralText()),
34
- [SyntaxKind.TemplateTail] :(sssc)=>format(sssc.getLiteralText()),
35
- })??String(`%${i++}`);
36
- })
37
- })
38
- },
39
- });
40
- });
41
- }
42
- });
43
- const pos = b.getLineAndColumnAtPos(d.getStart());
44
- const dat:I18nTextData={
45
- original:result,
46
- scan_time:date,
47
- position: `${filePath}:${pos.line}:${pos.column}`,
48
- lang_table:{},
49
- source:"Ast"
50
- }
51
- dats.push(dat);
52
- }
53
- return dats;
54
- }
55
-
56
- async function scanI18n(i18nDataDir:string,include:string,exclude:string,funckey:string[]|string){
57
- const fixedKey = typeof funckey == 'string' ? [funckey] : funckey;
58
- const filePaths = (await UtilFT.fileSearchGlob(process.cwd(),include,{ingore:exclude}))
59
- .filter(p=>['.ts','.tsx'].includes(path.parse(p).ext));
60
- const project = new Project();
61
- await SI18n.init(i18nDataDir,'*');
62
- //console.log(filePaths);
63
- (await Promise.all(filePaths.map(p=>procFile(project,p,fixedKey))))
64
- .flat().forEach(dat=>SI18n.addOriginalText(dat));
65
- await SI18n.saveTable();
66
- }
67
-
68
- /**生成i18n */
69
- export const CmdGenI18n = (program:Command) => program
70
- .command("Gen-I18n")
71
- .alias("geni18n")
72
- .description("根据文件行为树生成i18n数据")
73
- .option("-o, --output <path>" , "输出的数据目录位置 默认 i18n",'i18n')
74
- .option("-i, --include <glob>", "包含的glob 默认 src/**/*.ts","src/**/*.ts")
75
- .option("-g, --exclude <glob>", "忽略的glob")
76
- .option("-f, --funckey <string|strings>", "扫描的目标函数名, 可传入逗号分隔数组, 默认 t",
77
- (i:string)=>i.split(','),['t'])
78
- .action(async (opt) => {
79
- await scanI18n(
80
- opt.output ,
81
- opt.include,
82
- opt.exclude,
83
- opt.funckey,
84
- );
85
- });
@@ -1,24 +0,0 @@
1
- import { Command } from "commander";
2
- import { UtilDT } from "@/src/UtilDevTool";
3
-
4
- /**生成schema */
5
- export const CmdGenSchema = (program:Command) => program
6
- .command("Gen-Schema")
7
- .alias("genschema")
8
- .description("生成匹配的文件的所有type的schema")
9
- .option("-i, --include <glob>", "包含的glob 默认 src/**/*.schema.ts","src/**/*.schema.ts")
10
- .option("-g, --exclude <glob>", "忽略的glob")
11
- .option("-p, --project <path>", "tsconfig路径 默认tsconfig.json","tsconfig.json")
12
- .option("-o, --out <dir>", "schema输出路径目录 默认 ./schema/")
13
- .option("-it, --include-types <regexp[]>", "包含的types正则匹配数组, 传入逗号分隔数组",(i:string)=>i.split(','))
14
- .option("-et, --exclude-types <regexp[]>", "排除的types正则匹配数组, 传入逗号分隔数组",(i:string)=>i.split(','))
15
- .action(async (opt) => {
16
- await UtilDT.generateSchema(process.cwd(), {
17
- include : opt.include,
18
- exclude : opt.exclude,
19
- project : opt.project,
20
- outDir : opt.out,
21
- includeTypes: opt.includeTypes,
22
- excludeTypes: opt.excludeTypes
23
- });
24
- });
@@ -1,65 +0,0 @@
1
- import { Command } from 'commander';
2
- import * as fs from 'fs';
3
- import path from 'pathe';
4
-
5
- import { SLogger, UtilFT, UtilFunc } from '@zwa73/utils';
6
-
7
- import { checkProject, DATA_PATH, MIRROR_SOURCE, PROJECT_PATH } from './RouteInterface';
8
-
9
-
10
-
11
-
12
-
13
- const InitDataPath = path.join(DATA_PATH,'init');
14
-
15
- /**复制基础文件 */
16
- async function copyData() {
17
- const filelist = await fs.promises.readdir(InitDataPath);
18
- const plist = filelist.map(async (fileName)=>{
19
- SLogger.info(`正在复制 ${fileName}`);
20
- const filePath = path.join(InitDataPath,fileName);
21
- const targetPath = path.join(PROJECT_PATH,fileName);
22
- if(!await UtilFT.pathExists(targetPath))
23
- await fs.promises.cp(filePath,targetPath,{recursive:true});
24
- else
25
- SLogger.info(`${fileName} 已存在 跳过`);
26
- return null;
27
- })
28
- await Promise.all(plist);
29
- }
30
-
31
- /**安装npm包 */
32
- async function installPackage() {
33
- const install = async (name:string)=>
34
- await UtilFunc.exec(`npm i --registry ${MIRROR_SOURCE} ${name}`);
35
- const installdev = async (name:string)=>
36
- await UtilFunc.exec(`npm i --registry ${MIRROR_SOURCE} --save-dev ${name}`);
37
- const packageList = ['@zwa73/utils'];
38
- const devPackList = [
39
- '@zwa73/dev-utils',
40
- '@types/fluent-ffmpeg',
41
- '@types/node',
42
- ];
43
- for(const name of packageList){
44
- SLogger.info(`正在安装 ${name}`);
45
- await install(name);
46
- }
47
- for(const name of devPackList){
48
- SLogger.info(`正在安装 ${name}`);
49
- await installdev(name);
50
- }
51
- }
52
-
53
- /**对项目进行初始化 */
54
- export const CmdInit = (program:Command)=>program
55
- .command('Init')
56
- .alias('init')
57
- .description('对当前目录进行项目初始化')
58
- .action(async (opt) => {
59
- checkProject();
60
- SLogger.info(`开始初始化设置当前目录 ${PROJECT_PATH}`);
61
- await Promise.all([
62
- copyData(),
63
- installPackage(),
64
- ]);
65
- });
@@ -1,42 +0,0 @@
1
- import { Command } from 'commander';
2
- import * as fs from 'fs';
3
- import path from 'pathe';
4
-
5
- import { SLogger, UtilFT, UtilFunc } from '@zwa73/utils';
6
-
7
- import { checkProject, DATA_PATH, MIRROR_SOURCE, PROJECT_PATH } from './RouteInterface';
8
-
9
-
10
- const InitDataPath = path.join(DATA_PATH,'InitElectron');
11
-
12
- /**复制基础文件 */
13
- async function copyData() {
14
- const filelist = await fs.promises.readdir(InitDataPath);
15
- const plist = filelist.map(async (fileName)=>{
16
- SLogger.info(`正在复制 ${fileName}`);
17
- const filePath = path.join(InitDataPath,fileName);
18
- const targetPath = path.join(PROJECT_PATH,fileName);
19
- if(!await UtilFT.pathExists(targetPath))
20
- await fs.promises.cp(filePath,targetPath,{recursive:true});
21
- else
22
- SLogger.info(`${fileName} 已存在 跳过`);
23
- return null;
24
- })
25
- await Promise.all(plist);
26
- await fs.promises.rename('./gitignore','./.gitignore');
27
- }
28
-
29
-
30
- /**对项目进行初始化 */
31
- export const CmdInitElectron = (program:Command)=>program
32
- .command('Init-Electron')
33
- .alias('initelectron')
34
- .description('对当前目录进行项目初始化,创建Electron基础环境')
35
- .action(async (opt) => {
36
- //checkProject();
37
- SLogger.info(`开始初始化设置当前目录 ${PROJECT_PATH}`);
38
- await Promise.all([
39
- copyData(),
40
- UtilFunc.exec(`npm ci`,{outlvl:'info',errlvl:'warn'})
41
- ]);
42
- });
@@ -1,64 +0,0 @@
1
- import { SLogger, UtilFT, matchProc, throwError } from "@zwa73/utils";
2
- import { Command } from "commander";
3
- import fs from "fs";
4
- import path from "pathe";
5
-
6
- const DupMethodList = ["skip","overwrite","move"] as const;
7
- type DupMethod = typeof DupMethodList[number];
8
- const DupMethodWithoutMove = DupMethodList.filter(t=>t!='move') as Exclude<DupMethod,'move'>[];
9
-
10
- /**重命名文件或路径 */
11
- export const CmdMapPath = (program: Command) => program
12
- .command("Map-Path")
13
- .alias("mappath")
14
- .description("根据正则表达式对文件名进行映射")
15
- .argument("<regex>", "要匹配的正则表达式, posix风格路径")
16
- .argument("<replacement>", "替换字符串")
17
- .option("-e, --exclude <regex>", "排除文件的正则表达式")
18
- .option(`-d, --duplicate-handling <${DupMethodWithoutMove.join('|')}|[path:string]>`,
19
- `处理重名文件的方式:
20
- skip 不进行处理
21
- overwrite 覆盖重名
22
- 其他字符串 将重名部分映射到指定目录下的对应位置, 再次重复将会覆盖`,
23
- "skip")
24
- .option("-r, --recursive", "是否处理子目录", false)
25
- .option("-m, --move", "重命名而不是复制文件", false)
26
- .option("-t, --test", "不对文件进行实际操作, 在控制台输出映射结果", false)
27
- .action(async (regexStr, replacement, options) => {
28
- const regex = new RegExp(regexStr);
29
- const excludeRegex = options.exclude ? new RegExp(options.exclude) : null;
30
- if(!DupMethodList.includes(options.duplicateHandling))
31
- throwError(`${options.duplicateHandling} 不是有效的 duplicate-handling`);
32
- const duplicateHandling = options.duplicateHandling as DupMethod;
33
- const basePath = process.cwd();
34
- // 遍历当前目录下的所有文件
35
- const filePaths = (await UtilFT.fileSearchRegex(basePath, regex.source,{relative:options.recursive}))
36
- .map((filePath)=>path.relative(basePath, filePath))
37
- .filter((filePath)=>excludeRegex ? (!excludeRegex.test(filePath)) : true);
38
-
39
- //对单个路径映射
40
- const mapPath = async (source:string,target:string)=>{
41
- const dir = path.parse(target).dir;
42
- await UtilFT.ensurePathExists(dir,{dir:true});
43
- if(options.test) return SLogger.info(`${source} -> ${target}`);
44
- if (options.move) await fs.promises.rename(source, target);
45
- else await fs.promises.copyFile(source, target);
46
- }
47
-
48
- for(const filePath of filePaths){
49
- // 重命名文件
50
- const newFilePath = filePath.replace(regex, replacement);
51
- // 如果文件名发生了变化
52
- if (newFilePath === filePath) continue;
53
- //如果文件已存在
54
- if(await UtilFT.pathExists(newFilePath)){
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));
62
- } else await mapPath(filePath,newFilePath);
63
- }
64
- });
@@ -1,16 +0,0 @@
1
- import { Command } from 'commander';
2
-
3
- import { SLogger, UtilFunc } from '@zwa73/utils';
4
-
5
- /**编译并运行某个文件 */
6
- export const CmdNode = (program:Command)=>program
7
- .command('Node <path|path[]>')
8
- .alias('node')
9
- .option('-p, --project <path>','tsconfig的目录')
10
- .description('编译并运行某个文件')
11
- .action(async (arg, opt) => {
12
- SLogger.info(`编译并运行: ${arg}`);
13
- let cmd = `ts-node -r tsconfig-paths/register ${arg}`;
14
- if(opt.project) cmd+=` -P ${opt.project}`;
15
- await UtilFunc.exec(cmd,{outlvl:'info',errlvl:'error'});
16
- });
@@ -1,96 +0,0 @@
1
- import { Command } from 'commander';
2
- import path from 'pathe';
3
-
4
- import { memoize, SLogger, throwError, UtilFT, UtilFunc } from '@zwa73/utils';
5
-
6
- import { checkProject, OFFICIAL_SOURCE, PROJECT_PATH } from './RouteInterface';
7
- import fs from 'fs';
8
-
9
- /**解析版本号为number数组 */
10
- function parseVersion(version: string){
11
- const arr = version.split(".").map(Number);
12
- if (arr.length !== 3)
13
- throwError(`${version} 不是有效的版本号`,'error');
14
- for (let i = 0; i < 3; i++){
15
- if (!isFinite(arr[i]))
16
- throwError(`${version} 不是有效的版本号`,'error');
17
- }
18
- return arr;
19
- }
20
- /**判断版本号是否有效 */
21
- function checkVersion(oldVersion: string, newVersion: string) {
22
- const oldParts = parseVersion(oldVersion);
23
- const newParts = parseVersion(newVersion);
24
- for (let i = 0; i < 3; i++) {
25
- if (newParts[i] < oldParts[i])
26
- throwError(`${newVersion} 低于当前版本号 ${oldVersion}`,'error');
27
- if (newParts[i] > oldParts[i])
28
- break;
29
- }
30
- }
31
-
32
- /**更新版本号 */
33
- async function updateVersion(newVersion?: string): Promise<string> {
34
- const packagePath = path.join(PROJECT_PATH, "package.json");
35
- const packageData = await memoize(UtilFT.loadJSONFile)(packagePath) as any;
36
- if (newVersion) {
37
- checkVersion(packageData.version, newVersion);
38
- packageData.version = newVersion;
39
- } else {
40
- const version = packageData.version.split(".");
41
- version[2] = (parseInt(version[2]) + 1).toString();
42
- packageData.version = version.join(".");
43
- }
44
- await UtilFT.writeJSONFile(packagePath, packageData);
45
- return packageData.version;
46
- }
47
- /**获取包名 */
48
- async function getPackName(){
49
- const packagePath = path.join(PROJECT_PATH, "package.json");
50
- const packageData = await memoize(UtilFT.loadJSONFile)(packagePath) as any;
51
- return packageData.name
52
- .replace(/\//g,'-')
53
- .replace(/^@/g,'');
54
- }
55
-
56
- /**更新版本号并发布npm包 */
57
- export const CmdRelease = (program: Command) =>program
58
- .command("Release")
59
- .alias("release")
60
- .description("更新版本号并发布包")
61
- .option("-v, --version <version>", "指定发布的版本号 格式应为 `${number}.${number}.${number}`")
62
- .option("-a, --access <access>", "npm publish 的 access 参数 默认 public","public")
63
- .option("-l, --local <path>", "仅打包到本地对印目录下 如./build/",undefined)
64
- .action(async (opt:{
65
- version?: string;
66
- access: string;
67
- local?: string;
68
- }) => {
69
- checkProject();
70
- SLogger.info(`开始发布项目`);
71
- try {
72
- const newVersion = await updateVersion(opt.version);
73
- SLogger.info(`新版本号: ${newVersion}`);
74
- if(opt.local){
75
- SLogger.info("正在打包...");
76
- const fullpath = path.join(process.cwd(),opt.local);
77
- await UtilFT.ensurePathExists(fullpath,{dir:true});
78
- await UtilFunc.exec(`npm pack`,{errlvl:'info'});
79
- const packageName = await getPackName();
80
- const filelist = await fs.promises.readdir(process.cwd());
81
- await Promise.all(filelist
82
- .filter(p=>new RegExp(packageName).test(p))
83
- .map(async p=>{
84
- const packagePath = path.join(fullpath, p);
85
- await fs.promises.rename(p, packagePath);
86
- }))
87
- return;
88
- }
89
- SLogger.info("正在发布...");
90
- const cmd = `npm publish --registry ${OFFICIAL_SOURCE} --access ${opt.access}`;
91
- await UtilFunc.exec(cmd,{errlvl:'info'});
92
- SLogger.info("发布完成");
93
- } catch (error) {
94
- SLogger.error(error);
95
- }
96
- });
@@ -1,24 +0,0 @@
1
- import { program } from 'commander';
2
-
3
- import { CmdInit } from './Init';
4
- import { CmdNode } from './Node';
5
- import { CmdRelease } from './Release';
6
- import { CmdMapPath } from './MapPath';
7
- import { CmdScanDups } from './ScanDups';
8
- import { CmdGenSchema } from './GenSchema';
9
- import { CmdExpandMacro } from './ExpandMacro';
10
- import { CmdGenI18n } from './GenI18n';
11
- import { CmdInitElectron } from './InitElectron';
12
-
13
- export async function cliRoute(){
14
- CmdInit(program);
15
- CmdInitElectron(program);
16
- CmdNode(program);
17
- CmdRelease(program);
18
- CmdMapPath(program);
19
- CmdScanDups(program);
20
- CmdGenSchema(program);
21
- CmdExpandMacro(program);
22
- CmdGenI18n(program);
23
- program.parse(process.argv);
24
- }
@@ -1,47 +0,0 @@
1
- import { SLogger, UtilFT } from "@zwa73/utils";
2
- import { Command } from "commander";
3
- import fs from "fs";
4
- import crypto from 'crypto';
5
- import path from "pathe";
6
-
7
- async function calculateHash(filePath:string) {
8
- return new Promise<string>((resolve, reject) => {
9
- const hash = crypto.createHash('md5');
10
- const stream = fs.createReadStream(filePath);
11
- stream.on('data', (data) => hash.update(data));
12
- stream.on('end', () => resolve(hash.digest('hex')));
13
- stream.on('error', reject);
14
- });
15
- }
16
-
17
-
18
- /**重命名文件或路径 scan_duplicates */
19
- export const CmdScanDups = (program: Command) => program
20
- .command("Scan-Dups")
21
- .alias("scandups")
22
- .description("扫描当前目录下hash重复的文件")
23
- .option("-re, --regex <regex>", "文件的正则表达式, 使用posix路径",".*")
24
- .option("-o, --out <dir|console>", "输出的json文件路径, 默认 scandupsOut.json, 为 \"console\" 时无文件输出", "scandupsOut")
25
- .option("-r, --recursive", "是否处理子目录, 默认 true", true)
26
- .action(async (options) => {
27
- const regex = new RegExp(options.regex);
28
- const basePath = process.cwd();
29
- const pList = (await UtilFT.fileSearchRegex(basePath, regex.source, {
30
- relative: options.recursive,
31
- })).map(async (filePath) => ({ filePath, hash: await calculateHash(filePath) }));
32
-
33
- const hashMap = (await Promise.all(pList)).reduce((obj,cur)=>{
34
- obj[cur.hash] = (obj[cur.hash]??[]).concat(cur.filePath);
35
- return obj;
36
- },{} as Record<string,string[]>);
37
- const out:Record<string,string[]> = {};
38
- for (const hash in hashMap) {
39
- const duplicateFiles = hashMap[hash];
40
- if(duplicateFiles.length<=1) continue;
41
- out[hash] = duplicateFiles;
42
- }
43
- if(options.out==="console")
44
- SLogger.info(out);
45
- else
46
- await UtilFT.writeJSONFile(path.join(basePath,options.out),out);
47
- });
@@ -1 +0,0 @@
1
- export * from './Route';
@@ -1,4 +0,0 @@
1
- import { UtilMacro } from "./UtilMacro";
2
-
3
-
4
- //UtilMacro.exportComment('src/**/*.ts');
package/src/QuickFunc.ts DELETED
@@ -1,7 +0,0 @@
1
- import { UtilDT } from "./UtilDevTool";
2
-
3
- export const {
4
- regionMacro ,
5
- fileMacro ,
6
- commentMacro,
7
- } = UtilDT;
package/src/UtilAst.ts DELETED
@@ -1,25 +0,0 @@
1
- import { AnyFunc,I18nTextData } from "@zwa73/utils";
2
- import { SyntaxKind , KindToNodeMappings, Node} from "ts-morph";
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
- export namespace UtilAst{
11
- /**匹配Node的类型进行处理 无法匹配时返回undefined
12
- * @param node - ast节点
13
- * @param funcMap - 处理函数映射表
14
- */
15
- export function withKind<T extends Partial<{
16
- [P in SyntaxKind]:((n:KindToNodeMappings[P])=>unknown)
17
- }>>(node:Node,funcMap:T):{
18
- [P in keyof T]:T[P] extends AnyFunc ? ReturnType<T[P]> : never
19
- }[keyof T]|undefined{
20
- const kind = node.getKind();
21
- const func = funcMap[kind] as any;
22
- if(func) return func(node);
23
- return undefined;
24
- }
25
- }