@ranger1/dx 0.1.109 → 0.1.111

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/lib/cli/dx-cli.js CHANGED
@@ -68,6 +68,7 @@ class DxCli {
68
68
  contracts: args => handleContracts(this, args),
69
69
  release: args => handleRelease(this, args),
70
70
  }
71
+ this.registerConfiguredCommandHandlers()
71
72
 
72
73
  this.flagDefinitions = FLAG_DEFINITIONS
73
74
  this.validateLoadedHelpConfig()
@@ -163,6 +164,65 @@ class DxCli {
163
164
  return this.commands[command]
164
165
  }
165
166
 
167
+ registerConfiguredCommandHandlers() {
168
+ for (const [commandName, config] of Object.entries(this.commands || {})) {
169
+ if (commandName === 'help') continue
170
+ if (this.commandHandlers[commandName]) continue
171
+ if (!this.isExecutableConfigTree(config)) continue
172
+
173
+ this.commandHandlers[commandName] = args => this.handleConfiguredCommand(commandName, args)
174
+ }
175
+ }
176
+
177
+ isExecutableConfigTree(node) {
178
+ if (!node || typeof node !== 'object' || Array.isArray(node)) return false
179
+ if (node.command || node.internal || node.concurrent || node.sequential) return true
180
+
181
+ return Object.entries(node).some(([key, value]) => {
182
+ if (key === 'help' || key === 'description' || key === 'args') return false
183
+ if (key === 'app' || key === 'ports' || key === 'dangerous') return false
184
+ return this.isExecutableConfigTree(value)
185
+ })
186
+ }
187
+
188
+ async handleConfiguredCommand(commandName, args = []) {
189
+ const environment = this.determineEnvironment()
190
+ const config = this.resolveConfiguredCommand(commandName, args, environment)
191
+
192
+ if (!config) {
193
+ const path = [commandName, ...args].join('.')
194
+ logger.error(`未找到命令配置: ${path}`)
195
+ process.exitCode = 1
196
+ return
197
+ }
198
+
199
+ if (config.concurrent && Array.isArray(config.commands)) {
200
+ await this.handleConcurrentCommands(config.commands, null, environment)
201
+ } else if (config.sequential && Array.isArray(config.commands)) {
202
+ await this.handleSequentialCommands(config.commands, environment)
203
+ } else {
204
+ await this.executeCommand(config)
205
+ }
206
+ }
207
+
208
+ resolveConfiguredCommand(commandName, args = [], environment) {
209
+ let config = this.commands?.[commandName]
210
+ if (!config) return null
211
+
212
+ for (const arg of args) {
213
+ if (!config || typeof config !== 'object' || Array.isArray(config)) return null
214
+ config = config[arg]
215
+ if (!config) return null
216
+ }
217
+
218
+ if (environment && config && typeof config === 'object' && !Array.isArray(config)) {
219
+ const envKey = this.normalizeEnvKey(environment)
220
+ if (config[envKey]) config = config[envKey]
221
+ }
222
+
223
+ return config
224
+ }
225
+
166
226
  // 检测并生成 Prisma Client
167
227
  async ensurePrismaClient() {
168
228
  // 仅对真正安装了 @prisma/client 的项目执行检查。
@@ -38,10 +38,10 @@ const TARGET_CONFIGS = {
38
38
 
39
39
  const ALLOWED_DEPLOY_MODES = ['prebuilt']
40
40
 
41
- const APP_ENV_MAP = {
42
- development: 'dev',
43
- staging: 'staging',
44
- production: 'prod'
41
+ const DX_ENV_FLAG_MAP = {
42
+ development: '--dev',
43
+ staging: '--staging',
44
+ production: '--prod'
45
45
  }
46
46
 
47
47
  const VERCEL_PROJECT_LINK_PATH = '.vercel/project.json'
@@ -351,8 +351,7 @@ export async function deployToVercel(target, options = {}) {
351
351
  // - 前置构建/生成(shared/contracts/backend 等)应由项目自己的 Nx 依赖图或 Vercel buildCommand 负责。
352
352
  // - 这样 dx deploy 能兼容不同 monorepo 布局(不强依赖 apps/sdk 等目录)。
353
353
 
354
- // 映射环境标识:development -> dev, staging -> staging, production -> prod
355
- const buildEnv = APP_ENV_MAP[environment]
354
+ const dxEnvFlag = DX_ENV_FLAG_MAP[environment]
356
355
 
357
356
  for (const t of targets) {
358
357
  const targetConfig = getTargetConfig(t)
@@ -425,7 +424,10 @@ export async function deployToVercel(target, options = {}) {
425
424
  const envVars = {
426
425
  ...process.env,
427
426
  VERCEL_PROJECT_ID: projectId,
428
- APP_ENV: buildEnv,
427
+ APP_ENV: environment,
428
+ NEXT_PUBLIC_APP_ENV: environment,
429
+ VITE_APP_ENV: environment,
430
+ DX_ENV_FLAG: dxEnvFlag,
429
431
  NODE_ENV: envManager.mapAppEnvToNodeEnv(environment),
430
432
  VERCEL_ORG_ID: orgId
431
433
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ranger1/dx",
3
- "version": "0.1.109",
3
+ "version": "0.1.111",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {