@zwa73/dev-utils 1.0.88 → 1.0.90

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 (113) hide show
  1. package/bin/cli +1 -1
  2. package/data/template/base/package.json +7 -6
  3. package/data/template/base/scripts/compile.ps1 +25 -8
  4. package/data/template/base/scripts/release.ps1 +5 -2
  5. package/data/template/base/tsconfig.json +3 -5
  6. package/data/template/base/tsup.config.js +35 -0
  7. package/data/template/cjs/gitignore +3 -0
  8. package/data/template/cjs/package.json +19 -0
  9. package/data/template/cjs/scripts/compile.ps1 +13 -0
  10. package/data/template/cjs/scripts/expand-macro.ps1 +2 -0
  11. package/data/template/cjs/scripts/release.ps1 +8 -0
  12. package/data/template/cjs/scripts/watch.ps1 +10 -0
  13. package/data/template/cjs/src/index.ts +0 -0
  14. package/data/template/cjs/src/macro.macro.ts +6 -0
  15. package/data/template/cjs/tsconfig.compile.json +12 -0
  16. package/data/template/cjs/tsconfig.json +21 -0
  17. package/data/template/electron/package.json +25 -25
  18. package/dist/Command/Bump.d.ts +6 -0
  19. package/dist/Command/Bump.js +70 -0
  20. package/dist/Command/CheckToken.d.ts +10 -0
  21. package/dist/Command/CheckToken.js +52 -0
  22. package/dist/{mjs/Command → Command}/ExpandMacro.d.ts +1 -1
  23. package/dist/{cjs/Command → Command}/GenI18n.d.ts +1 -1
  24. package/dist/{cjs/Command → Command}/GenI18n.js +20 -12
  25. package/dist/{cjs/Command → Command}/GenSchema.d.ts +1 -1
  26. package/dist/{cjs/Command → Command}/GenTemplate.d.ts +1 -1
  27. package/dist/{cjs/Command → Command}/GenTemplate.js +9 -6
  28. package/dist/{cjs/Command → Command}/MapPath.d.ts +1 -1
  29. package/dist/Command/MapPath.js +115 -0
  30. package/dist/{cjs/Command → Command}/Node.d.ts +1 -1
  31. package/dist/{cjs/Command → Command}/Node.js +1 -1
  32. package/dist/{cjs/Command → Command}/Release.d.ts +1 -1
  33. package/dist/{cjs/Command → Command}/Release.js +9 -45
  34. package/dist/{cjs/Command → Command}/Route.js +7 -5
  35. package/dist/{cjs/Command → Command}/ScanDups.d.ts +1 -1
  36. package/dist/{cjs/Command → Command}/ScanDups.js +15 -13
  37. package/dist/DynImport.d.ts +15 -0
  38. package/dist/DynImport.js +15 -0
  39. package/dist/{mjs/UtilAst.d.ts → UtilAst.d.ts} +2 -2
  40. package/dist/{mjs/UtilDevTool.d.ts → UtilDevTool.d.ts} +1 -1
  41. package/dist/{cjs/UtilDevTool.js → UtilDevTool.js} +21 -38
  42. package/dist/UtilInterface.d.ts +8 -0
  43. package/dist/UtilMacro.d.ts +7 -0
  44. package/dist/{cjs/UtilMacro.js → UtilMacro.js} +4 -4
  45. package/package.json +2 -10
  46. package/data/template/base/tsconfig.cjs.json +0 -8
  47. package/data/template/base/tsconfig.mjs.json +0 -9
  48. package/dist/cjs/Command/ExpandMacro.d.ts +0 -3
  49. package/dist/cjs/Command/MapPath.js +0 -80
  50. package/dist/cjs/UtilAst.d.ts +0 -13
  51. package/dist/cjs/UtilDevTool.d.ts +0 -99
  52. package/dist/cjs/UtilInterface.d.ts +0 -4
  53. package/dist/cjs/UtilMacro.d.ts +0 -7
  54. package/dist/cjs/test/testFileMacro.d.ts +0 -1
  55. package/dist/cjs/test/testFileMacro.js +0 -1
  56. package/dist/cjs/test/testGlobMacro.d.ts +0 -1
  57. package/dist/cjs/test/testGlobMacro.js +0 -2
  58. package/dist/cjs/test/testRegex.d.ts +0 -1
  59. package/dist/cjs/test/testRegex.js +0 -3
  60. package/dist/cjs/test/testRegexa.d.ts +0 -1
  61. package/dist/cjs/test/testRegexa.js +0 -1
  62. package/dist/mjs/Command/ExpandMacro.js +0 -16
  63. package/dist/mjs/Command/GenI18n.d.ts +0 -3
  64. package/dist/mjs/Command/GenI18n.js +0 -75
  65. package/dist/mjs/Command/GenSchema.d.ts +0 -3
  66. package/dist/mjs/Command/GenSchema.js +0 -22
  67. package/dist/mjs/Command/GenTemplate.d.ts +0 -3
  68. package/dist/mjs/Command/GenTemplate.js +0 -61
  69. package/dist/mjs/Command/MapPath.d.ts +0 -3
  70. package/dist/mjs/Command/MapPath.js +0 -73
  71. package/dist/mjs/Command/Node.d.ts +0 -3
  72. package/dist/mjs/Command/Node.js +0 -14
  73. package/dist/mjs/Command/Release.d.ts +0 -3
  74. package/dist/mjs/Command/Release.js +0 -90
  75. package/dist/mjs/Command/Route.d.ts +0 -1
  76. package/dist/mjs/Command/Route.js +0 -20
  77. package/dist/mjs/Command/RouteInterface.d.ts +0 -24
  78. package/dist/mjs/Command/RouteInterface.js +0 -58
  79. package/dist/mjs/Command/ScanDups.d.ts +0 -3
  80. package/dist/mjs/Command/ScanDups.js +0 -114
  81. package/dist/mjs/Command/index.d.ts +0 -1
  82. package/dist/mjs/Command/index.js +0 -1
  83. package/dist/mjs/QuickFunc.d.ts +0 -2
  84. package/dist/mjs/QuickFunc.js +0 -2
  85. package/dist/mjs/UtilAst.js +0 -15
  86. package/dist/mjs/UtilDevTool.js +0 -297
  87. package/dist/mjs/UtilInterface.d.ts +0 -4
  88. package/dist/mjs/UtilInterface.js +0 -1
  89. package/dist/mjs/UtilMacro.d.ts +0 -7
  90. package/dist/mjs/UtilMacro.js +0 -23
  91. package/dist/mjs/index.d.ts +0 -5
  92. package/dist/mjs/index.js +0 -5
  93. package/dist/mjs/test/testFileMacro.d.ts +0 -1
  94. package/dist/mjs/test/testFileMacro.js +0 -1
  95. package/dist/mjs/test/testGlobMacro.d.ts +0 -1
  96. package/dist/mjs/test/testGlobMacro.js +0 -2
  97. package/dist/mjs/test/testRegex.d.ts +0 -1
  98. package/dist/mjs/test/testRegex.js +0 -2
  99. package/dist/mjs/test/testRegexa.d.ts +0 -1
  100. package/dist/mjs/test/testRegexa.js +0 -1
  101. package/dist/{cjs/Command → Command}/ExpandMacro.js +0 -0
  102. package/dist/{cjs/Command → Command}/GenSchema.js +0 -0
  103. package/dist/{cjs/Command → Command}/Route.d.ts +0 -0
  104. package/dist/{cjs/Command → Command}/RouteInterface.d.ts +0 -0
  105. package/dist/{cjs/Command → Command}/RouteInterface.js +1 -1
  106. /package/dist/{cjs/Command → Command}/index.d.ts +0 -0
  107. /package/dist/{cjs/Command → Command}/index.js +0 -0
  108. /package/dist/{cjs/QuickFunc.d.ts → QuickFunc.d.ts} +0 -0
  109. /package/dist/{cjs/QuickFunc.js → QuickFunc.js} +0 -0
  110. /package/dist/{cjs/UtilAst.js → UtilAst.js} +0 -0
  111. /package/dist/{cjs/UtilInterface.js → UtilInterface.js} +0 -0
  112. /package/dist/{cjs/index.d.ts → index.d.ts} +0 -0
  113. /package/dist/{cjs/index.js → index.js} +0 -0
package/bin/cli CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const {cliRoute} = require('../dist/cjs/index.js');
3
+ const {cliRoute} = require('../dist/index.js');
4
4
 
5
5
  cliRoute();
@@ -2,13 +2,14 @@
2
2
  "name": "<%= projectName %>",
3
3
  "version": "1.0.0",
4
4
  "description": "<%= projectDescription %>",
5
+ "types": "./dist/types/index.d.ts",
5
6
  "exports": {
6
- ".": {
7
- "require": "./dist/cjs/index.js",
8
- "import": "./dist/mjs/index.js"
9
- }
10
- },
11
- "types": "./dist/mjs/index.d.ts",
7
+ ".": {
8
+ "require": "./dist/cjs/index.js",
9
+ "import": "./dist/mjs/index.mjs",
10
+ "types": "./dist/types/index.d.ts"
11
+ }
12
+ },
12
13
  "scripts": {
13
14
  "test": "jest",
14
15
  "expand-macro": "powershell scripts/expand-macro",
@@ -1,8 +1,25 @@
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"
1
+ # compiletsupv1.0.0
2
+ if (Test-Path dist) {
3
+ Write-Output "开始删除原dist"
4
+ Remove-Item -Recurse -Force dist
5
+ }
6
+ Write-Output "开始类型检查..."
7
+ # 用 tsc 做类型检查
8
+ # tsc -p tsconfig.compile.json
9
+ tsc -p tsconfig.compile.json --noEmit
10
+ if ($LASTEXITCODE -ne 0) {
11
+ Write-Error "类型检查失败, 停止编译"
12
+ exit $LASTEXITCODE
13
+ }
14
+
15
+ Write-Output "类型检查通过, 开始 tsup 编译..."
16
+
17
+ # 执行 tsup
18
+ $tsupOutput = tsup --silent 2>&1
19
+ if ($LASTEXITCODE -ne 0) {
20
+ Write-Error "tsup 编译失败"
21
+ Write-Output $tsupOutput # 只在失败时打印 tsup 的输出
22
+ exit $LASTEXITCODE
23
+ }
24
+
25
+ Write-Output "编译完成"
@@ -1,4 +1,7 @@
1
- Write-Output 开始编译
2
- npm run compile
1
+ npm run compile
2
+ if ($LASTEXITCODE -ne 0) {
3
+ Write-Error "编译失败, 停止发布"
4
+ exit $LASTEXITCODE
5
+ }
3
6
  Write-Output 开始发布
4
7
  npx zcli release
@@ -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,35 @@
1
+ const { defineConfig } = require("tsup");
2
+
3
+ const common = {
4
+ entry: [
5
+ "src/**/*.ts",
6
+ "!**/test/**",
7
+ "!src/**/*.macro.ts",
8
+ ],
9
+ tsconfig: 'tsconfig.compile.json',
10
+ clean: false,
11
+ dts: false,
12
+ external: []
13
+ }
14
+ export default defineConfig([
15
+ // CommonJS 输出
16
+ {
17
+ ...common,
18
+ format: ["cjs"],
19
+ outDir: "dist/cjs",
20
+ target: "es2022",
21
+ },
22
+ // ESM 输出
23
+ {
24
+ ...common,
25
+ format: ["esm"],
26
+ outDir: "dist/mjs",
27
+ target: "esnext",
28
+ },
29
+ {
30
+ ...common,
31
+ name: "types",
32
+ dts: { only: true },
33
+ outDir: "dist/types",
34
+ }
35
+ ]);
@@ -0,0 +1,3 @@
1
+ **/node_modules/**
2
+ **/test/**
3
+ dist/**
@@ -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,13 @@
1
+ npm run expand-macro
2
+ # compile v1.0.0
3
+ if (Test-Path dist) {
4
+ Write-Output "开始删除原dist"
5
+ Remove-Item -Recurse -Force dist
6
+ }
7
+ Write-Output 开始编译
8
+ tsc -p tsconfig.compile.json
9
+ if ($LASTEXITCODE -ne 0) {
10
+ Write-Error "tsc 编译失败"
11
+ exit $LASTEXITCODE
12
+ }
13
+ tsc-alias -p tsconfig.compile.json
@@ -0,0 +1,2 @@
1
+ Write-Output 开始展开宏
2
+ npx zcli Expand-Macro
@@ -0,0 +1,8 @@
1
+ # releasev1.0.0
2
+ npm run compile
3
+ if ($LASTEXITCODE -ne 0) {
4
+ Write-Error "编译失败, 停止发布"
5
+ exit $LASTEXITCODE
6
+ }
7
+ Write-Output 开始发布
8
+ npx zcli release
@@ -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,6 @@
1
+ import { UtilMacro } from '@zwa73/dev-utils';
2
+
3
+
4
+
5
+
6
+ UtilMacro.exportComment('src/**/index.ts');
@@ -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": "^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",
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": "^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": "*",
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",
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": "^1.0.1",
50
- "react": "^18.3.1",
51
- "react-dom": "^18.3.1",
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
  }
@@ -0,0 +1,6 @@
1
+ import type { Command } from 'commander';
2
+ export declare const bump: (opt: {
3
+ version?: string;
4
+ }) => Promise<void>;
5
+ /**更新版本号 */
6
+ export declare const CmdBump: (program: Command) => Command;
@@ -0,0 +1,70 @@
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.CmdBump = exports.bump = void 0;
7
+ const utils_1 = require("@zwa73/utils");
8
+ const pathe_1 = __importDefault(require("pathe"));
9
+ const RouteInterface_1 = require("./RouteInterface");
10
+ /**解析版本号为number数组 */
11
+ function parseVersion(version) {
12
+ const arr = version.split(".").map(Number);
13
+ if (arr.length !== 3)
14
+ (0, utils_1.throwError)(`${version} 不是有效的版本号`, 'error');
15
+ for (let i = 0; i < 3; i++) {
16
+ if (!isFinite(arr[i]))
17
+ (0, utils_1.throwError)(`${version} 不是有效的版本号`, 'error');
18
+ }
19
+ return arr;
20
+ }
21
+ /**判断版本号是否有效 */
22
+ function checkVersion(oldVersion, newVersion) {
23
+ const oldParts = parseVersion(oldVersion);
24
+ const newParts = parseVersion(newVersion);
25
+ for (let i = 0; i < 3; i++) {
26
+ if (newParts[i] < oldParts[i])
27
+ (0, utils_1.throwError)(`${newVersion} 低于当前版本号 ${oldVersion}`, 'error');
28
+ if (newParts[i] > oldParts[i])
29
+ break;
30
+ }
31
+ }
32
+ /**更新版本号 */
33
+ async function updateVersion(newVersion) {
34
+ const packagePath = pathe_1.default.join(RouteInterface_1.PROCESS_PATH, "package.json");
35
+ const packageData = await (0, utils_1.memoize)(utils_1.UtilFT.loadJSONFile)(packagePath);
36
+ if (newVersion == 'current')
37
+ return packageData.version;
38
+ if (newVersion) {
39
+ checkVersion(packageData.version, newVersion);
40
+ packageData.version = newVersion;
41
+ }
42
+ else {
43
+ const version = packageData.version.split(".");
44
+ version[2] = (parseInt(version[2]) + 1).toString();
45
+ packageData.version = version.join(".");
46
+ }
47
+ await utils_1.UtilFT.writeJSONFile(packagePath, packageData);
48
+ return packageData.version;
49
+ }
50
+ const bump = async (opt) => {
51
+ await (0, RouteInterface_1.checkProject)();
52
+ utils_1.SLogger.info(`开始更新版本号`);
53
+ try {
54
+ const newVersion = await updateVersion(opt.version);
55
+ utils_1.SLogger.info(`新版本号: ${newVersion}`);
56
+ }
57
+ catch (error) {
58
+ utils_1.SLogger.error(error);
59
+ throw error;
60
+ }
61
+ };
62
+ exports.bump = bump;
63
+ /**更新版本号 */
64
+ const CmdBump = (program) => program
65
+ .command("bump")
66
+ .alias("version")
67
+ .description("更新项目版本号")
68
+ .option("-v, --version <version>", "指定版本号, 为 `current` 时不更新版本号, 格式应为 `${number}.${number}.${number}`")
69
+ .action(exports.bump);
70
+ exports.CmdBump = CmdBump;
@@ -0,0 +1,10 @@
1
+ import type { LogLevel } from "@zwa73/utils";
2
+ import type { Command } from "commander";
3
+ /**检查npm token过期 */
4
+ export declare function checkNpmToken(opt?: {
5
+ logstd?: boolean;
6
+ threshold?: number;
7
+ loglvl?: LogLevel | 'none' | ((v: string) => void);
8
+ }): Promise<string | undefined>;
9
+ /**更新版本号并发布npm包 */
10
+ export declare const CmdCheckToken: (program: Command) => Command;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CmdCheckToken = void 0;
4
+ exports.checkNpmToken = checkNpmToken;
5
+ const utils_1 = require("@zwa73/utils");
6
+ /**检查npm token过期 */
7
+ async function checkNpmToken(opt) {
8
+ const { logstd = false, threshold = 15, loglvl = 'warn', } = opt ?? {};
9
+ try {
10
+ const { stderr, stdout } = await utils_1.UtilFunc.exec('npm token list', {
11
+ outlvl: logstd ? console.log : undefined
12
+ });
13
+ // 正则:
14
+ //Publish token npm_a0… with id 616dfb created 2025-12-05
15
+ //with IP whitelist:
16
+ // [1] 前缀 npm_xxx [2] id [3] 创建日期 yyyy-mm-dd
17
+ const re = /token\s+(npm_[^\s]+).*?id\s+([a-z0-9]+).*?created\s+(\d{4}-\d{2}-\d{2})/gi;
18
+ const now = new Date();
19
+ const msg = [];
20
+ for (const m of stdout.matchAll(re)) {
21
+ const [, prefix, id, created] = m;
22
+ const createdDate = new Date(created);
23
+ // 默认 Granular Token 有效期 90 天;Classic 看起来“Never”,可按需特殊处理
24
+ const expiresDate = new Date(createdDate.getTime() + 90 * 24 * 60 * 60 * 1000);
25
+ const daysLeft = Math.floor((expiresDate.getTime() - now.getTime()) / (1000 * 60 * 60 * 24));
26
+ if (daysLeft <= threshold)
27
+ msg.push(`⚠️ Token ${prefix} with id ${id} 即将过期, 剩余 ${daysLeft} 天, 过期 ${expiresDate.toISOString().slice(0, 10)}`);
28
+ }
29
+ const msgText = msg.join('\n');
30
+ if (msgText.length > 0) {
31
+ if (typeof loglvl == 'string' && loglvl !== 'none')
32
+ utils_1.SLogger.log(loglvl, msgText);
33
+ else if (typeof loglvl == 'function')
34
+ loglvl(msgText);
35
+ return msgText;
36
+ }
37
+ return undefined;
38
+ }
39
+ catch (e) {
40
+ utils_1.SLogger.error('checkNpmToken 错误', e);
41
+ return undefined;
42
+ }
43
+ }
44
+ /**更新版本号并发布npm包 */
45
+ const CmdCheckToken = (program) => program
46
+ .command("Check-Token")
47
+ .alias("checktoken")
48
+ .description("检查npm token是否即将过期")
49
+ .action(async () => {
50
+ await checkNpmToken({ logstd: true });
51
+ });
52
+ exports.CmdCheckToken = CmdCheckToken;
@@ -1,3 +1,3 @@
1
- import { Command } from "commander";
1
+ import type { Command } from "commander";
2
2
  /**构造macro */
3
3
  export declare const CmdExpandMacro: (program: Command) => Command;
@@ -1,3 +1,3 @@
1
- import { Command } from "commander";
1
+ import type { Command } from "commander";
2
2
  /**生成i18n */
3
3
  export declare const CmdGenI18n: (program: Command) => Command;
@@ -5,18 +5,22 @@ 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
- const UtilAst_1 = require("../UtilAst");
10
8
  const pathe_1 = __importDefault(require("pathe"));
9
+ const DynImport_1 = require("../DynImport");
10
+ const UtilAst_1 = require("../UtilAst");
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
+ if (!TsMorph)
17
+ (0, utils_1.throwError)(`ts-morph 未安装`);
18
+ const { SyntaxKind } = TsMorph;
15
19
  const date = new Date().toISOString();
16
20
  //const content = await fs.promises.readFile(filePath,'utf-8');
17
21
  const b = p.addSourceFileAtPath(filePath);
18
22
  //const b = p.createSourceFile(path.relative(process.cwd(),filePath),content,{overwrite:true});
19
- const ds = b.getDescendantsOfKind(ts_morph_1.SyntaxKind.TaggedTemplateExpression);
23
+ const ds = b.getDescendantsOfKind(SyntaxKind.TaggedTemplateExpression);
20
24
  const dats = [];
21
25
  for (const d of ds) {
22
26
  if (!funckey.includes(d.getTag().getText()))
@@ -25,17 +29,17 @@ async function procFile(p, filePath, funckey) {
25
29
  let result = '';
26
30
  let i = 0;
27
31
  UtilAst_1.UtilAst.withKind(template, {
28
- [ts_morph_1.SyntaxKind.NoSubstitutionTemplateLiteral]: (t) => result += format(t.getLiteralText()),
29
- [ts_morph_1.SyntaxKind.TemplateExpression]: (t) => {
32
+ [SyntaxKind.NoSubstitutionTemplateLiteral]: (t) => result += format(t.getLiteralText()),
33
+ [SyntaxKind.TemplateExpression]: (t) => {
30
34
  t.getChildren().forEach((c) => {
31
35
  UtilAst_1.UtilAst.withKind(c, {
32
- [ts_morph_1.SyntaxKind.TemplateHead]: (sc) => result += format(sc.getLiteralText()),
33
- [ts_morph_1.SyntaxKind.SyntaxList]: (sc) => {
34
- sc.getChildrenOfKind(ts_morph_1.SyntaxKind.TemplateSpan).forEach((span) => {
36
+ [SyntaxKind.TemplateHead]: (sc) => result += format(sc.getLiteralText()),
37
+ [SyntaxKind.SyntaxList]: (sc) => {
38
+ sc.getChildrenOfKind(SyntaxKind.TemplateSpan).forEach((span) => {
35
39
  span.getChildren().forEach((ssc) => {
36
40
  result += UtilAst_1.UtilAst.withKind(ssc, {
37
- [ts_morph_1.SyntaxKind.TemplateMiddle]: (sssc) => format(sssc.getLiteralText()),
38
- [ts_morph_1.SyntaxKind.TemplateTail]: (sssc) => format(sssc.getLiteralText()),
41
+ [SyntaxKind.TemplateMiddle]: (sssc) => format(sssc.getLiteralText()),
42
+ [SyntaxKind.TemplateTail]: (sssc) => format(sssc.getLiteralText()),
39
43
  }) ?? String(`%${i++}`);
40
44
  });
41
45
  });
@@ -57,13 +61,17 @@ async function procFile(p, filePath, funckey) {
57
61
  return dats;
58
62
  }
59
63
  async function scanI18n(i18nDataDir, include, exclude, funckey) {
64
+ const TsMorph = await (0, DynImport_1.importTsMorph)();
65
+ if (!TsMorph)
66
+ (0, utils_1.throwError)(`ts-morph 未安装`);
67
+ const { Project } = TsMorph;
60
68
  const fixedKey = typeof funckey == 'string' ? [funckey] : funckey;
61
69
  const filePaths = (await utils_1.UtilFT.fileSearchGlob(process.cwd(), include, { ingore: exclude }))
62
70
  .filter(p => ['.ts', '.tsx'].includes(pathe_1.default.parse(p).ext));
63
- const project = new ts_morph_1.Project();
71
+ const project = new Project();
64
72
  await utils_1.SI18n.init(i18nDataDir, '*');
65
73
  //console.log(filePaths);
66
- (await Promise.all(filePaths.map(p => procFile(project, p, fixedKey))))
74
+ (await Promise.all(filePaths.map(async (p) => procFile(project, p, fixedKey))))
67
75
  .flat().forEach(dat => utils_1.SI18n.addOriginalText(dat));
68
76
  await utils_1.SI18n.saveTable();
69
77
  }
@@ -1,3 +1,3 @@
1
- import { Command } from "commander";
1
+ import type { Command } from "commander";
2
2
  /**生成schema */
3
3
  export declare const CmdGenSchema: (program: Command) => Command;
@@ -1,3 +1,3 @@
1
- import { Command } from "commander";
1
+ import type { Command } from "commander";
2
2
  /**生成schema */
3
3
  export declare const CmdGenTemplate: (program: Command) => Command;
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.CmdGenTemplate = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const utils_1 = require("@zwa73/utils");
7
9
  const pathe_1 = __importDefault(require("pathe"));
8
10
  const RouteInterface_1 = require("./RouteInterface");
9
- const utils_1 = require("@zwa73/utils");
10
- const fs_1 = __importDefault(require("fs"));
11
11
  /**复制基础文件 */
12
12
  async function copyData(templatePath, projectPath) {
13
13
  const filelist = await fs_1.default.promises.readdir(templatePath);
@@ -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
- await installPackage(projectPath, ['@zwa73/utils'], ['@types/node']);
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;
@@ -1,3 +1,3 @@
1
- import { Command } from "commander";
1
+ import type { Command } from "commander";
2
2
  /**重命名文件或路径 */
3
3
  export declare const CmdMapPath: (program: Command) => Command;