@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/bin/cli CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const {cliRoute} = require('../index');
3
+ const {cliRoute} = await import('../dist/mjs/index.js');
4
4
 
5
5
  cliRoute();
@@ -0,0 +1,3 @@
1
+ **/node_modules/**
2
+ **/test/**
3
+ dist/**
@@ -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,8 @@
1
+ Write-Output 开始删除原dist
2
+ Remove-Item -Recurse -Force dist
3
+ Write-Output 开始编译
4
+ tsc -p tsconfig.cjs.json
5
+ tsc-alias -p tsconfig.cjs.json
6
+ tsc -p tsconfig.mjs.json
7
+ tsc-alias -p tsconfig.mjs.json
8
+ tsc-esm-fix --tsconfig "./tsconfig.mjs.json"
@@ -0,0 +1,6 @@
1
+ import { UtilMacro } from '@zwa73/dev-utils';
2
+
3
+
4
+
5
+
6
+ UtilMacro.exportComment('src/**/index.ts');
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "outDir": "./dist/cjs",
6
+ "target": "ES2022"
7
+ },
8
+ "include": ["./src/**/*.ts", "./src/**/*.js"]
9
+ }
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "allowJs": true,
3
+ "allowJs": true,
4
4
  "strict": true,
5
- "target": "ES2022",
6
5
  "module": "commonjs",
7
6
  "moduleResolution": "node",
8
7
  "esModuleInterop": true,
@@ -11,6 +10,7 @@
11
10
  "baseUrl": ".",
12
11
  "emitDecoratorMetadata": true,
13
12
  "experimentalDecorators": true,
13
+ "skipLibCheck": true,
14
14
  "paths": {
15
15
  "@/src/*" : ["./src/*"],
16
16
  "@/*" : ["./*"],
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "ESNext",
5
+ "outDir": "./dist/mjs",
6
+ "target": "ESNext",
7
+ "allowSyntheticDefaultImports": true
8
+ },
9
+ "include": ["./src/**/*.ts", "./src/**/*.js"]
10
+ }
@@ -0,0 +1,3 @@
1
+ import { Command } from "commander";
2
+ /**生成schema */
3
+ export declare const CmdGenTemplate: (program: Command) => Command;
@@ -0,0 +1,25 @@
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
+ /**生成schema */
11
+ const CmdGenTemplate = (program) => program
12
+ .command("Gen-Template")
13
+ .alias("gentemplate")
14
+ .description("生成项目模板")
15
+ .argument("<template>", "项目模板 可用 base|electron")
16
+ .action(async (templateName) => {
17
+ const yeoman = (await utils_1.UtilFunc.dynamicImport("yeoman-environment")).default;
18
+ const env = new yeoman();
19
+ const namespace = `utildt:${templateName}`;
20
+ // 注册生成器
21
+ env.register(pathe_1.default.join(RouteInterface_1.ROOT_PATH, "dist", "mjs", "Generator", templateName, "index.js"), { namespace });
22
+ // 运行生成器
23
+ env.run([namespace], {});
24
+ });
25
+ 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 InitElectron_1 = require("./InitElectron");
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(__dirname, '..', '..', 'data');
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
  /** 检测非浮点的整数类型 */
@@ -0,0 +1,2 @@
1
+ import Generator from "yeoman-generator";
2
+ export declare const generatorBuilder: (templateName: string) => (new () => Generator);
@@ -0,0 +1,65 @@
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.generatorBuilder = void 0;
7
+ const RouteInterface_1 = require("../Command/RouteInterface");
8
+ const yeoman_generator_1 = __importDefault(require("yeoman-generator"));
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const pathe_1 = __importDefault(require("pathe"));
11
+ const utils_1 = require("@zwa73/utils");
12
+ const generatorBuilder = (templateName) => class extends yeoman_generator_1.default {
13
+ answers = {};
14
+ // 提示用户输入
15
+ async prompting() {
16
+ this.answers = await this.prompt([
17
+ {
18
+ type: "input",
19
+ name: "projectName",
20
+ message: "项目名称",
21
+ default: this.appname,
22
+ },
23
+ {
24
+ type: "input",
25
+ name: "projectDescription",
26
+ message: "项目描述",
27
+ default: "A new project",
28
+ },
29
+ {
30
+ type: "input",
31
+ name: "authorName",
32
+ message: "作者名",
33
+ default: "Your Name",
34
+ },
35
+ ]);
36
+ }
37
+ // 写入文件
38
+ writing() {
39
+ this.fs.copyTpl(this.templatePath(`${RouteInterface_1.TEMPLATE_PATH}/${templateName}/package.json`), this.destinationPath(`${this.answers.projectName}/package.json`), this.answers);
40
+ this.fs.copyTpl(this.templatePath(`${RouteInterface_1.TEMPLATE_PATH}/${templateName}/**/*`), this.destinationPath(this.answers.projectName), this.answers);
41
+ }
42
+ // 生成结束
43
+ async end() {
44
+ const dependencies = ['@zwa73/utils'];
45
+ const devDependencies = ['@types/node'];
46
+ await this.spawn('npm', ['install', ...dependencies, `--registry=${RouteInterface_1.MIRROR_SOURCE}`], {
47
+ cwd: this.destinationPath(this.answers.projectName),
48
+ stdio: 'inherit'
49
+ });
50
+ await this.spawn('npm', ['install', ...devDependencies, `--registry=${RouteInterface_1.MIRROR_SOURCE}`, '--save-dev'], {
51
+ cwd: this.destinationPath(this.answers.projectName),
52
+ stdio: 'inherit'
53
+ });
54
+ // 重命名 gitignore 文件为 .gitignore
55
+ const projectPath = this.destinationPath(this.answers.projectName);
56
+ const gitignorePath = pathe_1.default.join(projectPath, 'gitignore');
57
+ const dotGitignorePath = pathe_1.default.join(projectPath, '.gitignore');
58
+ if (await utils_1.UtilFT.pathExists(gitignorePath)) {
59
+ fs_1.default.promises.rename(gitignorePath, dotGitignorePath);
60
+ this.log('gitignore 文件已重命名为 .gitignore');
61
+ }
62
+ this.log("All done!");
63
+ }
64
+ };
65
+ exports.generatorBuilder = generatorBuilder;
@@ -0,0 +1,3 @@
1
+ import Generator from "yeoman-generator";
2
+ declare const _default: new () => Generator;
3
+ export default _default;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const Common_1 = require("../Common");
4
+ exports.default = (0, Common_1.generatorBuilder)('base');
@@ -0,0 +1,3 @@
1
+ import Generator from "yeoman-generator";
2
+ declare const _default: new () => Generator;
3
+ export default _default;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const Common_1 = require("../Common");
4
+ exports.default = (0, Common_1.generatorBuilder)('electron');
@@ -0,0 +1 @@
1
+ type FileMacro = 5;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ type Test3 = 4;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //#endregion 1 ssa
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ 2;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const QuickFunc_1 = require("../QuickFunc");
4
+ (0, QuickFunc_1.regionMacro)('macroTest1', "type Test1 = 1");
5
+ (0, QuickFunc_1.regionMacro)('macroTest2', "type Test2 = 2");
6
+ (0, QuickFunc_1.regionMacro)('macroTest3', "type Test3 = 3");
7
+ (0, QuickFunc_1.commentMacro)('comment1', "type CM1 = 3");
8
+ (0, QuickFunc_1.commentMacro)('comment2', "type CM2 = 3");
9
+ (0, QuickFunc_1.regionMacro)('macroTest4', "type Test3 = 4", { filePath: 'src/test/**/*.ts', glob: true });
10
+ (0, QuickFunc_1.fileMacro)("type FileMacro = 5", { filePath: 'src/test/testFileMacro.ts' });
11
+ (0, QuickFunc_1.commentMacro)(/regexTest[\S]*/, ({ matchId: id }) => `type ${id} = "${id}"`);
@@ -0,0 +1 @@
1
+ type CM1 = 3;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const QuickFunc_1 = require("../QuickFunc");
4
+ (0, QuickFunc_1.commentMacro)('comment1', "type CM1 = 3");
@@ -0,0 +1,3 @@
1
+ import { Command } from "commander";
2
+ /**构造macro */
3
+ export declare const CmdExpandMacro: (program: Command) => Command;
@@ -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,3 @@
1
+ import { Command } from "commander";
2
+ /**生成i18n */
3
+ export declare const CmdGenI18n: (program: Command) => Command;
@@ -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,3 @@
1
+ import { Command } from "commander";
2
+ /**生成schema */
3
+ export declare const CmdGenSchema: (program: Command) => Command;
@@ -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,3 @@
1
+ import { Command } from "commander";
2
+ /**生成schema */
3
+ export declare const CmdGenTemplate: (program: Command) => Command;
@@ -0,0 +1,18 @@
1
+ import path from 'pathe';
2
+ import { ROOT_PATH } from "./RouteInterface.js";
3
+ import { UtilFunc } from "@zwa73/utils";
4
+ /**生成schema */
5
+ export const CmdGenTemplate = (program) => program
6
+ .command("Gen-Template")
7
+ .alias("gentemplate")
8
+ .description("生成项目模板")
9
+ .argument("<template>", "项目模板 可用 base|electron")
10
+ .action(async (templateName) => {
11
+ const yeoman = (await UtilFunc.dynamicImport("yeoman-environment")).default;
12
+ const env = new yeoman();
13
+ const namespace = `utildt:${templateName}`;
14
+ // 注册生成器
15
+ env.register(path.join(ROOT_PATH, "dist", "mjs", "Generator", templateName, "index.js"), { namespace });
16
+ // 运行生成器
17
+ env.run([namespace], {});
18
+ });
@@ -0,0 +1,3 @@
1
+ import { Command } from "commander";
2
+ /**重命名文件或路径 */
3
+ export declare const CmdMapPath: (program: Command) => Command;
@@ -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,3 @@
1
+ import { Command } from 'commander';
2
+ /**编译并运行某个文件 */
3
+ export declare const CmdNode: (program: Command) => Command;
@@ -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,3 @@
1
+ import { Command } from 'commander';
2
+ /**更新版本号并发布npm包 */
3
+ export declare const CmdRelease: (program: Command) => Command;