@ranger1/dx 0.1.110 → 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 +60 -0
- package/package.json +1 -1
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 的项目执行检查。
|