gen-api-types 1.0.8 → 1.0.10

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.
package/README.en.md CHANGED
@@ -51,6 +51,10 @@ As shown in the code above:
51
51
  1. `typeName: string` Interface return type name. If not specified, the default name will be: `Response_${ClassName}_${MethodName}`
52
52
  2. `args: any[]` Method parameter list. The tool will pass this list when calling the request method.
53
53
 
54
+ > Note:
55
+
56
+ If TypeScript reports the decorator error: "The runtime will invoke the decorator with 2 arguments, but the decorator expects 3", set `compilerOptions.experimentalDecorators` to `true` in tsconfig.
57
+
54
58
  ##### 2. Execute command
55
59
 
56
60
  ```shell
package/README.md CHANGED
@@ -52,6 +52,10 @@ export class TestApi {
52
52
  1. `typeName: string` 接口返回类型名称,若不指定该字段,默认生成名称为: `Response_${类名}_${方法名}`
53
53
  2. `args:any[] ` 方法参数列表,工具调用请求方法时,会将参数列表传入
54
54
 
55
+ > 注意:
56
+
57
+ 若使用装饰器时ts报错: "运行时将使用 2 个自变量调用修饰器,但修饰器需要 3 个",请将tsconfig中`compilerOptions.experimentalDecorators`设置为`true`
58
+
55
59
  ##### 2. 执行命令
56
60
 
57
61
  ```shell
package/bin/index.js CHANGED
@@ -1,8 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { spawn } = require('child_process');
4
- const path = require('path');
3
+ import { spawn } from 'node:child_process';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { createRequire } from 'node:module';
5
7
 
8
+ const require = createRequire(import.meta.url);
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
6
10
  const args = process.argv.slice(2);
7
11
  const cliPath = path.resolve(__dirname, '../src/cli/index.ts');
8
12
  const tsxCliPath = require.resolve('tsx/cli');
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "gen-api-types",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "一个自动生成请求接口返回类型的 cli 小工具",
5
5
  "main": "./src/index.ts",
6
+ "exports": {
7
+ ".": "./src/index.ts"
8
+ },
9
+ "type": "module",
6
10
  "bin": {
7
11
  "gen-api-types": "bin/index.js",
8
12
  "gat": "bin/index.js"
package/src/argv/index.ts CHANGED
@@ -50,7 +50,7 @@ export const { positionals, values: { project_root, output_file, output_dir, ts_
50
50
 
51
51
  if (help) {
52
52
  console.log(`
53
- Usage: tsx cli.js [options] [positionals]
53
+ gen-api-types [options] [positionals
54
54
 
55
55
  Options:
56
56
  -h, --help 输出帮助信息
@@ -1,3 +1,5 @@
1
1
  export const GEN_TYPE_METADATA_KEY = Symbol('gen:type:metadata');
2
+ /** 标记方法的装饰器名称 */
2
3
  export const M_DECO_NAME = 'gen_type_m';
4
+ /** 标记类的装饰器名称 */
3
5
  export const C_DECO_NAME = 'gen_type_c';
@@ -25,7 +25,6 @@ export function gen_type_m({ args = [], typeName }: GenTypeOptions = {}) {
25
25
 
26
26
  /**
27
27
  * 标记类
28
- * @returns
29
28
  */
30
29
  export function gen_type_c() {
31
30
  return function <T>(target: T) {
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export { C_DECO_NAME, M_DECO_NAME } from './constant';
1
2
  export * from './decotators';
2
3
 
package/tsconfig.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "exclude": [],
3
- "include": ["src", "test"],
3
+ "include": ["src", "test"], //把这些源码/声明文件加入项目
4
4
  "compilerOptions": {
5
5
  /* Visit https://aka.ms/tsconfig to read more about this file */
6
- "types": ["node"],
6
+ "types": ["node"], //它主要用来控制自动引入哪些 @types 包 或类型包
7
7
  /* Projects */
8
8
  // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
9
9
  // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */