Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config update #44

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
build
scratch/
scratch/
# This file is generated by the runreal CLI during the test
.runreal/dist/script.esm.js
18 changes: 10 additions & 8 deletions src/cmd.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import { Command, EnumType, ulid } from './deps.ts'

import { config } from './lib/config.ts'
import { Config } from './lib/config.ts'
import { logger, LogLevel } from './lib/logger.ts'

const LogLevelType = new EnumType(LogLevel)

export const cmd = new Command()
.globalOption('--session-id <sessionId:string>', 'Session Id', {
default: ulid() as string,
// action: ({ sessionId }) => logger.setSessionId(sessionId),
})
.globalType('log-level', new EnumType(LogLevel))
.globalType('log-level', LogLevelType)
.globalOption('--log-level <level:log-level>', 'Log level', {
default: LogLevel.DEBUG,
default: LogLevelType.values().at(LogLevelType.values().indexOf(LogLevel.DEBUG)),
action: ({ logLevel }) => logger.setLogLevel(logLevel),
})
.globalOption('-c, --config-path <configPath:string>', 'Path to config file', {
action: async ({ configPath }) => {
if (configPath) { const cfg = await config.mergeConfig(configPath) }
},
})
.globalOption('-c, --config-path <configPath:string>', 'Path to config file')
.globalEnv('RUNREAL_ENGINE_PATH=<enginePath:string>', 'Overide path to engine folder', { prefix: 'RUNREAL_' })
.globalOption('--engine-path <enginePath:string>', 'Path to engine folder')
.globalEnv('RUNREAL_PROJECT_PATH=<projectPath:string>', 'Overide path to project folder', { prefix: 'RUNREAL_' })
Expand All @@ -26,3 +24,7 @@ export const cmd = new Command()
.globalOption('--build-id <buildId:string>', 'Overide build ID')
.globalEnv('RUNREAL_BUILD_PATH=<buildPath:string>', 'Overide path to build output folder', { prefix: 'RUNREAL_' })
.globalOption('--build-path <buildPath:string>', 'Path to save build outputs')
.globalAction(async (options) => {
// We load the config here so that the singleton should be instantiated before any command is run
await Config.create({ path: options.configPath })
})
14 changes: 9 additions & 5 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import { Command, EnumType, ValidationError } from '../deps.ts'

import { createEngine, Engine, EngineConfiguration, EnginePlatform, EngineTarget } from '../lib/engine.ts'
import { findProjectFile, getProjectName } from '../lib/utils.ts'
import { config } from '../lib/config.ts'
import { CliOptions, GlobalOptions } from '../lib/types.ts'
import type { GlobalOptions } from '../lib/types.ts'
import { Config } from '../lib/config.ts'

const TargetError = (target: string, targets: string[]) => {
return new ValidationError(`Invalid Target: ${target}
Valid Targets: ${targets.join(', ')}
`)
}
export type BuildOptions = typeof build extends Command<any, any, infer Options, any, any> ? Options
export type BuildOptions = typeof build extends Command<void, void, infer Options, infer Argument, GlobalOptions>
? Options
: never

export const build = new Command<GlobalOptions>()
Expand All @@ -23,9 +24,12 @@ export const build = new Command<GlobalOptions>()
})
.option('-d, --dry-run', 'Dry run')
.arguments('<target:string>')
.action(async (options: unknown, target = EngineTarget.Editor) => {
.action(async (options, target = EngineTarget.Editor) => {
const { platform, configuration, dryRun } = options as BuildOptions
const { engine: { path: enginePath }, project: { path: projectPath } } = config.get(options as CliOptions)
const config = Config.getInstance()
const { engine: { path: enginePath }, project: { path: projectPath } } = config.mergeConfigCLIConfig({
cliOptions: options,
})

const engine = createEngine(enginePath)
const validTargets = await engine.parseEngineTargets()
Expand Down
5 changes: 4 additions & 1 deletion src/commands/buildgraph/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Command } from '../../deps.ts'
import { GlobalOptions } from '../../lib/types.ts'
import type { GlobalOptions } from '../../lib/types.ts'

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

export const buildgraph = new Command<GlobalOptions>()
.description('buildgraph')
.action((function () {
this.showHelp()
}))
.command('run', run)
14 changes: 9 additions & 5 deletions src/commands/buildgraph/run.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Command, path, readNdjson } from '../../deps.ts'
import { config } from '../../lib/config.ts'
import { CliOptions, GlobalOptions } from '../../lib/types.ts'
import { Config } from '../../lib/config.ts'
import type { GlobalOptions } from '../../lib/types.ts'
import { createEngine } from '../../lib/engine.ts'

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

interface AutomationToolLogs {
Expand All @@ -30,12 +30,16 @@ export const run = new Command<GlobalOptions>()
.arguments('<buildGraphScript:file> <buildGraphArgs...>')
.stopEarly()
.action(async (options, buildGraphScript: string, ...buildGraphArgs: Array<string>) => {
const { engine: { path: enginePath } } = config.get(options as CliOptions)
const config = Config.getInstance()
const { engine: { path: enginePath } } = config.mergeConfigCLIConfig({ cliOptions: options })
const engine = createEngine(enginePath)
const { success, code } = await engine.runBuildGraph(buildGraphScript, buildGraphArgs)
if (!success) {
const logs = await getAutomationToolLogs(enginePath)
logs.filter(({ level }) => level === 'Error').forEach(({ message }) => console.log(`[BUILDGRAPH RUN] ${message}`))

for (const message of logs.filter(({ level }) => level === 'Error')) {
console.log(`[BUILDGRAPH RUN] ${message}`)
}
Deno.exit(code)
}
})
1 change: 1 addition & 0 deletions src/commands/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Command } from '../deps.ts'

export const clean = new Command()
.option('--dry-run', 'Dry run', { default: false })
.description('clean')
.action(async (options) => {
await Engine.runClean(options)
})
12 changes: 7 additions & 5 deletions src/commands/debug/debug-config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { Command } from '../../deps.ts'
import { config } from '../../lib/config.ts'
import { CliOptions, GlobalOptions } from '../../lib/types.ts'
import { Config } from '../../lib/config.ts'
import type { GlobalOptions } from '../../lib/types.ts'

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

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

if (render) {
const rendered = config.renderConfig(cfg)
Expand Down
5 changes: 4 additions & 1 deletion src/commands/debug/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Command } from '../../deps.ts'
import { GlobalOptions } from '../../lib/types.ts'
import type { GlobalOptions } from '../../lib/types.ts'

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

export const debug = new Command<GlobalOptions>()
.description('debug')
.action((function () {
this.showHelp()
}))
.command('config', debugConfig)
5 changes: 4 additions & 1 deletion src/commands/engine/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { Command } from '../../deps.ts'

import { GlobalOptions } from '../../lib/types.ts'
import type { GlobalOptions } from '../../lib/types.ts'
import { install } from './install.ts'
import { update } from './update.ts'
import { setup } from './setup.ts'
import { version } from './version.ts'

export const engine = new Command<GlobalOptions>()
.description('engine')
.action((function () {
this.showHelp()
}))
.command('install', install)
.command('update', update)
.command('setup', setup)
Expand Down
12 changes: 7 additions & 5 deletions src/commands/engine/install.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Command, ValidationError } from '../../deps.ts'
import { cloneRepo, runEngineSetup } from '../../lib/utils.ts'
import { CliOptions } from '../../lib/types.ts'
import { config } from '../../lib/config.ts'
import type { GlobalOptions } from '../../lib/types.ts'
import { Config } from '../../lib/config.ts'

export type InstallOptions = typeof install extends Command<any, any, infer Options, any, any> ? Options
export type InstallOptions = typeof install extends Command<void, void, infer Options, infer Argument, GlobalOptions>
? Options
: never

export const install = new Command()
export const install = new Command<GlobalOptions>()
.description('install engine from a source repository')
.option('-b, --branch <branch:string>', 'git checkout (branch | tag)')
.option('-f, --force', 'force overwrite of destination', { default: false })
Expand Down Expand Up @@ -39,7 +40,8 @@ export const install = new Command()
dryRun,
setup,
} = options as InstallOptions
const cfg = config.get(options as CliOptions)

const cfg = Config.getInstance().mergeConfigCLIConfig({ cliOptions: options })
source = source || cfg.engine.gitSource
destination = destination || cfg.engine.path

Expand Down
10 changes: 6 additions & 4 deletions src/commands/engine/setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Command } from '../../deps.ts'
import { config } from '../../lib/config.ts'
import { CliOptions, GlobalOptions } from '../../lib/types.ts'
import { Config } from '../../lib/config.ts'
import type { GlobalOptions } from '../../lib/types.ts'
import { runEngineSetup } from '../../lib/utils.ts'

export type SetupOptions = typeof setup extends Command<any, any, infer Options, any, any> ? Options
export type SetupOptions = typeof setup extends Command<void, void, infer Options, [], GlobalOptions> ? Options
: never

export const setup = new Command<GlobalOptions>()
Expand All @@ -16,7 +16,9 @@ export const setup = new Command<GlobalOptions>()
)
.action(async (options, ...args) => {
const { gitdepends, gitdependscache } = options as SetupOptions
const { engine: { path: enginePath } } = config.get(options as CliOptions)
const { engine: { path: enginePath } } = Config.getInstance().mergeConfigCLIConfig({
cliOptions: options,
})
if (gitdepends) {
await runEngineSetup({ enginePath, gitDependsCache: gitdependscache })
}
Expand Down
9 changes: 5 additions & 4 deletions src/commands/engine/update.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Command, ValidationError } from '../../deps.ts'
import { deleteEngineHooks, exec, isGitRepo, runEngineSetup } from '../../lib/utils.ts'
import { config } from '../../lib/config.ts'
import { CliOptions, GlobalOptions } from '../../lib/types.ts'
import { Config } from '../../lib/config.ts'
import type { GlobalOptions } from '../../lib/types.ts'

export type UpdateOptions = typeof update extends Command<any, any, infer Options, any, any> ? Options
export type UpdateOptions = typeof update extends Command<void, void, infer Options, [], GlobalOptions> ? Options
: never

export const update = new Command<GlobalOptions>()
Expand Down Expand Up @@ -39,7 +39,8 @@ export const update = new Command<GlobalOptions>()
gitCleanFlags,
dryRun,
} = options as UpdateOptions
const cfg = config.get(options as CliOptions)

const cfg = Config.getInstance().mergeConfigCLIConfig({ cliOptions: options })
const isRepo = await isGitRepo(cfg.engine.path)
if (!isRepo) {
throw new ValidationError(
Expand Down
16 changes: 8 additions & 8 deletions src/commands/engine/version.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { Command } from '../../deps.ts'
import { config } from '../../lib/config.ts'
import { CliOptions, GlobalOptions } from '../../lib/types.ts'
import { Config } from '../../lib/config.ts'
import type { GlobalOptions } from '../../lib/types.ts'
import { createEngine } from '../../lib/engine.ts'
import { logger } from '../../lib/logger.ts'

export type VersionOptions = typeof version extends Command<any, any, infer Options, any, any> ? Options
export type VersionOptions = typeof version extends Command<void, void, infer Options, [], GlobalOptions> ? Options
: never

export const version = new Command<GlobalOptions>()
.description('print the engine version')
.action(
async (options, ..._args) => {
(options, ..._args) => {
logger.setContext(version.getName())
const cfg = config.get(options as CliOptions)
console.log(cfg)
const engine = await createEngine(cfg.engine.path)
const engineVersion = await engine.getEngineVersion('full')
const config = Config.getInstance()
const cfg = config.mergeConfigCLIConfig({ cliOptions: options })
const engine = createEngine(cfg.engine.path)
const engineVersion = engine.getEngineVersion('full')
logger.info(engineVersion)
},
)
4 changes: 2 additions & 2 deletions src/commands/gen.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Command } from '../deps.ts'
import { createEngine, Engine } from '../lib/engine.ts'
import { createEngine } from '../lib/engine.ts'
import { exec, findProjectFile } from '../lib/utils.ts'

export type GenOptions = typeof gen extends Command<void, void, infer Options extends Record<string, unknown>, [], void>
Expand All @@ -22,7 +22,7 @@ export const gen = new Command()
...args: string[]
) => {
const projectFile = await findProjectFile(projectPath)
const engine = await createEngine(enginePath)
const engine = createEngine(enginePath)

if (dryRun) {
console.log(`[gen] enginePath: ${enginePath}`)
Expand Down
8 changes: 4 additions & 4 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Command, ValidationError } from '../deps.ts'
import { createEngine } from '../lib/engine.ts'
import { GlobalOptions } from '../lib/types.ts'
import type { GlobalOptions } from '../lib/types.ts'
import { findProjectFile, getProjectName, writeConfigFile } from '../lib/utils.ts'

export type InitOptions = typeof init extends Command<any, any, infer Options, any, any> ? Options
export type InitOptions = typeof init extends Command<void, void, infer Options, [], GlobalOptions> ? Options
: never

export const init = new Command<GlobalOptions>()
Expand All @@ -17,8 +17,8 @@ export const init = new Command<GlobalOptions>()
}
const projectFile = await findProjectFile(projectPath)
const projectName = await getProjectName(projectPath)
const engine = await createEngine(enginePath)
const engineVersion = await engine.getEngineVersion()
const engine = createEngine(enginePath)
const engineVersion = engine.getEngineVersion()
console.log(`[init] enginePath: ${enginePath}`)
console.log(`[init] engineVersion: ${engineVersion}`)
console.log(`[init] projectPath: ${projectPath}`)
Expand Down
21 changes: 12 additions & 9 deletions src/commands/pkg.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Command, EnumType, ValidationError } from '../deps.ts'
import { createEngine, Engine, EngineConfiguration, EnginePlatform, EngineTarget } from '../lib/engine.ts'
import { findProjectFile } from '../lib/utils.ts'
import { config } from '../lib/config.ts'
import { CliOptions, GlobalOptions } from '../lib/types.ts'
import { Config } from '../lib/config.ts'
import type { CliOptions, GlobalOptions } from '../lib/types.ts'

const defaultBCRArgs = [
'-build',
Expand Down Expand Up @@ -41,7 +41,7 @@ const profiles = {
'server': serverBCRArgs,
}

export type PkgOptions = typeof pkg extends Command<any, any, infer Options, any, any> ? Options
export type PkgOptions = typeof pkg extends Command<void, void, infer Options, [], GlobalOptions> ? Options
: never

export const pkg = new Command<GlobalOptions>()
Expand All @@ -58,13 +58,16 @@ export const pkg = new Command<GlobalOptions>()
.option('--profile <profile:string>', 'Build profile', { default: 'client', required: true })
.action(async (options) => {
const { platform, configuration, dryRun, profile, archiveDirectory, zip } = options as PkgOptions
const { engine: { path: enginePath }, project: { path: projectPath } } = config.get(options as CliOptions)
const cfg = await Config.getInstance()
const { engine: { path: enginePath }, project: { path: projectPath } } = cfg.mergeConfigCLIConfig({
cliOptions: options,
})

const literal = pkg.getLiteralArgs().map((arg) => arg.toLowerCase())
const profileArgs = profiles[profile as keyof typeof profiles] || []
const bcrArgs = Array.from(new Set([...profileArgs, ...literal]))

const engine = await createEngine(enginePath)
const engine = createEngine(enginePath)
const projectFile = await findProjectFile(projectPath).catch(() => null)
if (projectFile) {
bcrArgs.push(`-project=${projectFile}`)
Expand All @@ -79,13 +82,13 @@ export const pkg = new Command<GlobalOptions>()
bcrArgs.push(`-clientconfig=${configuration}`)
}
if (archiveDirectory) {
bcrArgs.push(`-archive`)
bcrArgs.push('-archive')
bcrArgs.push(`-archiveDirectory=${archiveDirectory}`)
bcrArgs.push(`-archivemetadata`)
bcrArgs.push('-archivemetadata')
}
if (dryRun) {
console.log(`[package] package ${profile} ${configuration} ${platform}`)
console.log(`[package] BCR args:`)
console.log('[package] BCR args:')
console.log(bcrArgs)
return
}
Expand All @@ -101,7 +104,7 @@ export const pkg = new Command<GlobalOptions>()
const zipArgs = [
`-add=${expectedArchivePath}`,
`-archive=${expectedArchivePath}.zip`,
`-compression=5`,
'-compression=5',
]
await engine.runUAT(['ZipUtils', ...zipArgs])
}
Expand Down
Loading