@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
@@ -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>;
@@ -0,0 +1,20 @@
1
+ import { program } from 'commander';
2
+ import { CmdNode } from './Node.js';
3
+ import { CmdRelease } from './Release.js';
4
+ import { CmdMapPath } from './MapPath.js';
5
+ import { CmdScanDups } from './ScanDups.js';
6
+ import { CmdGenSchema } from './GenSchema.js';
7
+ import { CmdExpandMacro } from './ExpandMacro.js';
8
+ import { CmdGenI18n } from './GenI18n.js';
9
+ import { CmdGenTemplate } from './GenTemplate.js';
10
+ export async function cliRoute() {
11
+ CmdNode(program);
12
+ CmdRelease(program);
13
+ CmdMapPath(program);
14
+ CmdScanDups(program);
15
+ CmdGenSchema(program);
16
+ CmdExpandMacro(program);
17
+ CmdGenI18n(program);
18
+ CmdGenTemplate(program);
19
+ program.parse(process.argv);
20
+ }
@@ -0,0 +1,24 @@
1
+ /**npm镜像源 */
2
+ export declare const MIRROR_SOURCE = "https://registry.npmmirror.com/";
3
+ /**npm官方源 */
4
+ export declare const OFFICIAL_SOURCE = "https://registry.npmjs.org/";
5
+ /**根目录 */
6
+ export declare const ROOT_PATH: string;
7
+ /**data文件夹路径 */
8
+ export declare const DATA_PATH: string;
9
+ /**template文件夹路径 */
10
+ export declare const TEMPLATE_PATH: string;
11
+ /**项目路径 */
12
+ export declare const PROJECT_PATH: string;
13
+ /** 检测非浮点的整数类型 */
14
+ export declare function parseInteger(value: string): number;
15
+ /** 检测任意数字类型 */
16
+ export declare function parseNumber(value: string): number;
17
+ /** 检测布尔类型 */
18
+ export declare function parseBoolean(value: string): boolean;
19
+ /**在镜像源内镜像操作 */
20
+ export declare function withMirrorSource(func: (() => any)): Promise<void>;
21
+ /**在官方源内镜像操作 */
22
+ export declare function withOfficialSource(func: (() => any)): Promise<void>;
23
+ /**检查目录是否为项目 */
24
+ export declare function checkProject(): Promise<void>;
@@ -1,63 +1,58 @@
1
- import path from 'pathe';
2
-
3
- import { SLogger, throwError, UtilFT, UtilFunc } from '@zwa73/utils';
4
-
5
- /**npm镜像源 */
6
- export const MIRROR_SOURCE = "https://registry.npmmirror.com/";
7
- /**npm官方源 */
8
- export const OFFICIAL_SOURCE = "https://registry.npmjs.org/";
9
- /**data文件夹路径 */
10
- export const DATA_PATH = path.join(__dirname,'..','..','data');
11
- /**项目路径 */
12
- export const PROJECT_PATH = process.cwd();
13
-
14
- /** 检测非浮点的整数类型 */
15
- export function parseInteger(value: string): number {
16
- const num = Number(value);
17
- if(!(typeof num === 'number' && isFinite(num) && Math.floor(num) === num))
18
- throwError(`${value} 不是有效的整数数字`);
19
- return num;
20
- }
21
-
22
- /** 检测任意数字类型 */
23
- export function parseNumber(value: string):number {
24
- const num = Number(value);
25
- if(!(typeof value === 'number' && isFinite(value)))
26
- throwError(`${value} 不是有效的数字`);
27
- return num;
28
- }
29
-
30
- /** 检测布尔类型 */
31
- export function parseBoolean(value: string): boolean {
32
- return value? true:false;
33
- }
34
-
35
-
36
- /**在镜像源内镜像操作 */
37
- export async function withMirrorSource(func:(()=>any)){
38
- const out = await UtilFunc.exec('npm config get registry');
39
- const OriginSource = out.stdout.trim()//?
40
- SLogger.info(`正在修改npm源为 镜像源: ${MIRROR_SOURCE}`);
41
- await UtilFunc.exec(`npm config set registry ${MIRROR_SOURCE}`);
42
- await func();
43
- SLogger.info(`正在修改npm源为 原始源: ${OriginSource}`);
44
- await UtilFunc.exec(`npm config set registry ${OriginSource}`);
45
- }
46
-
47
- /**在官方源内镜像操作 */
48
- export async function withOfficialSource(func:(()=>any)){
49
- const out = await UtilFunc.exec('npm config get registry');
50
- const OriginSource = out.stdout.trim()//?
51
- SLogger.info(`正在修改npm源为 官方源: ${OFFICIAL_SOURCE}`);
52
- await UtilFunc.exec(`npm config set registry ${OFFICIAL_SOURCE}`);
53
- await func();
54
- SLogger.info(`正在修改npm源为 原始源: ${OriginSource}`);
55
- await UtilFunc.exec(`npm config set registry ${OriginSource}`);
56
- }
57
-
58
- /**检查目录是否为项目 */
59
- export async function checkProject() {
60
- const filePath = path.join(PROJECT_PATH,"package.json");
61
- if(!(await UtilFT.pathExists(filePath)))
62
- throwError(`当前目录: ${PROJECT_PATH} 不是npm项目目录, 请先使用 npm init`);
63
- }
1
+ import path from 'pathe';
2
+ import { SLogger, throwError, UtilFT, UtilFunc } from '@zwa73/utils';
3
+ /**npm镜像源 */
4
+ export const MIRROR_SOURCE = "https://registry.npmmirror.com/";
5
+ /**npm官方源 */
6
+ export const OFFICIAL_SOURCE = "https://registry.npmjs.org/";
7
+ /**根目录 */
8
+ export const ROOT_PATH = path.join(`${process.platform === 'win32' ? '' : '/'}${/file:\/{2,3}(.+)\/[^/]/.exec(import.meta.url)[1]}`, '..', '..', '..');
9
+ /**data文件夹路径 */
10
+ export const DATA_PATH = path.join(ROOT_PATH, 'data');
11
+ /**template文件夹路径 */
12
+ export const TEMPLATE_PATH = path.join(DATA_PATH, 'template');
13
+ /**项目路径 */
14
+ export const PROJECT_PATH = process.cwd();
15
+ /** 检测非浮点的整数类型 */
16
+ export function parseInteger(value) {
17
+ const num = Number(value);
18
+ if (!(typeof num === 'number' && isFinite(num) && Math.floor(num) === num))
19
+ throwError(`${value} 不是有效的整数数字`);
20
+ return num;
21
+ }
22
+ /** 检测任意数字类型 */
23
+ export function parseNumber(value) {
24
+ const num = Number(value);
25
+ if (!(typeof value === 'number' && isFinite(value)))
26
+ throwError(`${value} 不是有效的数字`);
27
+ return num;
28
+ }
29
+ /** 检测布尔类型 */
30
+ export function parseBoolean(value) {
31
+ return value ? true : false;
32
+ }
33
+ /**在镜像源内镜像操作 */
34
+ export async function withMirrorSource(func) {
35
+ const out = await UtilFunc.exec('npm config get registry');
36
+ const OriginSource = out.stdout.trim(); //?
37
+ SLogger.info(`正在修改npm源为 镜像源: ${MIRROR_SOURCE}`);
38
+ await UtilFunc.exec(`npm config set registry ${MIRROR_SOURCE}`);
39
+ await func();
40
+ SLogger.info(`正在修改npm源为 原始源: ${OriginSource}`);
41
+ await UtilFunc.exec(`npm config set registry ${OriginSource}`);
42
+ }
43
+ /**在官方源内镜像操作 */
44
+ export async function withOfficialSource(func) {
45
+ const out = await UtilFunc.exec('npm config get registry');
46
+ const OriginSource = out.stdout.trim(); //?
47
+ SLogger.info(`正在修改npm源为 官方源: ${OFFICIAL_SOURCE}`);
48
+ await UtilFunc.exec(`npm config set registry ${OFFICIAL_SOURCE}`);
49
+ await func();
50
+ SLogger.info(`正在修改npm源为 原始源: ${OriginSource}`);
51
+ await UtilFunc.exec(`npm config set registry ${OriginSource}`);
52
+ }
53
+ /**检查目录是否为项目 */
54
+ export async function checkProject() {
55
+ const filePath = path.join(PROJECT_PATH, "package.json");
56
+ if (!(await UtilFT.pathExists(filePath)))
57
+ throwError(`当前目录: ${PROJECT_PATH} 不是npm项目目录, 请先使用 npm init`);
58
+ }
@@ -0,0 +1,3 @@
1
+ import { Command } from "commander";
2
+ /**重命名文件或路径 scan_duplicates */
3
+ export declare const CmdScanDups: (program: Command) => Command;
@@ -0,0 +1,43 @@
1
+ import { SLogger, UtilFT } from "@zwa73/utils";
2
+ import fs from "fs";
3
+ import crypto from 'crypto';
4
+ import path from "pathe";
5
+ async function calculateHash(filePath) {
6
+ return new Promise((resolve, reject) => {
7
+ const hash = crypto.createHash('md5');
8
+ const stream = fs.createReadStream(filePath);
9
+ stream.on('data', (data) => hash.update(data));
10
+ stream.on('end', () => resolve(hash.digest('hex')));
11
+ stream.on('error', reject);
12
+ });
13
+ }
14
+ /**重命名文件或路径 scan_duplicates */
15
+ export const CmdScanDups = (program) => program
16
+ .command("Scan-Dups")
17
+ .alias("scandups")
18
+ .description("扫描当前目录下hash重复的文件")
19
+ .option("-re, --regex <regex>", "文件的正则表达式, 使用posix路径", ".*")
20
+ .option("-o, --out <dir|console>", "输出的json文件路径, 默认 scandupsOut.json, 为 \"console\" 时无文件输出", "scandupsOut")
21
+ .option("-r, --recursive", "是否处理子目录, 默认 true", true)
22
+ .action(async (options) => {
23
+ const regex = new RegExp(options.regex);
24
+ const basePath = process.cwd();
25
+ const pList = (await UtilFT.fileSearchRegex(basePath, regex.source, {
26
+ relative: options.recursive,
27
+ })).map(async (filePath) => ({ filePath, hash: await calculateHash(filePath) }));
28
+ const hashMap = (await Promise.all(pList)).reduce((obj, cur) => {
29
+ obj[cur.hash] = (obj[cur.hash] ?? []).concat(cur.filePath);
30
+ return obj;
31
+ }, {});
32
+ const out = {};
33
+ for (const hash in hashMap) {
34
+ const duplicateFiles = hashMap[hash];
35
+ if (duplicateFiles.length <= 1)
36
+ continue;
37
+ out[hash] = duplicateFiles;
38
+ }
39
+ if (options.out === "console")
40
+ SLogger.info(out);
41
+ else
42
+ await UtilFT.writeJSONFile(path.join(basePath, options.out), out);
43
+ });
@@ -0,0 +1 @@
1
+ export * from './Route.js';
@@ -0,0 +1 @@
1
+ export * from './Route.js';
@@ -0,0 +1,2 @@
1
+ import Generator from "yeoman-generator";
2
+ export declare const generatorBuilder: (templateName: string) => (new () => Generator);
@@ -0,0 +1,58 @@
1
+ import { MIRROR_SOURCE, TEMPLATE_PATH } from "../Command/RouteInterface.js";
2
+ import Generator from "yeoman-generator";
3
+ import fs from 'fs';
4
+ import path from 'pathe';
5
+ import { UtilFT } from "@zwa73/utils";
6
+ export const generatorBuilder = (templateName) => class extends Generator {
7
+ answers = {};
8
+ // 提示用户输入
9
+ async prompting() {
10
+ this.answers = await this.prompt([
11
+ {
12
+ type: "input",
13
+ name: "projectName",
14
+ message: "项目名称",
15
+ default: this.appname,
16
+ },
17
+ {
18
+ type: "input",
19
+ name: "projectDescription",
20
+ message: "项目描述",
21
+ default: "A new project",
22
+ },
23
+ {
24
+ type: "input",
25
+ name: "authorName",
26
+ message: "作者名",
27
+ default: "Your Name",
28
+ },
29
+ ]);
30
+ }
31
+ // 写入文件
32
+ writing() {
33
+ this.fs.copyTpl(this.templatePath(`${TEMPLATE_PATH}/${templateName}/package.json`), this.destinationPath(`${this.answers.projectName}/package.json`), this.answers);
34
+ this.fs.copyTpl(this.templatePath(`${TEMPLATE_PATH}/${templateName}/**/*`), this.destinationPath(this.answers.projectName), this.answers);
35
+ }
36
+ // 生成结束
37
+ async end() {
38
+ const dependencies = ['@zwa73/utils'];
39
+ const devDependencies = ['@types/node'];
40
+ await this.spawn('npm', ['install', ...dependencies, `--registry=${MIRROR_SOURCE}`], {
41
+ cwd: this.destinationPath(this.answers.projectName),
42
+ stdio: 'inherit'
43
+ });
44
+ await this.spawn('npm', ['install', ...devDependencies, `--registry=${MIRROR_SOURCE}`, '--save-dev'], {
45
+ cwd: this.destinationPath(this.answers.projectName),
46
+ stdio: 'inherit'
47
+ });
48
+ // 重命名 gitignore 文件为 .gitignore
49
+ const projectPath = this.destinationPath(this.answers.projectName);
50
+ const gitignorePath = path.join(projectPath, 'gitignore');
51
+ const dotGitignorePath = path.join(projectPath, '.gitignore');
52
+ if (await UtilFT.pathExists(gitignorePath)) {
53
+ fs.promises.rename(gitignorePath, dotGitignorePath);
54
+ this.log('gitignore 文件已重命名为 .gitignore');
55
+ }
56
+ this.log("All done!");
57
+ }
58
+ };
@@ -0,0 +1,3 @@
1
+ import Generator from "yeoman-generator";
2
+ declare const _default: new () => Generator;
3
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import { generatorBuilder } from "../Common.js";
2
+ export default 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,2 @@
1
+ import { generatorBuilder } from "../Common.js";
2
+ export default generatorBuilder('electron');
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //UtilMacro.exportComment('src/**/*.ts');
@@ -0,0 +1,2 @@
1
+ import { UtilDT } from "./UtilDevTool.js";
2
+ export declare const regionMacro: typeof UtilDT.regionMacro, fileMacro: typeof UtilDT.fileMacro, commentMacro: typeof UtilDT.commentMacro;
@@ -0,0 +1,2 @@
1
+ import { UtilDT } from "./UtilDevTool.js";
2
+ export const { regionMacro, fileMacro, commentMacro, } = UtilDT;
@@ -0,0 +1,13 @@
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
+ }
@@ -0,0 +1,15 @@
1
+ export var UtilAst;
2
+ (function (UtilAst) {
3
+ /**匹配Node的类型进行处理 无法匹配时返回undefined
4
+ * @param node - ast节点
5
+ * @param funcMap - 处理函数映射表
6
+ */
7
+ function withKind(node, funcMap) {
8
+ const kind = node.getKind();
9
+ const func = funcMap[kind];
10
+ if (func)
11
+ return func(node);
12
+ return undefined;
13
+ }
14
+ UtilAst.withKind = withKind;
15
+ })(UtilAst || (UtilAst = {}));
@@ -0,0 +1,99 @@
1
+ import { JObject } from '@zwa73/utils';
2
+ export declare namespace UtilDT {
3
+ /**执行js/ts的可选项 */
4
+ type BatchNodeOpt = Partial<{
5
+ /**tsconfig路径 */
6
+ project: string;
7
+ }>;
8
+ /**build任意ts文件的可选项 */
9
+ type BuildMatchOpt = Partial<{
10
+ /**包含的glob */
11
+ include: string | string[];
12
+ /**忽略的glob */
13
+ exclude: string | string[];
14
+ }> & BatchNodeOpt;
15
+ /**build schema的可选项 */
16
+ type BuildSchemaOpt = Partial<{
17
+ /**将会覆盖 definitions 对应内容的表 */
18
+ coverDefine: JObject;
19
+ /**schema输出路径目录 如 ./schema/ */
20
+ outDir: string;
21
+ /**包含的types正则匹配数组 默认 [/.*\/] */
22
+ includeTypes?: string[];
23
+ /**排除的types正则匹配数组 */
24
+ excludeTypes?: string[];
25
+ }> & BuildMatchOpt;
26
+ /**生成匹配的文件的所有type的schema
27
+ * @async
28
+ * @param dir - 基础目录
29
+ * @param opt - 可选参数
30
+ * @param opt.include - 包含的glob 默认 **\/\*.schema.ts
31
+ * @param opt.exclude - 忽略的glob
32
+ * @param opt.coverDefine - 将会覆盖 definitions 对应内容的表
33
+ * @param opt.project - tsconfig路径
34
+ * @param opt.outDir - schema输出路径目录 默认 ./schema/
35
+ * @param opt.includeTypes - 包含的types正则匹配数组 默认 [/.*\/]
36
+ * @param opt.excludeTypes - 排除的types正则匹配数组
37
+ */
38
+ export function generateSchema(dir: string, opt?: BuildSchemaOpt): Promise<void>;
39
+ /**运行所有匹配的的js/ts文件
40
+ * @async
41
+ * @param dir - 基础目录
42
+ * @param opt - 可选参数
43
+ * @param opt.include - 包含的glob 默认 index.ts
44
+ * @param opt.exclude - 忽略的glob
45
+ * @param opt.project - tsconfig路径
46
+ */
47
+ export function matchNode(dir: string, opt?: BuildMatchOpt): Promise<void>;
48
+ /**运行所有js/ts文件
49
+ * @async
50
+ * @param filepath - 需要运行的文件
51
+ * @param opt - 可选参数
52
+ * @param opt.project - tsconfig路径
53
+ */
54
+ export function batchNode(filepath: string | string[], opt?: BatchNodeOpt): Promise<void>;
55
+ /**宏的可选参数 */
56
+ type MacroOpt = Partial<{
57
+ /**宏展开的目标文件 */
58
+ filePath: string[] | string;
59
+ /**使用glob匹配而非文件路径 */
60
+ glob: boolean;
61
+ }>;
62
+ /**codeText的参数 */
63
+ type CodeTextOpt = {
64
+ /**匹配的region/comment id */
65
+ matchId: string;
66
+ /**region/comment id正则的执行结果*/
67
+ execArr: RegExpExecArray;
68
+ /**展开宏的目标文件 */
69
+ filePath: string;
70
+ /**展开宏区域的原文本 */
71
+ text: string;
72
+ /**缩进 会自动应用 */
73
+ inent: string;
74
+ };
75
+ /**将codeText写入对应region
76
+ * @param regionId - 区域id \`//#region ${id}\`
77
+ * @param codeText - 文本
78
+ * @param opt - 可选参数
79
+ * @param opt.filePath - 目标文件 默认为去除".macro"的同名文件
80
+ * @param opt.glob - 使用glob匹配而非文件路径
81
+ */
82
+ export function regionMacro(regionId: string | RegExp, codeText: string | ((opt: CodeTextOpt) => string | Promise<string>), opt?: MacroOpt): Promise<void>;
83
+ /**将codeText写入对应注释下
84
+ * @param commentId - 注释id \`// ${id}\`
85
+ * @param codeText - 文本
86
+ * @param opt - 可选参数
87
+ * @param opt.filePath - 目标文件 默认为去除".macro"的同名文件
88
+ * @param opt.glob - 使用glob匹配而非文件路径
89
+ */
90
+ export function commentMacro(commentId: string | RegExp, codeText: string | ((opt: CodeTextOpt) => string | Promise<string>), opt?: MacroOpt): Promise<void>;
91
+ /**将codeText写入对应文件 不存在则创建
92
+ * @param codeText - 文本
93
+ * @param opt - 可选参数
94
+ * @param opt.filePath - 目标文件 默认为去除".macro"的同名文件
95
+ * @param opt.glob - 使用glob匹配而非文件路径
96
+ */
97
+ export function fileMacro(codeText: string | ((opt: Omit<CodeTextOpt, 'ident' | 'matchId' | 'execArr'>) => string | Promise<string>), opt?: MacroOpt): Promise<void>;
98
+ export {};
99
+ }