@dune2/cli 1.0.0 → 1.0.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.
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
- package/readme.md +49 -17
package/dist/cli.js
CHANGED
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json","../src/cli.ts"],"sourcesContent":["{\n \"name\": \"@dune2/cli\",\n \"version\": \"0.
|
|
1
|
+
{"version":3,"sources":["../package.json","../src/cli.ts"],"sourcesContent":["{\n \"name\": \"@dune2/cli\",\n \"version\": \"1.0.0\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/liaoyinglong/next-tools.git\",\n \"directory\": \"packages/cli\"\n },\n \"type\": \"module\",\n \"exports\": {\n \".\": {\n \"import\": \"./dist/index.js\"\n },\n \"./cli\": {\n \"import\": \"./dist/cli.js\"\n },\n \"./normalizeConfig\": {\n \"import\": \"./dist/normalizeConfig.js\"\n },\n \"./prettier\": {\n \"import\": \"./dist/prettier.js\",\n \"require\": \"./dist/prettier.cjs\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"types\": \"dist/index.d.ts\",\n \"bin\": {\n \"dune\": \"./dist/cli.js\"\n },\n \"files\": [\n \"dist\"\n ],\n \"scripts\": {\n \"build\": \"shx rm -rf ./dist && tsup --splitting\",\n \"dev\": \"pnpm run build --watch\",\n \"lint\": \"tsc --diagnostics --noEmit\",\n \"test\": \"vitest run\",\n \"test:u\": \"vitest -u\"\n },\n \"dependencies\": {\n \"@apidevtools/swagger-parser\": \"^10.1.0\",\n \"cac\": \"^6.7.14\",\n \"debug\": \"^4.3.4\",\n \"enquirer\": \"^2.3.6\",\n \"fs-extra\": \"^11.2.0\",\n \"jiti\": \"^2.4.2\",\n \"json-schema-to-typescript\": \"15.0.0\",\n \"lodash\": \"^4.17.21\",\n \"p-map\": \"^7.0.2\",\n \"path-to-regexp\": \"7.1.0\",\n \"picocolors\": \"^1.0.0\"\n },\n \"devDependencies\": {\n \"@types/debug\": \"^4.1.7\",\n \"@types/lodash\": \"^4.14.186\",\n \"gaxios\": \"*\",\n \"openapi-types\": \"^12.0.2\",\n \"prettier\": \"^3\",\n \"tsup\": \"8\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n }\n}\n","#!/usr/bin/env node\nimport { version } from \"../package.json\";\nimport { cli } from \"./shared\";\n\n//#region api 相关\ncli\n .command(\"generateApi\", \"生成 api 文件\")\n .example(\"dune generateApi\")\n .action(async () => {\n const { generateApi } = await import(\"./commands/generateApi\");\n await generateApi();\n });\n//#endregion\n\ncli\n .command(\"init\", \"初始化配置文件\")\n .example(\"dune init\")\n .action(async () => {\n const { initConfig } = await import(\"./commands/initConfig\");\n await initConfig();\n });\n\ncli\n .command(\"interactive\", \"交互式操作\")\n .example(\"dune interactive\")\n .alias(\"i\")\n .action(async (args) => {\n const { interactive } = await import(\"./commands/interactive\");\n await interactive(args);\n });\n\n// make default command run interactive\ncli.command(\"\").action(async (args) => {\n const { interactive } = await import(\"./commands/interactive\");\n await interactive(args);\n});\n\ncli.version(version);\ncli.help();\n\n(async () => {\n try {\n // Parse CLI args without running the command\n cli.parse(process.argv, { run: false });\n // Run the command yourself\n // You only need `await` when your command action returns a Promise\n await cli.runMatchedCommand();\n } catch (error) {\n // Handle error here..\n // e.g.\n // console.error(error.stack)\n // process.exit(1)\n }\n})();\n"],"mappings":";;;;;;AAEE,cAAW;;;ACGb,IACG,QAAQ,eAAe,+BAAW,EAClC,QAAQ,kBAAkB,EAC1B,OAAO,YAAY;AAClB,QAAM,EAAE,YAAY,IAAI,MAAM,OAAO,2BAAwB;AAC7D,QAAM,YAAY;AACpB,CAAC;AAGH,IACG,QAAQ,QAAQ,4CAAS,EACzB,QAAQ,WAAW,EACnB,OAAO,YAAY;AAClB,QAAM,EAAE,WAAW,IAAI,MAAM,OAAO,0BAAuB;AAC3D,QAAM,WAAW;AACnB,CAAC;AAEH,IACG,QAAQ,eAAe,gCAAO,EAC9B,QAAQ,kBAAkB,EAC1B,MAAM,GAAG,EACT,OAAO,OAAO,SAAS;AACtB,QAAM,EAAE,YAAY,IAAI,MAAM,OAAO,2BAAwB;AAC7D,QAAM,YAAY,IAAI;AACxB,CAAC;AAGH,IAAI,QAAQ,EAAE,EAAE,OAAO,OAAO,SAAS;AACrC,QAAM,EAAE,YAAY,IAAI,MAAM,OAAO,2BAAwB;AAC7D,QAAM,YAAY,IAAI;AACxB,CAAC;AAED,IAAI,QAAQ,OAAO;AACnB,IAAI,KAAK;AAAA,CAER,YAAY;AACX,MAAI;AAEF,QAAI,MAAM,QAAQ,MAAM,EAAE,KAAK,MAAM,CAAC;AAGtC,UAAM,IAAI,kBAAkB;AAAA,EAC9B,SAAS,OAAO;AAAA,EAKhB;AACF,GAAG;","names":[]}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,33 +1,65 @@
|
|
|
1
|
-
|
|
1
|
+
# CLI 工具
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
-
|
|
3
|
+
一个基于 CAC 的命令行工具,主要用于 API 代码生成和配置管理。
|
|
4
|
+
|
|
5
|
+
## 功能特性
|
|
6
|
+
|
|
7
|
+
- 从 Swagger/OpenAPI 规范生成 API 请求代码
|
|
8
|
+
- 自动生成 TypeScript 类型定义
|
|
9
|
+
- 支持配置文件初始化
|
|
10
|
+
- 交互式命令选择界面
|
|
11
|
+
|
|
12
|
+
## 安装与使用
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @dune2/cli
|
|
16
|
+
```
|
|
8
17
|
|
|
9
18
|
## 支持的命令
|
|
10
19
|
|
|
11
20
|
```shell
|
|
12
21
|
Commands:
|
|
13
|
-
|
|
14
|
-
extract 提取代码中的文案
|
|
15
|
-
upload 上传翻译文件
|
|
16
|
-
generateApi 生成api文件
|
|
22
|
+
generateApi 生成 API 文件
|
|
17
23
|
init 初始化配置文件
|
|
18
24
|
interactive 交互式操作
|
|
19
25
|
```
|
|
20
26
|
|
|
21
|
-
|
|
27
|
+
### 主要命令详解
|
|
28
|
+
|
|
29
|
+
#### `dune generateApi`
|
|
30
|
+
|
|
31
|
+
从 Swagger/OpenAPI 规范生成 API 请求代码,包括:
|
|
32
|
+
|
|
33
|
+
- 自动生成 TypeScript 类型定义
|
|
34
|
+
- 支持 URL 路径参数处理
|
|
35
|
+
- 生成请求构造器
|
|
36
|
+
- 支持响应类型推断
|
|
37
|
+
- 自动格式化生成的代码
|
|
38
|
+
|
|
39
|
+
#### `dune init`
|
|
40
|
+
|
|
41
|
+
初始化项目配置文件,创建 `dune.config.ts` 配置文件模板:
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { defineConfig } from "@dune2/cli";
|
|
45
|
+
|
|
46
|
+
export default defineConfig({
|
|
47
|
+
i18n: [],
|
|
48
|
+
api: [],
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
#### `dune interactive` 或 `dune i`
|
|
22
53
|
|
|
23
|
-
|
|
54
|
+
进入交互式命令选择界面,提供友好的命令选择体验。
|
|
24
55
|
|
|
25
|
-
|
|
56
|
+
## 交互式模式
|
|
26
57
|
|
|
27
|
-
|
|
58
|
+
运行 `dune` 或 `dune interactive` 进入交互式选择模式,使用上下键选择要执行的命令,回车键确认执行。
|
|
28
59
|
|
|
29
|
-
|
|
60
|
+
## 配置文件
|
|
30
61
|
|
|
31
|
-
|
|
62
|
+
工具会在项目根目录查找 `dune.config.ts` 配置文件,支持:
|
|
32
63
|
|
|
33
|
-
|
|
64
|
+
- API 配置:Swagger 文档路径、输出目录等
|
|
65
|
+
- 国际化配置:多语言支持相关配置
|