@lsby/net-core 0.0.15 → 0.0.16-beta.1

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 (90) hide show
  1. package/dist/bin/gen-list/bin.cjs +66 -76
  2. package/dist/bin/gen-list/index.cjs +66 -76
  3. package/dist/bin/gen-test/bin.cjs +74 -84
  4. package/dist/bin/gen-test/index.cjs +74 -84
  5. package/dist/bin/gen-type/bin.cjs +78 -88
  6. package/dist/bin/gen-type/index.cjs +78 -88
  7. package/dist/cjs/bin/gen-list/bin.cjs +66 -76
  8. package/dist/cjs/bin/gen-list/index.cjs +66 -76
  9. package/dist/cjs/bin/gen-test/bin.cjs +74 -84
  10. package/dist/cjs/bin/gen-test/index.cjs +74 -84
  11. package/dist/cjs/bin/gen-type/bin.cjs +78 -88
  12. package/dist/cjs/bin/gen-type/index.cjs +78 -88
  13. package/dist/cjs/global/global.cjs +20 -32
  14. package/dist/cjs/global/global.d.cts +1 -2
  15. package/dist/cjs/index.cjs +107 -153
  16. package/dist/cjs/index.d.cts +0 -1
  17. package/dist/cjs/interface/interface-type.d.cts +0 -1
  18. package/dist/cjs/interface/interface.d.cts +1 -2
  19. package/dist/cjs/interface/plug.d.cts +1 -2
  20. package/dist/cjs/plugin/chinese-path.cjs +6 -10
  21. package/dist/cjs/plugin/chinese-path.d.cts +0 -1
  22. package/dist/cjs/plugin/custom-data.cjs +1 -2
  23. package/dist/cjs/plugin/custom-data.d.cts +0 -1
  24. package/dist/cjs/plugin/json.cjs +36 -52
  25. package/dist/cjs/plugin/json.d.cts +0 -1
  26. package/dist/cjs/plugin/urlencoded.cjs +11 -15
  27. package/dist/cjs/plugin/urlencoded.d.cts +0 -1
  28. package/dist/cjs/result/result.cjs +29 -46
  29. package/dist/cjs/result/result.d.cts +5 -6
  30. package/dist/cjs/server/server.cjs +61 -89
  31. package/dist/cjs/server/server.d.cts +1 -2
  32. package/dist/cjs/test/test.cjs +3 -3
  33. package/dist/cjs/test/test.d.cts +1 -2
  34. package/dist/cjs/tools/get-pro-name.cjs +9 -12
  35. package/dist/cjs/tools/get-pro-name.d.cts +1 -3
  36. package/dist/cjs/tools/log.cjs +6 -13
  37. package/dist/cjs/tools/log.d.cts +3 -5
  38. package/dist/esm/bin/gen-list/bin.js +2 -2
  39. package/dist/esm/bin/gen-list/index.js +2 -2
  40. package/dist/esm/bin/gen-test/bin.js +2 -2
  41. package/dist/esm/bin/gen-test/index.js +2 -2
  42. package/dist/esm/bin/gen-type/bin.js +2 -2
  43. package/dist/esm/bin/gen-type/index.js +2 -2
  44. package/dist/esm/chunk-2BXFPOH7.js +21 -0
  45. package/dist/esm/{chunk-6MRTDFSR.js → chunk-5FNMT2PW.js} +10 -15
  46. package/dist/esm/chunk-5UUMGDDD.js +26 -0
  47. package/dist/esm/{chunk-UX3PS2US.js → chunk-7LWIMBMX.js} +7 -9
  48. package/dist/esm/chunk-ALBZFUFF.js +78 -0
  49. package/dist/esm/chunk-AMLY6GJ7.js +35 -0
  50. package/dist/esm/{chunk-PLYBVQKK.js → chunk-BZOQHDXK.js} +6 -13
  51. package/dist/esm/chunk-FXHL3NIN.js +94 -0
  52. package/dist/esm/chunk-GTG2AAAC.js +63 -0
  53. package/dist/esm/{chunk-ET2XZBZD.js → chunk-JOVAHJTO.js} +3 -3
  54. package/dist/esm/{chunk-LVYS3C7A.js → chunk-P6PGPAMW.js} +1 -2
  55. package/dist/esm/chunk-VLNWJ4OM.js +87 -0
  56. package/dist/esm/chunk-XG4VZZOX.js +22 -0
  57. package/dist/esm/global/global.d.ts +1 -2
  58. package/dist/esm/global/global.js +3 -3
  59. package/dist/esm/index.d.ts +0 -1
  60. package/dist/esm/index.js +16 -16
  61. package/dist/esm/interface/interface-type.d.ts +0 -1
  62. package/dist/esm/interface/interface.d.ts +1 -2
  63. package/dist/esm/interface/plug.d.ts +1 -2
  64. package/dist/esm/plugin/chinese-path.d.ts +0 -1
  65. package/dist/esm/plugin/chinese-path.js +1 -1
  66. package/dist/esm/plugin/custom-data.d.ts +0 -1
  67. package/dist/esm/plugin/custom-data.js +1 -1
  68. package/dist/esm/plugin/json.d.ts +0 -1
  69. package/dist/esm/plugin/json.js +4 -4
  70. package/dist/esm/plugin/urlencoded.d.ts +0 -1
  71. package/dist/esm/plugin/urlencoded.js +1 -1
  72. package/dist/esm/result/result.d.ts +5 -6
  73. package/dist/esm/result/result.js +4 -4
  74. package/dist/esm/server/server.d.ts +1 -2
  75. package/dist/esm/server/server.js +4 -4
  76. package/dist/esm/test/test.d.ts +1 -2
  77. package/dist/esm/test/test.js +1 -1
  78. package/dist/esm/tools/get-pro-name.d.ts +1 -3
  79. package/dist/esm/tools/get-pro-name.js +1 -1
  80. package/dist/esm/tools/log.d.ts +3 -5
  81. package/dist/esm/tools/log.js +1 -1
  82. package/package.json +1 -2
  83. package/dist/esm/chunk-6B6B4ORK.js +0 -81
  84. package/dist/esm/chunk-75WPG7GQ.js +0 -26
  85. package/dist/esm/chunk-7FRLG3EW.js +0 -24
  86. package/dist/esm/chunk-NONZJEA2.js +0 -97
  87. package/dist/esm/chunk-TAOTBUWM.js +0 -79
  88. package/dist/esm/chunk-UNQLD6KL.js +0 -30
  89. package/dist/esm/chunk-VTGSN4Y4.js +0 -39
  90. package/dist/esm/chunk-ZEWFWADM.js +0 -90
@@ -36,11 +36,9 @@ module.exports = __toCommonJS(gen_test_exports);
36
36
  var import_node_fs = __toESM(require("fs"), 1);
37
37
  var import_node_path = __toESM(require("path"), 1);
38
38
  var import_typescript = __toESM(require("typescript"), 1);
39
- var import_ts_fp_data2 = require("@lsby/ts-fp-data");
40
39
 
41
40
  // src/tools/log.ts
42
41
  var import_debug = __toESM(require("debug"), 1);
43
- var import_ts_fp_data = require("@lsby/ts-fp-data");
44
42
  var Log = class _Log {
45
43
  constructor(fileName) {
46
44
  this.fileName = fileName;
@@ -56,97 +54,89 @@ var Log = class _Log {
56
54
  extend(name) {
57
55
  return new _Log(`${this.fileName}:${name}`);
58
56
  }
59
- info(formatter, ...args) {
60
- return new import_ts_fp_data.Task(async () => {
61
- this._info(formatter, ...args);
62
- });
57
+ async info(formatter, ...args) {
58
+ this._info(formatter, ...args);
63
59
  }
64
- debug(formatter, ...args) {
65
- return new import_ts_fp_data.Task(async () => {
66
- this._debug(formatter, ...args);
67
- });
60
+ async debug(formatter, ...args) {
61
+ this._debug(formatter, ...args);
68
62
  }
69
- err(formatter, ...args) {
70
- return new import_ts_fp_data.Task(async () => {
71
- this._err(formatter, ...args);
72
- });
63
+ async err(formatter, ...args) {
64
+ this._err(formatter, ...args);
73
65
  }
74
66
  };
75
67
 
76
68
  // src/bin/gen-test/index.ts
77
- function main(tsconfigPath, interfaceFolderPath, outFilePath, filter) {
78
- return new import_ts_fp_data2.Task(async () => {
79
- var log = new Log("@lsby:net-core").extend("gen-test");
80
- const projectRootPath = import_node_path.default.dirname(tsconfigPath);
81
- const tsconfigJson = import_typescript.default.parseConfigFileTextToJson(tsconfigPath, import_node_fs.default.readFileSync(tsconfigPath, "utf8"));
82
- if (tsconfigJson.error) {
83
- throw new Error("\u65E0\u6CD5\u89E3\u6790 tsconfig.json");
84
- }
85
- const parsedTsconfig = import_typescript.default.parseJsonConfigFileContent(tsconfigJson.config, import_typescript.default.sys, import_node_path.default.resolve(tsconfigPath, ".."));
86
- await log.debug("\u6210\u529F\u89E3\u6790 tsconfig \u6587\u4EF6...").run();
87
- const projectHost = import_typescript.default.createCompilerHost(parsedTsconfig.options);
88
- const project = import_typescript.default.createProgram(parsedTsconfig.fileNames, parsedTsconfig.options, projectHost);
89
- await log.debug("\u6210\u529F\u8BFB\u53D6\u9879\u76EE...").run();
90
- const _check = project.getTypeChecker();
91
- const allSourceFiles = project.getSourceFiles();
92
- const typeSourceFiles = allSourceFiles.filter((sourceFile) => {
93
- return new RegExp(`${interfaceFolderPath.replaceAll("\\", "\\\\")}.*type.ts`).test(
94
- import_node_path.default.resolve(sourceFile.fileName)
95
- );
96
- });
97
- const testSourceFiles = allSourceFiles.filter((sourceFile) => {
98
- return new RegExp(`${interfaceFolderPath.replaceAll("\\", "\\\\")}.*.test.ts`).test(
99
- import_node_path.default.resolve(sourceFile.fileName)
100
- );
101
- });
102
- const testSourceFilesFilter = testSourceFiles.filter((sourceFile) => {
103
- return new RegExp(filter).test(import_node_path.default.resolve(sourceFile.fileName));
104
- });
105
- await log.debug(
106
- "\u627E\u5230 %o \u4E2A\u63A5\u53E3\uFF0C\u5176\u4E2D\u6709 %o \u4E2A\u6D4B\u8BD5\uFF0C\u7B5B\u9009\u540E\u8FD8\u5269 %o \u4E2A...",
107
- typeSourceFiles.length,
108
- testSourceFiles.length,
109
- testSourceFilesFilter.length
110
- ).run();
111
- const importCode = [];
112
- const testCode = [];
113
- for (var index = 0; index < testSourceFilesFilter.length; index++) {
114
- var testSourceFile = testSourceFilesFilter[index];
115
- if (testSourceFile == null)
116
- throw new Error("\u975E\u9884\u671F\u7684\u6570\u7EC4\u8D8A\u754C");
117
- const filenameRelativeToApiFolder = import_node_path.default.relative(interfaceFolderPath, testSourceFile.fileName).replaceAll("\\", "/");
118
- const importName = filenameRelativeToApiFolder.replaceAll("/", "_").replaceAll(".test.ts", "").replaceAll("./", "").replaceAll("-", "_");
119
- const filenameRelativeToProjectRoot = import_node_path.default.relative(projectRootPath, testSourceFile.fileName).replaceAll("\\", "/").replaceAll(".ts", "");
120
- const outputFolderRelativeToProjectRoot = import_node_path.default.relative(import_node_path.default.dirname(outFilePath), projectRootPath).replaceAll("\\", "/");
121
- const importPath = import_node_path.default.join(outputFolderRelativeToProjectRoot, filenameRelativeToProjectRoot).replaceAll("\\", "/");
122
- await log.info(`\u5904\u7406\uFF08${index + 1} / ${testSourceFilesFilter.length}\uFF09\uFF1A${filenameRelativeToApiFolder}`).run();
123
- for (const node of testSourceFile.statements) {
124
- if (import_typescript.default.isExportAssignment(node) && node.isExportEquals === void 0) {
125
- const expression = node.expression;
126
- if (import_typescript.default.isNewExpression(expression) && expression.expression.getText() === "\u6D4B\u8BD5") {
127
- break;
128
- }
129
- throw new Error(`${testSourceFile.fileName}\uFF1A\u9ED8\u8BA4\u5BFC\u51FA\u4E0D\u662F \u6D4B\u8BD5`);
69
+ async function main(tsconfigPath, interfaceFolderPath, outFilePath, filter) {
70
+ var log = new Log("@lsby:net-core").extend("gen-test");
71
+ const projectRootPath = import_node_path.default.dirname(tsconfigPath);
72
+ const tsconfigJson = import_typescript.default.parseConfigFileTextToJson(tsconfigPath, import_node_fs.default.readFileSync(tsconfigPath, "utf8"));
73
+ if (tsconfigJson.error) {
74
+ throw new Error("\u65E0\u6CD5\u89E3\u6790 tsconfig.json");
75
+ }
76
+ const parsedTsconfig = import_typescript.default.parseJsonConfigFileContent(tsconfigJson.config, import_typescript.default.sys, import_node_path.default.resolve(tsconfigPath, ".."));
77
+ await log.debug("\u6210\u529F\u89E3\u6790 tsconfig \u6587\u4EF6...");
78
+ const projectHost = import_typescript.default.createCompilerHost(parsedTsconfig.options);
79
+ const project = import_typescript.default.createProgram(parsedTsconfig.fileNames, parsedTsconfig.options, projectHost);
80
+ await log.debug("\u6210\u529F\u8BFB\u53D6\u9879\u76EE...");
81
+ const _check = project.getTypeChecker();
82
+ const allSourceFiles = project.getSourceFiles();
83
+ const typeSourceFiles = allSourceFiles.filter((sourceFile) => {
84
+ return new RegExp(`${interfaceFolderPath.replaceAll("\\", "\\\\")}.*type.ts`).test(
85
+ import_node_path.default.resolve(sourceFile.fileName)
86
+ );
87
+ });
88
+ const testSourceFiles = allSourceFiles.filter((sourceFile) => {
89
+ return new RegExp(`${interfaceFolderPath.replaceAll("\\", "\\\\")}.*.test.ts`).test(
90
+ import_node_path.default.resolve(sourceFile.fileName)
91
+ );
92
+ });
93
+ const testSourceFilesFilter = testSourceFiles.filter((sourceFile) => {
94
+ return new RegExp(filter).test(import_node_path.default.resolve(sourceFile.fileName));
95
+ });
96
+ await log.debug(
97
+ "\u627E\u5230 %o \u4E2A\u63A5\u53E3\uFF0C\u5176\u4E2D\u6709 %o \u4E2A\u6D4B\u8BD5\uFF0C\u7B5B\u9009\u540E\u8FD8\u5269 %o \u4E2A...",
98
+ typeSourceFiles.length,
99
+ testSourceFiles.length,
100
+ testSourceFilesFilter.length
101
+ );
102
+ const importCode = [];
103
+ const testCode = [];
104
+ for (var index = 0; index < testSourceFilesFilter.length; index++) {
105
+ var testSourceFile = testSourceFilesFilter[index];
106
+ if (testSourceFile == null)
107
+ throw new Error("\u975E\u9884\u671F\u7684\u6570\u7EC4\u8D8A\u754C");
108
+ const filenameRelativeToApiFolder = import_node_path.default.relative(interfaceFolderPath, testSourceFile.fileName).replaceAll("\\", "/");
109
+ const importName = filenameRelativeToApiFolder.replaceAll("/", "_").replaceAll(".test.ts", "").replaceAll("./", "").replaceAll("-", "_");
110
+ const filenameRelativeToProjectRoot = import_node_path.default.relative(projectRootPath, testSourceFile.fileName).replaceAll("\\", "/").replaceAll(".ts", "");
111
+ const outputFolderRelativeToProjectRoot = import_node_path.default.relative(import_node_path.default.dirname(outFilePath), projectRootPath).replaceAll("\\", "/");
112
+ const importPath = import_node_path.default.join(outputFolderRelativeToProjectRoot, filenameRelativeToProjectRoot).replaceAll("\\", "/");
113
+ await log.info(`\u5904\u7406\uFF08${index + 1} / ${testSourceFilesFilter.length}\uFF09\uFF1A${filenameRelativeToApiFolder}`);
114
+ for (const node of testSourceFile.statements) {
115
+ if (import_typescript.default.isExportAssignment(node) && node.isExportEquals === void 0) {
116
+ const expression = node.expression;
117
+ if (import_typescript.default.isNewExpression(expression) && expression.expression.getText() === "\u6D4B\u8BD5") {
118
+ break;
130
119
  }
120
+ throw new Error(`${testSourceFile.fileName}\uFF1A\u9ED8\u8BA4\u5BFC\u51FA\u4E0D\u662F \u6D4B\u8BD5`);
131
121
  }
132
- importCode.push(`import ${importName} from '${importPath}'`);
133
- testCode.push(generateTestCode(importName, importName));
134
- }
135
- const finalTestFile = [
136
- "import { test } from 'vitest'",
137
- "import './unit-test-prefix'",
138
- "",
139
- ...importCode,
140
- "",
141
- ...testCode,
142
- ""
143
- ].join("\n");
144
- var outDir = import_node_path.default.dirname(outFilePath);
145
- if (!(0, import_node_fs.existsSync)(outDir)) {
146
- (0, import_node_fs.mkdirSync)(outDir, { recursive: true });
147
122
  }
148
- (0, import_node_fs.writeFileSync)(outFilePath, finalTestFile);
149
- }).run();
123
+ importCode.push(`import ${importName} from '${importPath}'`);
124
+ testCode.push(generateTestCode(importName, importName));
125
+ }
126
+ const finalTestFile = [
127
+ "import { test } from 'vitest'",
128
+ "import './unit-test-prefix'",
129
+ "",
130
+ ...importCode,
131
+ "",
132
+ ...testCode,
133
+ ""
134
+ ].join("\n");
135
+ var outDir = import_node_path.default.dirname(outFilePath);
136
+ if (!(0, import_node_fs.existsSync)(outDir)) {
137
+ (0, import_node_fs.mkdirSync)(outDir, { recursive: true });
138
+ }
139
+ (0, import_node_fs.writeFileSync)(outFilePath, finalTestFile);
150
140
  }
151
141
  function generateTestCode(testCaseName, importName) {
152
142
  return `test('${testCaseName}', async () => await ${importName}.\u8FD0\u884C())`;
@@ -32,11 +32,9 @@ var import_node_crypto = require("crypto");
32
32
  var import_node_fs = __toESM(require("fs"), 1);
33
33
  var import_node_path = __toESM(require("path"), 1);
34
34
  var import_typescript = __toESM(require("typescript"), 1);
35
- var import_ts_fp_data2 = require("@lsby/ts-fp-data");
36
35
 
37
36
  // src/tools/log.ts
38
37
  var import_debug = __toESM(require("debug"), 1);
39
- var import_ts_fp_data = require("@lsby/ts-fp-data");
40
38
  var Log = class _Log {
41
39
  constructor(fileName) {
42
40
  this.fileName = fileName;
@@ -52,20 +50,14 @@ var Log = class _Log {
52
50
  extend(name) {
53
51
  return new _Log(`${this.fileName}:${name}`);
54
52
  }
55
- info(formatter, ...args) {
56
- return new import_ts_fp_data.Task(async () => {
57
- this._info(formatter, ...args);
58
- });
53
+ async info(formatter, ...args) {
54
+ this._info(formatter, ...args);
59
55
  }
60
- debug(formatter, ...args) {
61
- return new import_ts_fp_data.Task(async () => {
62
- this._debug(formatter, ...args);
63
- });
56
+ async debug(formatter, ...args) {
57
+ this._debug(formatter, ...args);
64
58
  }
65
- err(formatter, ...args) {
66
- return new import_ts_fp_data.Task(async () => {
67
- this._err(formatter, ...args);
68
- });
59
+ async err(formatter, ...args) {
60
+ this._err(formatter, ...args);
69
61
  }
70
62
  };
71
63
 
@@ -98,85 +90,83 @@ export default Api
98
90
  `;
99
91
 
100
92
  // src/bin/gen-type/index.ts
101
- function main(tsconfigPath, apiFolderPath, outputPath) {
102
- return new import_ts_fp_data2.Task(async () => {
103
- var log = new Log("@lsby:net-core").extend("gen-type");
104
- const tsconfigJson = import_typescript.default.parseConfigFileTextToJson(tsconfigPath, import_node_fs.default.readFileSync(tsconfigPath, "utf8"));
105
- if (tsconfigJson.error) {
106
- throw new Error("\u65E0\u6CD5\u89E3\u6790 tsconfig.json");
107
- }
108
- const parsedTsconfig = import_typescript.default.parseJsonConfigFileContent(tsconfigJson.config, import_typescript.default.sys, import_node_path.default.resolve(tsconfigPath, ".."));
109
- await log.debug("\u6210\u529F\u89E3\u6790 tsconfig \u6587\u4EF6...").run();
110
- const projectHost = import_typescript.default.createCompilerHost(parsedTsconfig.options);
111
- const project = import_typescript.default.createProgram(parsedTsconfig.fileNames, parsedTsconfig.options, projectHost);
112
- await log.debug("\u6210\u529F\u8BFB\u53D6\u9879\u76EE...").run();
113
- const allSourceFiles = project.getSourceFiles();
114
- const apiSourceFiles = allSourceFiles.filter((sourceFile) => {
115
- return new RegExp(`${apiFolderPath.replaceAll("\\", "\\\\")}.*type.ts`).test(import_node_path.default.resolve(sourceFile.fileName));
116
- });
117
- await log.debug("\u627E\u5230 %o \u4E2A\u63A5\u53E3...", apiSourceFiles.length).run();
118
- const apiTypeCalcFileNames = apiSourceFiles.map(
119
- (sourceFile) => sourceFile.fileName.replace("type.ts", `type-calculate-${(0, import_node_crypto.randomUUID)()}.ts`)
120
- );
121
- const apiTypeCalcFiles = apiTypeCalcFileNames.map((filename) => {
122
- return {
123
- name: filename,
124
- sourceFile: import_typescript.default.createSourceFile(filename, calcCode, import_typescript.default.ScriptTarget.Latest)
125
- };
126
- });
127
- await log.debug("\u6210\u529F\u751F\u6210\u865A\u62DF\u8BA1\u7B97\u6587\u4EF6...").run();
128
- const newProject = import_typescript.default.createProgram({
129
- rootNames: [...parsedTsconfig.fileNames, ...apiTypeCalcFileNames],
130
- options: parsedTsconfig.options,
131
- host: {
132
- ...projectHost,
133
- getSourceFile: (filename) => {
134
- const apiTypeCalcSourceFile = apiTypeCalcFiles.find(
135
- (apiTypeCalcSourceFile2) => apiTypeCalcSourceFile2.name === filename
136
- );
137
- if (apiTypeCalcSourceFile !== void 0) {
138
- return apiTypeCalcSourceFile.sourceFile;
139
- }
140
- return project.getSourceFile(filename);
141
- }
142
- },
143
- oldProgram: project
144
- });
145
- await log.debug("\u6210\u529F\u751F\u6210\u865A\u62DF\u9879\u76EE...").run();
146
- const check = newProject.getTypeChecker();
147
- await log.debug("\u6210\u529F\u751F\u6210\u865A\u62DF\u9879\u76EE\u7C7B\u578B\u68C0\u67E5\u5668...").run();
148
- const result = [];
149
- for (var index = 0; index < apiSourceFiles.length; index++) {
150
- var apiSourceFile = apiSourceFiles[index];
151
- if (apiSourceFile == null)
152
- throw new Error("\u975E\u9884\u671F\u7684\u6570\u7EC4\u8D8A\u754C");
153
- await log.info(`\u5904\u7406\uFF08${index + 1} / ${apiSourceFiles.length}\uFF09\uFF1A${apiSourceFile.fileName}`).run();
154
- const apiCalcSourceFile = apiTypeCalcFiles[index]?.sourceFile;
155
- if (apiCalcSourceFile === void 0) {
156
- throw new Error("\u975E\u9884\u671F\u7684\u6570\u7EC4\u8D8A\u754C");
157
- }
158
- for (const node of apiCalcSourceFile.statements) {
159
- if (import_typescript.default.isExportAssignment(node) && node.isExportEquals === void 0) {
160
- const apiType = check.getTypeAtLocation(node.expression);
161
- const typeString = check.typeToString(
162
- apiType,
163
- void 0,
164
- import_typescript.default.TypeFormatFlags.NoTruncation | import_typescript.default.TypeFormatFlags.AllowUniqueESSymbolType | import_typescript.default.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope
165
- );
166
- result.push(typeString);
93
+ async function main(tsconfigPath, apiFolderPath, outputPath) {
94
+ var log = new Log("@lsby:net-core").extend("gen-type");
95
+ const tsconfigJson = import_typescript.default.parseConfigFileTextToJson(tsconfigPath, import_node_fs.default.readFileSync(tsconfigPath, "utf8"));
96
+ if (tsconfigJson.error) {
97
+ throw new Error("\u65E0\u6CD5\u89E3\u6790 tsconfig.json");
98
+ }
99
+ const parsedTsconfig = import_typescript.default.parseJsonConfigFileContent(tsconfigJson.config, import_typescript.default.sys, import_node_path.default.resolve(tsconfigPath, ".."));
100
+ await log.debug("\u6210\u529F\u89E3\u6790 tsconfig \u6587\u4EF6...");
101
+ const projectHost = import_typescript.default.createCompilerHost(parsedTsconfig.options);
102
+ const project = import_typescript.default.createProgram(parsedTsconfig.fileNames, parsedTsconfig.options, projectHost);
103
+ await log.debug("\u6210\u529F\u8BFB\u53D6\u9879\u76EE...");
104
+ const allSourceFiles = project.getSourceFiles();
105
+ const apiSourceFiles = allSourceFiles.filter((sourceFile) => {
106
+ return new RegExp(`${apiFolderPath.replaceAll("\\", "\\\\")}.*type.ts`).test(import_node_path.default.resolve(sourceFile.fileName));
107
+ });
108
+ await log.debug("\u627E\u5230 %o \u4E2A\u63A5\u53E3...", apiSourceFiles.length);
109
+ const apiTypeCalcFileNames = apiSourceFiles.map(
110
+ (sourceFile) => sourceFile.fileName.replace("type.ts", `type-calculate-${(0, import_node_crypto.randomUUID)()}.ts`)
111
+ );
112
+ const apiTypeCalcFiles = apiTypeCalcFileNames.map((filename) => {
113
+ return {
114
+ name: filename,
115
+ sourceFile: import_typescript.default.createSourceFile(filename, calcCode, import_typescript.default.ScriptTarget.Latest)
116
+ };
117
+ });
118
+ await log.debug("\u6210\u529F\u751F\u6210\u865A\u62DF\u8BA1\u7B97\u6587\u4EF6...");
119
+ const newProject = import_typescript.default.createProgram({
120
+ rootNames: [...parsedTsconfig.fileNames, ...apiTypeCalcFileNames],
121
+ options: parsedTsconfig.options,
122
+ host: {
123
+ ...projectHost,
124
+ getSourceFile: (filename) => {
125
+ const apiTypeCalcSourceFile = apiTypeCalcFiles.find(
126
+ (apiTypeCalcSourceFile2) => apiTypeCalcSourceFile2.name === filename
127
+ );
128
+ if (apiTypeCalcSourceFile !== void 0) {
129
+ return apiTypeCalcSourceFile.sourceFile;
167
130
  }
131
+ return project.getSourceFile(filename);
168
132
  }
133
+ },
134
+ oldProgram: project
135
+ });
136
+ await log.debug("\u6210\u529F\u751F\u6210\u865A\u62DF\u9879\u76EE...");
137
+ const check = newProject.getTypeChecker();
138
+ await log.debug("\u6210\u529F\u751F\u6210\u865A\u62DF\u9879\u76EE\u7C7B\u578B\u68C0\u67E5\u5668...");
139
+ const result = [];
140
+ for (var index = 0; index < apiSourceFiles.length; index++) {
141
+ var apiSourceFile = apiSourceFiles[index];
142
+ if (apiSourceFile == null)
143
+ throw new Error("\u975E\u9884\u671F\u7684\u6570\u7EC4\u8D8A\u754C");
144
+ await log.info(`\u5904\u7406\uFF08${index + 1} / ${apiSourceFiles.length}\uFF09\uFF1A${apiSourceFile.fileName}`);
145
+ const apiCalcSourceFile = apiTypeCalcFiles[index]?.sourceFile;
146
+ if (apiCalcSourceFile === void 0) {
147
+ throw new Error("\u975E\u9884\u671F\u7684\u6570\u7EC4\u8D8A\u754C");
169
148
  }
170
- await log.debug("\u6210\u529F\u5904\u7406\u6240\u6709\u63A5\u53E3...").run();
171
- const outputPathAbs = import_node_path.default.resolve(outputPath);
172
- var outDir = import_node_path.default.dirname(outputPathAbs);
173
- if (!(0, import_node_fs.existsSync)(outDir)) {
174
- (0, import_node_fs.mkdirSync)(outDir, { recursive: true });
149
+ for (const node of apiCalcSourceFile.statements) {
150
+ if (import_typescript.default.isExportAssignment(node) && node.isExportEquals === void 0) {
151
+ const apiType = check.getTypeAtLocation(node.expression);
152
+ const typeString = check.typeToString(
153
+ apiType,
154
+ void 0,
155
+ import_typescript.default.TypeFormatFlags.NoTruncation | import_typescript.default.TypeFormatFlags.AllowUniqueESSymbolType | import_typescript.default.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope
156
+ );
157
+ result.push(typeString);
158
+ }
175
159
  }
176
- import_node_fs.default.writeFileSync(outputPathAbs, `export type InterfaceType = [${result.join(",")}]
160
+ }
161
+ await log.debug("\u6210\u529F\u5904\u7406\u6240\u6709\u63A5\u53E3...");
162
+ const outputPathAbs = import_node_path.default.resolve(outputPath);
163
+ var outDir = import_node_path.default.dirname(outputPathAbs);
164
+ if (!(0, import_node_fs.existsSync)(outDir)) {
165
+ (0, import_node_fs.mkdirSync)(outDir, { recursive: true });
166
+ }
167
+ import_node_fs.default.writeFileSync(outputPathAbs, `export type InterfaceType = [${result.join(",")}]
177
168
  `);
178
- await log.debug("\u751F\u6210\u6210\u529F\uFF1A%o", outputPathAbs).run();
179
- }).run();
169
+ await log.debug("\u751F\u6210\u6210\u529F\uFF1A%o", outputPathAbs);
180
170
  }
181
171
 
182
172
  // src/bin/gen-type/bin.ts
@@ -37,11 +37,9 @@ var import_node_crypto = require("crypto");
37
37
  var import_node_fs = __toESM(require("fs"), 1);
38
38
  var import_node_path = __toESM(require("path"), 1);
39
39
  var import_typescript = __toESM(require("typescript"), 1);
40
- var import_ts_fp_data2 = require("@lsby/ts-fp-data");
41
40
 
42
41
  // src/tools/log.ts
43
42
  var import_debug = __toESM(require("debug"), 1);
44
- var import_ts_fp_data = require("@lsby/ts-fp-data");
45
43
  var Log = class _Log {
46
44
  constructor(fileName) {
47
45
  this.fileName = fileName;
@@ -57,20 +55,14 @@ var Log = class _Log {
57
55
  extend(name) {
58
56
  return new _Log(`${this.fileName}:${name}`);
59
57
  }
60
- info(formatter, ...args) {
61
- return new import_ts_fp_data.Task(async () => {
62
- this._info(formatter, ...args);
63
- });
58
+ async info(formatter, ...args) {
59
+ this._info(formatter, ...args);
64
60
  }
65
- debug(formatter, ...args) {
66
- return new import_ts_fp_data.Task(async () => {
67
- this._debug(formatter, ...args);
68
- });
61
+ async debug(formatter, ...args) {
62
+ this._debug(formatter, ...args);
69
63
  }
70
- err(formatter, ...args) {
71
- return new import_ts_fp_data.Task(async () => {
72
- this._err(formatter, ...args);
73
- });
64
+ async err(formatter, ...args) {
65
+ this._err(formatter, ...args);
74
66
  }
75
67
  };
76
68
 
@@ -103,85 +95,83 @@ export default Api
103
95
  `;
104
96
 
105
97
  // src/bin/gen-type/index.ts
106
- function main(tsconfigPath, apiFolderPath, outputPath) {
107
- return new import_ts_fp_data2.Task(async () => {
108
- var log = new Log("@lsby:net-core").extend("gen-type");
109
- const tsconfigJson = import_typescript.default.parseConfigFileTextToJson(tsconfigPath, import_node_fs.default.readFileSync(tsconfigPath, "utf8"));
110
- if (tsconfigJson.error) {
111
- throw new Error("\u65E0\u6CD5\u89E3\u6790 tsconfig.json");
112
- }
113
- const parsedTsconfig = import_typescript.default.parseJsonConfigFileContent(tsconfigJson.config, import_typescript.default.sys, import_node_path.default.resolve(tsconfigPath, ".."));
114
- await log.debug("\u6210\u529F\u89E3\u6790 tsconfig \u6587\u4EF6...").run();
115
- const projectHost = import_typescript.default.createCompilerHost(parsedTsconfig.options);
116
- const project = import_typescript.default.createProgram(parsedTsconfig.fileNames, parsedTsconfig.options, projectHost);
117
- await log.debug("\u6210\u529F\u8BFB\u53D6\u9879\u76EE...").run();
118
- const allSourceFiles = project.getSourceFiles();
119
- const apiSourceFiles = allSourceFiles.filter((sourceFile) => {
120
- return new RegExp(`${apiFolderPath.replaceAll("\\", "\\\\")}.*type.ts`).test(import_node_path.default.resolve(sourceFile.fileName));
121
- });
122
- await log.debug("\u627E\u5230 %o \u4E2A\u63A5\u53E3...", apiSourceFiles.length).run();
123
- const apiTypeCalcFileNames = apiSourceFiles.map(
124
- (sourceFile) => sourceFile.fileName.replace("type.ts", `type-calculate-${(0, import_node_crypto.randomUUID)()}.ts`)
125
- );
126
- const apiTypeCalcFiles = apiTypeCalcFileNames.map((filename) => {
127
- return {
128
- name: filename,
129
- sourceFile: import_typescript.default.createSourceFile(filename, calcCode, import_typescript.default.ScriptTarget.Latest)
130
- };
131
- });
132
- await log.debug("\u6210\u529F\u751F\u6210\u865A\u62DF\u8BA1\u7B97\u6587\u4EF6...").run();
133
- const newProject = import_typescript.default.createProgram({
134
- rootNames: [...parsedTsconfig.fileNames, ...apiTypeCalcFileNames],
135
- options: parsedTsconfig.options,
136
- host: {
137
- ...projectHost,
138
- getSourceFile: (filename) => {
139
- const apiTypeCalcSourceFile = apiTypeCalcFiles.find(
140
- (apiTypeCalcSourceFile2) => apiTypeCalcSourceFile2.name === filename
141
- );
142
- if (apiTypeCalcSourceFile !== void 0) {
143
- return apiTypeCalcSourceFile.sourceFile;
144
- }
145
- return project.getSourceFile(filename);
146
- }
147
- },
148
- oldProgram: project
149
- });
150
- await log.debug("\u6210\u529F\u751F\u6210\u865A\u62DF\u9879\u76EE...").run();
151
- const check = newProject.getTypeChecker();
152
- await log.debug("\u6210\u529F\u751F\u6210\u865A\u62DF\u9879\u76EE\u7C7B\u578B\u68C0\u67E5\u5668...").run();
153
- const result = [];
154
- for (var index = 0; index < apiSourceFiles.length; index++) {
155
- var apiSourceFile = apiSourceFiles[index];
156
- if (apiSourceFile == null)
157
- throw new Error("\u975E\u9884\u671F\u7684\u6570\u7EC4\u8D8A\u754C");
158
- await log.info(`\u5904\u7406\uFF08${index + 1} / ${apiSourceFiles.length}\uFF09\uFF1A${apiSourceFile.fileName}`).run();
159
- const apiCalcSourceFile = apiTypeCalcFiles[index]?.sourceFile;
160
- if (apiCalcSourceFile === void 0) {
161
- throw new Error("\u975E\u9884\u671F\u7684\u6570\u7EC4\u8D8A\u754C");
162
- }
163
- for (const node of apiCalcSourceFile.statements) {
164
- if (import_typescript.default.isExportAssignment(node) && node.isExportEquals === void 0) {
165
- const apiType = check.getTypeAtLocation(node.expression);
166
- const typeString = check.typeToString(
167
- apiType,
168
- void 0,
169
- import_typescript.default.TypeFormatFlags.NoTruncation | import_typescript.default.TypeFormatFlags.AllowUniqueESSymbolType | import_typescript.default.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope
170
- );
171
- result.push(typeString);
98
+ async function main(tsconfigPath, apiFolderPath, outputPath) {
99
+ var log = new Log("@lsby:net-core").extend("gen-type");
100
+ const tsconfigJson = import_typescript.default.parseConfigFileTextToJson(tsconfigPath, import_node_fs.default.readFileSync(tsconfigPath, "utf8"));
101
+ if (tsconfigJson.error) {
102
+ throw new Error("\u65E0\u6CD5\u89E3\u6790 tsconfig.json");
103
+ }
104
+ const parsedTsconfig = import_typescript.default.parseJsonConfigFileContent(tsconfigJson.config, import_typescript.default.sys, import_node_path.default.resolve(tsconfigPath, ".."));
105
+ await log.debug("\u6210\u529F\u89E3\u6790 tsconfig \u6587\u4EF6...");
106
+ const projectHost = import_typescript.default.createCompilerHost(parsedTsconfig.options);
107
+ const project = import_typescript.default.createProgram(parsedTsconfig.fileNames, parsedTsconfig.options, projectHost);
108
+ await log.debug("\u6210\u529F\u8BFB\u53D6\u9879\u76EE...");
109
+ const allSourceFiles = project.getSourceFiles();
110
+ const apiSourceFiles = allSourceFiles.filter((sourceFile) => {
111
+ return new RegExp(`${apiFolderPath.replaceAll("\\", "\\\\")}.*type.ts`).test(import_node_path.default.resolve(sourceFile.fileName));
112
+ });
113
+ await log.debug("\u627E\u5230 %o \u4E2A\u63A5\u53E3...", apiSourceFiles.length);
114
+ const apiTypeCalcFileNames = apiSourceFiles.map(
115
+ (sourceFile) => sourceFile.fileName.replace("type.ts", `type-calculate-${(0, import_node_crypto.randomUUID)()}.ts`)
116
+ );
117
+ const apiTypeCalcFiles = apiTypeCalcFileNames.map((filename) => {
118
+ return {
119
+ name: filename,
120
+ sourceFile: import_typescript.default.createSourceFile(filename, calcCode, import_typescript.default.ScriptTarget.Latest)
121
+ };
122
+ });
123
+ await log.debug("\u6210\u529F\u751F\u6210\u865A\u62DF\u8BA1\u7B97\u6587\u4EF6...");
124
+ const newProject = import_typescript.default.createProgram({
125
+ rootNames: [...parsedTsconfig.fileNames, ...apiTypeCalcFileNames],
126
+ options: parsedTsconfig.options,
127
+ host: {
128
+ ...projectHost,
129
+ getSourceFile: (filename) => {
130
+ const apiTypeCalcSourceFile = apiTypeCalcFiles.find(
131
+ (apiTypeCalcSourceFile2) => apiTypeCalcSourceFile2.name === filename
132
+ );
133
+ if (apiTypeCalcSourceFile !== void 0) {
134
+ return apiTypeCalcSourceFile.sourceFile;
172
135
  }
136
+ return project.getSourceFile(filename);
173
137
  }
138
+ },
139
+ oldProgram: project
140
+ });
141
+ await log.debug("\u6210\u529F\u751F\u6210\u865A\u62DF\u9879\u76EE...");
142
+ const check = newProject.getTypeChecker();
143
+ await log.debug("\u6210\u529F\u751F\u6210\u865A\u62DF\u9879\u76EE\u7C7B\u578B\u68C0\u67E5\u5668...");
144
+ const result = [];
145
+ for (var index = 0; index < apiSourceFiles.length; index++) {
146
+ var apiSourceFile = apiSourceFiles[index];
147
+ if (apiSourceFile == null)
148
+ throw new Error("\u975E\u9884\u671F\u7684\u6570\u7EC4\u8D8A\u754C");
149
+ await log.info(`\u5904\u7406\uFF08${index + 1} / ${apiSourceFiles.length}\uFF09\uFF1A${apiSourceFile.fileName}`);
150
+ const apiCalcSourceFile = apiTypeCalcFiles[index]?.sourceFile;
151
+ if (apiCalcSourceFile === void 0) {
152
+ throw new Error("\u975E\u9884\u671F\u7684\u6570\u7EC4\u8D8A\u754C");
174
153
  }
175
- await log.debug("\u6210\u529F\u5904\u7406\u6240\u6709\u63A5\u53E3...").run();
176
- const outputPathAbs = import_node_path.default.resolve(outputPath);
177
- var outDir = import_node_path.default.dirname(outputPathAbs);
178
- if (!(0, import_node_fs.existsSync)(outDir)) {
179
- (0, import_node_fs.mkdirSync)(outDir, { recursive: true });
154
+ for (const node of apiCalcSourceFile.statements) {
155
+ if (import_typescript.default.isExportAssignment(node) && node.isExportEquals === void 0) {
156
+ const apiType = check.getTypeAtLocation(node.expression);
157
+ const typeString = check.typeToString(
158
+ apiType,
159
+ void 0,
160
+ import_typescript.default.TypeFormatFlags.NoTruncation | import_typescript.default.TypeFormatFlags.AllowUniqueESSymbolType | import_typescript.default.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope
161
+ );
162
+ result.push(typeString);
163
+ }
180
164
  }
181
- import_node_fs.default.writeFileSync(outputPathAbs, `export type InterfaceType = [${result.join(",")}]
165
+ }
166
+ await log.debug("\u6210\u529F\u5904\u7406\u6240\u6709\u63A5\u53E3...");
167
+ const outputPathAbs = import_node_path.default.resolve(outputPath);
168
+ var outDir = import_node_path.default.dirname(outputPathAbs);
169
+ if (!(0, import_node_fs.existsSync)(outDir)) {
170
+ (0, import_node_fs.mkdirSync)(outDir, { recursive: true });
171
+ }
172
+ import_node_fs.default.writeFileSync(outputPathAbs, `export type InterfaceType = [${result.join(",")}]
182
173
  `);
183
- await log.debug("\u751F\u6210\u6210\u529F\uFF1A%o", outputPathAbs).run();
184
- }).run();
174
+ await log.debug("\u751F\u6210\u6210\u529F\uFF1A%o", outputPathAbs);
185
175
  }
186
176
  // Annotate the CommonJS export names for ESM import in node:
187
177
  0 && (module.exports = {