Skip to content

Commit bc61ba9

Browse files
feat: add list-targets cmd
1 parent 7e94ccc commit bc61ba9

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

src/commands/build.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import type { GlobalOptions } from '../lib/types.ts'
66
import { Config } from '../lib/config.ts'
77

88
const TargetError = (target: string, targets: string[]) => {
9-
return new ValidationError(`Invalid Target: ${target}
10-
Valid Targets: ${targets.join(', ')}
11-
`)
9+
return new ValidationError(`Invalid Target: ${target}. Run 'runreal list-targets' to see valid targets.`)
1210
}
11+
1312
export type BuildOptions = typeof build extends Command<void, void, infer Options, infer Argument, GlobalOptions>
1413
? Options
1514
: never

src/commands/list-targets.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { Command } from '@cliffy/command'
2+
import { createEngine } from '../lib/engine.ts'
3+
import type { GlobalOptions } from '../lib/types.ts'
4+
import { Config } from '../lib/config.ts'
5+
6+
export type ListTargetsOptions = typeof listTargets extends
7+
Command<void, void, infer Options, infer Argument, GlobalOptions> ? Options
8+
: never
9+
10+
const logTargets = (targets: string[]) => {
11+
return targets.map((target) => {
12+
console.log(target)
13+
})
14+
}
15+
16+
export const listTargets = new Command<GlobalOptions>()
17+
.description('list-targets')
18+
.option('-e, --engine-only', 'list only engine targets')
19+
.option('-p, --project-only', 'list only project targets', { conflicts: ['engine-only'] })
20+
.action(async (options) => {
21+
const { engineOnly, projectOnly } = options as ListTargetsOptions
22+
const config = Config.getInstance()
23+
const { engine: { path: enginePath }, project: { path: projectPath } } = config.mergeConfigCLIConfig({
24+
cliOptions: options,
25+
})
26+
27+
const engine = createEngine(enginePath)
28+
const engineTargets = await engine.parseEngineTargets()
29+
let projectTargets: string[] = []
30+
31+
if (projectPath) {
32+
projectTargets = (await engine.parseProjectTargets(projectPath)).filter((target) =>
33+
!engineTargets.includes(target)
34+
)
35+
}
36+
37+
if (engineOnly) {
38+
return logTargets(engineTargets)
39+
}
40+
41+
if (projectOnly) {
42+
return logTargets(projectTargets)
43+
}
44+
45+
const targets = Array.from(new Set([...engineTargets, ...projectTargets]))
46+
return logTargets(targets)
47+
})

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { script } from './commands/script.ts'
1515
import { runpython } from './commands/runpython.ts'
1616
import { uasset } from './commands/uasset/index.ts'
1717
import { auth } from './commands/auth.ts'
18+
import { listTargets } from './commands/list-targets.ts'
1819

1920
await cmd
2021
.name('runreal')
@@ -27,6 +28,7 @@ await cmd
2728
.command('debug', debug)
2829
.command('clean', clean)
2930
.command('build', build)
31+
.command('list-targets', listTargets)
3032
.command('engine', engine)
3133
.command('uat', uat)
3234
.command('ubt', ubt)

0 commit comments

Comments
 (0)