Skip to content

Commit ffc487f

Browse files
feat: config improvment (#47)
1 parent ed88e59 commit ffc487f

31 files changed

+275
-186
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
build
2-
scratch/
2+
scratch/
3+
# This file is generated by the runreal CLI during the test
4+
.runreal/dist/script.esm.js

src/cmd.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
import { Command, EnumType, ulid } from './deps.ts'
22

3-
import { config } from './lib/config.ts'
3+
import { Config } from './lib/config.ts'
44
import { logger, LogLevel } from './lib/logger.ts'
55

6+
const LogLevelType = new EnumType(LogLevel)
7+
68
export const cmd = new Command()
79
.globalOption('--session-id <sessionId:string>', 'Session Id', {
810
default: ulid() as string,
911
// action: ({ sessionId }) => logger.setSessionId(sessionId),
1012
})
11-
.globalType('log-level', new EnumType(LogLevel))
13+
.globalType('log-level', LogLevelType)
1214
.globalOption('--log-level <level:log-level>', 'Log level', {
13-
default: LogLevel.DEBUG,
15+
default: LogLevelType.values().at(LogLevelType.values().indexOf(LogLevel.DEBUG)),
1416
action: ({ logLevel }) => logger.setLogLevel(logLevel),
1517
})
16-
.globalOption('-c, --config-path <configPath:string>', 'Path to config file', {
17-
action: async ({ configPath }) => {
18-
if (configPath) { const cfg = await config.mergeConfig(configPath) }
19-
},
20-
})
18+
.globalOption('-c, --config-path <configPath:string>', 'Path to config file')
2119
.globalEnv('RUNREAL_ENGINE_PATH=<enginePath:string>', 'Overide path to engine folder', { prefix: 'RUNREAL_' })
2220
.globalOption('--engine-path <enginePath:string>', 'Path to engine folder')
2321
.globalEnv('RUNREAL_PROJECT_PATH=<projectPath:string>', 'Overide path to project folder', { prefix: 'RUNREAL_' })
@@ -26,3 +24,7 @@ export const cmd = new Command()
2624
.globalOption('--build-id <buildId:string>', 'Overide build ID')
2725
.globalEnv('RUNREAL_BUILD_PATH=<buildPath:string>', 'Overide path to build output folder', { prefix: 'RUNREAL_' })
2826
.globalOption('--build-path <buildPath:string>', 'Path to save build outputs')
27+
.globalAction(async (options) => {
28+
// We load the config here so that the singleton should be instantiated before any command is run
29+
await Config.create({ path: options.configPath })
30+
})

src/commands/build.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import { Command, EnumType, ValidationError } from '../deps.ts'
22

33
import { createEngine, Engine, EngineConfiguration, EnginePlatform, EngineTarget } from '../lib/engine.ts'
44
import { findProjectFile, getProjectName } from '../lib/utils.ts'
5-
import { config } from '../lib/config.ts'
6-
import { CliOptions, GlobalOptions } from '../lib/types.ts'
5+
import type { GlobalOptions } from '../lib/types.ts'
6+
import { Config } from '../lib/config.ts'
77

88
const TargetError = (target: string, targets: string[]) => {
99
return new ValidationError(`Invalid Target: ${target}
1010
Valid Targets: ${targets.join(', ')}
1111
`)
1212
}
13-
export type BuildOptions = typeof build extends Command<any, any, infer Options, any, any> ? Options
13+
export type BuildOptions = typeof build extends Command<void, void, infer Options, infer Argument, GlobalOptions>
14+
? Options
1415
: never
1516

1617
export const build = new Command<GlobalOptions>()
@@ -23,9 +24,12 @@ export const build = new Command<GlobalOptions>()
2324
})
2425
.option('-d, --dry-run', 'Dry run')
2526
.arguments('<target:string>')
26-
.action(async (options: unknown, target = EngineTarget.Editor) => {
27+
.action(async (options, target = EngineTarget.Editor) => {
2728
const { platform, configuration, dryRun } = options as BuildOptions
28-
const { engine: { path: enginePath }, project: { path: projectPath } } = config.get(options as CliOptions)
29+
const config = Config.getInstance()
30+
const { engine: { path: enginePath }, project: { path: projectPath } } = config.mergeConfigCLIConfig({
31+
cliOptions: options,
32+
})
2933

3034
const engine = createEngine(enginePath)
3135
const validTargets = await engine.parseEngineTargets()

src/commands/buildgraph/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { Command } from '../../deps.ts'
2-
import { GlobalOptions } from '../../lib/types.ts'
2+
import type { GlobalOptions } from '../../lib/types.ts'
33

44
import { run } from './run.ts'
55

66
export const buildgraph = new Command<GlobalOptions>()
77
.description('buildgraph')
8+
.action((function () {
9+
this.showHelp()
10+
}))
811
.command('run', run)

src/commands/buildgraph/run.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Command, path, readNdjson } from '../../deps.ts'
2-
import { config } from '../../lib/config.ts'
3-
import { CliOptions, GlobalOptions } from '../../lib/types.ts'
2+
import { Config } from '../../lib/config.ts'
3+
import type { GlobalOptions } from '../../lib/types.ts'
44
import { createEngine } from '../../lib/engine.ts'
55

6-
export type RunOptions = typeof run extends Command<any, any, infer Options, any, any> ? Options
6+
export type RunOptions = typeof run extends Command<void, void, infer Options, infer Argument, GlobalOptions> ? Options
77
: never
88

99
interface AutomationToolLogs {
@@ -30,12 +30,16 @@ export const run = new Command<GlobalOptions>()
3030
.arguments('<buildGraphScript:file> <buildGraphArgs...>')
3131
.stopEarly()
3232
.action(async (options, buildGraphScript: string, ...buildGraphArgs: Array<string>) => {
33-
const { engine: { path: enginePath } } = config.get(options as CliOptions)
33+
const config = Config.getInstance()
34+
const { engine: { path: enginePath } } = config.mergeConfigCLIConfig({ cliOptions: options })
3435
const engine = createEngine(enginePath)
3536
const { success, code } = await engine.runBuildGraph(buildGraphScript, buildGraphArgs)
3637
if (!success) {
3738
const logs = await getAutomationToolLogs(enginePath)
38-
logs.filter(({ level }) => level === 'Error').forEach(({ message }) => console.log(`[BUILDGRAPH RUN] ${message}`))
39+
40+
for (const message of logs.filter(({ level }) => level === 'Error')) {
41+
console.log(`[BUILDGRAPH RUN] ${message}`)
42+
}
3943
Deno.exit(code)
4044
}
4145
})

src/commands/clean.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Command } from '../deps.ts'
33

44
export const clean = new Command()
55
.option('--dry-run', 'Dry run', { default: false })
6+
.description('clean')
67
.action(async (options) => {
78
await Engine.runClean(options)
89
})

src/commands/debug/debug-config.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import { Command } from '../../deps.ts'
2-
import { config } from '../../lib/config.ts'
3-
import { CliOptions, GlobalOptions } from '../../lib/types.ts'
2+
import { Config } from '../../lib/config.ts'
3+
import type { GlobalOptions } from '../../lib/types.ts'
44

5-
export type DebugConfigOptions = typeof debugConfig extends Command<any, any, infer Options, any, any> ? Options
5+
export type DebugConfigOptions = typeof debugConfig extends
6+
Command<void, void, infer Options extends Record<string, unknown>, [], GlobalOptions> ? Options
67
: never
78

89
export const debugConfig = new Command<GlobalOptions>()
910
.option('-r, --render', 'Render the config with substitutions')
1011
.description('debug config')
1112
.action((options) => {
12-
const { render } = options as DebugConfigOptions & GlobalOptions
13-
const cfg = config.get(options as CliOptions)
13+
const { render } = options
14+
const config = Config.getInstance()
15+
const cfg = config.mergeConfigCLIConfig({ cliOptions: options })
1416

1517
if (render) {
1618
const rendered = config.renderConfig(cfg)

src/commands/debug/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { Command } from '../../deps.ts'
2-
import { GlobalOptions } from '../../lib/types.ts'
2+
import type { GlobalOptions } from '../../lib/types.ts'
33

44
import { debugConfig } from './debug-config.ts'
55

66
export const debug = new Command<GlobalOptions>()
77
.description('debug')
8+
.action((function () {
9+
this.showHelp()
10+
}))
811
.command('config', debugConfig)

src/commands/engine/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { Command } from '../../deps.ts'
22

3-
import { GlobalOptions } from '../../lib/types.ts'
3+
import type { GlobalOptions } from '../../lib/types.ts'
44
import { install } from './install.ts'
55
import { update } from './update.ts'
66
import { setup } from './setup.ts'
77
import { version } from './version.ts'
88

99
export const engine = new Command<GlobalOptions>()
1010
.description('engine')
11+
.action(function () {
12+
this.showHelp()
13+
})
1114
.command('install', install)
1215
.command('update', update)
1316
.command('setup', setup)

src/commands/engine/install.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { Command, ValidationError } from '../../deps.ts'
22
import { cloneRepo, runEngineSetup } from '../../lib/utils.ts'
3-
import { CliOptions } from '../../lib/types.ts'
4-
import { config } from '../../lib/config.ts'
3+
import type { GlobalOptions } from '../../lib/types.ts'
4+
import { Config } from '../../lib/config.ts'
55

6-
export type InstallOptions = typeof install extends Command<any, any, infer Options, any, any> ? Options
6+
export type InstallOptions = typeof install extends Command<void, void, infer Options, infer Argument, GlobalOptions>
7+
? Options
78
: never
89

9-
export const install = new Command()
10+
export const install = new Command<GlobalOptions>()
1011
.description('install engine from a source repository')
1112
.option('-b, --branch <branch:string>', 'git checkout (branch | tag)')
1213
.option('-f, --force', 'force overwrite of destination', { default: false })
@@ -39,7 +40,8 @@ export const install = new Command()
3940
dryRun,
4041
setup,
4142
} = options as InstallOptions
42-
const cfg = config.get(options as CliOptions)
43+
44+
const cfg = Config.getInstance().mergeConfigCLIConfig({ cliOptions: options })
4345
source = source || cfg.engine.gitSource
4446
destination = destination || cfg.engine.path
4547

0 commit comments

Comments
 (0)