@ranger1/dx 0.1.97 → 0.1.98

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.md CHANGED
@@ -4,6 +4,38 @@
4
4
 
5
5
  本工具通过项目内的 `dx/config/*` 配置文件来驱动命令执行:你可以把它理解成「带环境变量分层 + 校验 + 命令编排能力的脚本系统」。
6
6
 
7
+ ## 当前规范
8
+
9
+ 当前版本的 `dx` 已收敛到 strict 配置规范。
10
+
11
+ 这意味着:
12
+
13
+ - 配置写错时直接报错,不再自动兼容旧写法
14
+ - `help` 输出由 `dx/config/commands.json` 动态生成,不再依赖代码中的大段硬编码文案
15
+ - 命令配置中的环境分支必须使用完整环境键
16
+
17
+ 当前推荐且受支持的环境键:
18
+
19
+ - `development`
20
+ - `staging`
21
+ - `production`
22
+ - `test`
23
+ - `e2e`
24
+
25
+ 当前推荐且受支持的 CLI 环境标志:
26
+
27
+ - `--dev`
28
+ - `--staging`
29
+ - `--prod`
30
+ - `--test`
31
+ - `--e2e`
32
+
33
+ 不再建议写法:
34
+
35
+ - `dev` / `prod` 作为配置节点名
36
+ - `--development` / `--production` / `--stage`
37
+ - 任何旧配置回退、旧命令别名或自动输入修正
38
+
7
39
  ## 安装
8
40
 
9
41
  必须全局安装,并始终使用最新版本:
@@ -70,12 +102,14 @@ DX_CONFIG_DIR=/path/to/your-repo/dx/config dx status
70
102
 
71
103
  ### 1) dx/config/commands.json
72
104
 
73
- 这是核心文件,定义了 dx 各命令要执行的 shell 命令,支持:
105
+ 这是核心文件,定义了 dx 各命令要执行的 shell 命令,也承载帮助信息配置。
106
+
107
+ 它支持:
74
108
 
75
109
  - 单命令:`{ "command": "..." }`
76
- - 并发:`{ "concurrent": true, "commands": ["build.front.dev", "build.admin.dev"] }`
77
- - 串行:`{ "sequential": true, "commands": ["build.backend.prod", "build.sdk"] }`
78
- - 环境分支:如 `build.backend.dev` / `build.backend.prod`(dx 会根据 `--dev/--prod/--staging/...` 选择)
110
+ - 并发:`{ "concurrent": true, "commands": ["build.front.development", "build.admin.development"] }`
111
+ - 串行:`{ "sequential": true, "commands": ["build.backend.production", "build.sdk"] }`
112
+ - 环境分支:如 `build.backend.development` / `build.backend.production`(dx 会根据 `--dev/--prod/--staging/...` 选择)
79
113
  - dotenv 包裹:配置里带 `"app": "backend"` 时,dx 会按 `env-layers.json` 拼出 dotenv 层并用 `pnpm exec dotenv ... -- <command>` 执行
80
114
 
81
115
  常见字段(单命令配置):
@@ -95,9 +129,39 @@ DX_CONFIG_DIR=/path/to/your-repo/dx/config dx status
95
129
  命令路径引用(并发/串行的 commands 数组)使用点号字符串,例如:
96
130
 
97
131
  ```json
98
- { "concurrent": true, "commands": ["build.shared", "build.front.dev"] }
132
+ { "concurrent": true, "commands": ["build.shared", "build.front.development"] }
133
+ ```
134
+
135
+ 帮助配置示例:
136
+
137
+ ```json
138
+ {
139
+ "help": {
140
+ "summary": "统一开发环境管理工具",
141
+ "globalOptions": [
142
+ { "flags": ["--dev"], "description": "使用 development 环境" },
143
+ { "flags": ["--prod"], "description": "使用 production 环境" }
144
+ ],
145
+ "commands": {
146
+ "start": {
147
+ "summary": "启动/桥接服务",
148
+ "notes": ["未指定 service 时默认使用开发套件,仅允许 --dev"],
149
+ "examples": [
150
+ { "command": "dx start backend --dev", "description": "启动后端开发服务" }
151
+ ]
152
+ }
153
+ }
154
+ }
155
+ }
99
156
  ```
100
157
 
158
+ 约束:
159
+
160
+ - 命令级帮助推荐放在 `help.commands.<command>`
161
+ - target 级帮助推荐放在 `help.targets.<command>.<target>`
162
+ - 帮助示例必须与真实命令树一致,不能写配置里不存在的 target
163
+ - 运行时会校验 help 配置结构;坏配置会直接报错
164
+
101
165
  ### 2) dx/config/env-layers.json
102
166
 
103
167
  用于定义不同环境下加载哪些 `.env.*` 文件(顺序 = 覆盖优先级)。格式:
@@ -202,6 +266,15 @@ dx test e2e backend apps/backend/e2e/auth
202
266
  dx test e2e quantify apps/quantify/e2e/health/health.e2e-spec.ts
203
267
  ```
204
268
 
269
+ 关于 `help`:
270
+
271
+ - `dx --help`
272
+ - `dx help <command>`
273
+
274
+ 现在都优先从 `commands.json` 的 `help` 区域动态生成。
275
+
276
+ 如果某个命令还没有补充足够的 `help` 元数据,输出会回退到配置结构推导出的最小帮助,而不是旧的手写兼容文案。
277
+
205
278
  命令约束摘要:
206
279
 
207
280
  - 对声明了 `requiresPath: true` 的 E2E target,`dx test e2e <target>` 必须提供文件或目录路径,禁止无路径或 `all` 全量执行
package/lib/cli/dx-cli.js CHANGED
@@ -164,8 +164,17 @@ class DxCli {
164
164
 
165
165
  // 检测并生成 Prisma Client
166
166
  async ensurePrismaClient() {
167
+ // 仅对真正安装了 @prisma/client 的项目执行检查。
168
+ // 依据「node_modules/@prisma/client/package.json 是否存在」判断项目是否使用 Prisma,
169
+ // 避免在纯文档站、纯前端等未引入 Prisma 的项目上误触发生成流程,
170
+ // 进而报出形如「未找到 db.generate 命令配置」的误导性错误。
171
+ const prismaClientDir = join(process.cwd(), 'node_modules', '@prisma', 'client')
172
+ if (!existsSync(join(prismaClientDir, 'package.json'))) {
173
+ return
174
+ }
175
+
167
176
  // pnpm 结构下检测 @prisma/client 生成的 default.js 文件
168
- const prismaClientPath = join(process.cwd(), 'node_modules', '@prisma', 'client', 'default.js')
177
+ const prismaClientPath = join(prismaClientDir, 'default.js')
169
178
 
170
179
  if (!existsSync(prismaClientPath)) {
171
180
  const environment = this.determineEnvironment()
@@ -83,6 +83,8 @@ export function renderGlobalHelp(model = {}) {
83
83
  pushSection(lines, '选项:', normalizeArray(model.globalOptions).map(option => formatOption(option)))
84
84
  pushSection(lines, '示例:', normalizeArray(model.examples).map(example => formatExample(example)))
85
85
 
86
+ lines.push('', `运行 ${invocation} help <命令> 查看子命令的详细用法和示例`)
87
+
86
88
  return lines.join('\n')
87
89
  }
88
90
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ranger1/dx",
3
- "version": "0.1.97",
3
+ "version": "0.1.98",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {