From 59b125c09a24c983be0cd40a0f5cec5ed69c49c6 Mon Sep 17 00:00:00 2001 From: Thibault Le Ouay Date: Sun, 17 Nov 2024 16:59:34 +0400 Subject: [PATCH] chore linting --- deno.lock | 37 +++++++++++++++++++++++++++++- src/commands/build.ts | 8 +++---- src/commands/buildgraph/index.ts | 2 +- src/commands/buildgraph/run.ts | 6 ++--- src/commands/clean.ts | 1 + src/commands/debug/debug-config.ts | 10 ++++---- src/commands/debug/index.ts | 2 +- src/commands/engine/index.ts | 2 +- src/commands/engine/install.ts | 29 +++++++++++------------ src/commands/engine/setup.ts | 6 ++--- src/commands/engine/update.ts | 9 +++----- src/commands/engine/version.ts | 6 ++--- src/commands/gen.ts | 4 ---- src/commands/init.ts | 6 ++--- src/commands/pkg.ts | 15 +++++------- src/commands/uat.ts | 5 +--- src/commands/ubt.ts | 8 +++---- src/commands/workflow/exec.ts | 7 ++---- src/commands/workflow/index.ts | 2 +- src/lib/config.ts | 21 +++++++++-------- src/lib/engine.ts | 10 ++++---- src/lib/logger.ts | 10 ++++---- src/lib/schema.ts | 2 +- src/lib/source.ts | 7 +++--- src/lib/template.ts | 8 ++++--- src/lib/types.ts | 16 ++++--------- src/lib/utils.ts | 19 ++++++--------- tests/config.test.ts | 2 +- 28 files changed, 129 insertions(+), 131 deletions(-) diff --git a/deno.lock b/deno.lock index 0c5026c..a6d6eeb 100644 --- a/deno.lock +++ b/deno.lock @@ -6,13 +6,19 @@ "jsr:@cliffy/internal@1.0.0-rc.7": "1.0.0-rc.7", "jsr:@cliffy/table@1.0.0-rc.7": "1.0.0-rc.7", "jsr:@rebeccastevens/deepmerge@*": "7.1.3", + "jsr:@std/assert@^1.0.6": "1.0.6", + "jsr:@std/async@^1.0.5": "1.0.7", "jsr:@std/bytes@^1.0.3": "1.0.3", + "jsr:@std/data-structures@^1.0.4": "1.0.4", "jsr:@std/dotenv@*": "0.225.2", "jsr:@std/fmt@*": "1.0.3", "jsr:@std/fmt@~1.0.2": "1.0.3", + "jsr:@std/internal@^1.0.4": "1.0.4", + "jsr:@std/json@1": "1.0.1", "jsr:@std/jsonc@*": "1.0.1", "jsr:@std/path@*": "1.0.8", "jsr:@std/streams@*": "1.0.8", + "jsr:@std/testing@^1.0.3": "1.0.3", "jsr:@std/text@~1.0.7": "1.0.8", "npm:zod-to-json-schema@*": "3.23.5_zod@3.23.8" }, @@ -45,17 +51,38 @@ "@rebeccastevens/deepmerge@7.1.3": { "integrity": "d9fb8c19fdfba403ffad8cca6a59ec2b399541e33694f2d9d9570179b0b5c155" }, + "@std/assert@1.0.6": { + "integrity": "1904c05806a25d94fe791d6d883b685c9e2dcd60e4f9fc30f4fc5cf010c72207", + "dependencies": [ + "jsr:@std/internal" + ] + }, + "@std/async@1.0.7": { + "integrity": "f4fadc0124432e37cba11e8b3880164661a664de00a65118d976848f32f96290" + }, "@std/bytes@1.0.3": { "integrity": "e5d5b9e685966314e4edb4be60dfc4bd7624a075bfd4ec8109252b4320f76452" }, + "@std/data-structures@1.0.4": { + "integrity": "fa0e20c11eb9ba673417450915c750a0001405a784e2a4e0c3725031681684a0" + }, "@std/dotenv@0.225.2": { "integrity": "e2025dce4de6c7bca21dece8baddd4262b09d5187217e231b033e088e0c4dd23" }, "@std/fmt@1.0.3": { "integrity": "97765c16aa32245ff4e2204ecf7d8562496a3cb8592340a80e7e554e0bb9149f" }, + "@std/internal@1.0.4": { + "integrity": "62e8e4911527e5e4f307741a795c0b0a9e6958d0b3790716ae71ce085f755422" + }, + "@std/json@1.0.1": { + "integrity": "1f0f70737e8827f9acca086282e903677bc1bb0c8ffcd1f21bca60039563049f" + }, "@std/jsonc@1.0.1": { - "integrity": "6b36956e2a7cbb08ca5ad7fbec72e661e6217c202f348496ea88747636710dda" + "integrity": "6b36956e2a7cbb08ca5ad7fbec72e661e6217c202f348496ea88747636710dda", + "dependencies": [ + "jsr:@std/json" + ] }, "@std/path@1.0.8": { "integrity": "548fa456bb6a04d3c1a1e7477986b6cffbce95102d0bb447c67c4ee70e0364be" @@ -66,6 +93,14 @@ "jsr:@std/bytes" ] }, + "@std/testing@1.0.3": { + "integrity": "f98c2bee53860a5916727d7e7d3abe920dd6f9edace022e2d059f00d05c2cf42", + "dependencies": [ + "jsr:@std/assert", + "jsr:@std/async", + "jsr:@std/data-structures" + ] + }, "@std/text@1.0.8": { "integrity": "40ba34caa095f393e78796e5eda37b8b4e2cc6cfd6f51f34658ad7487b1451e4" } diff --git a/src/commands/build.ts b/src/commands/build.ts index 3211799..22910c2 100644 --- a/src/commands/build.ts +++ b/src/commands/build.ts @@ -3,15 +3,13 @@ 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 { CliOptions, GlobalOptions } from '../lib/types.ts' const TargetError = (target: string, targets: string[]) => { return new ValidationError(`Invalid Target: ${target} Valid Targets: ${targets.join(', ')} `) } -export type BuildOptions = typeof build extends Command ? Options - : never export const build = new Command() .description('build') @@ -23,8 +21,8 @@ export const build = new Command() }) .option('-d, --dry-run', 'Dry run') .arguments('') - .action(async (options: unknown, target = EngineTarget.Editor) => { - const { platform, configuration, dryRun } = options as BuildOptions + .action(async (options, target = EngineTarget.Editor) => { + const { platform, configuration, dryRun } = options const { engine: { path: enginePath }, project: { path: projectPath } } = config.get(options as CliOptions) const engine = createEngine(enginePath) diff --git a/src/commands/buildgraph/index.ts b/src/commands/buildgraph/index.ts index 67571c5..9149694 100644 --- a/src/commands/buildgraph/index.ts +++ b/src/commands/buildgraph/index.ts @@ -1,5 +1,5 @@ import { Command } from '../../deps.ts' -import { GlobalOptions } from '../../lib/types.ts' +import type { GlobalOptions } from '../../lib/types.ts' import { run } from './run.ts' diff --git a/src/commands/buildgraph/run.ts b/src/commands/buildgraph/run.ts index 26153ad..bb6c6d0 100644 --- a/src/commands/buildgraph/run.ts +++ b/src/commands/buildgraph/run.ts @@ -1,10 +1,8 @@ +import { cmd } from '../../cmd.ts' import { Command, path, readNdjson } from '../../deps.ts' import { config } from '../../lib/config.ts' -import { CliOptions, GlobalOptions } from '../../lib/types.ts' import { createEngine } from '../../lib/engine.ts' - -export type RunOptions = typeof run extends Command ? Options - : never +import type { CliOptions, GlobalOptions } from '../../lib/types.ts' interface AutomationToolLogs { time: string diff --git a/src/commands/clean.ts b/src/commands/clean.ts index fe312a0..449907d 100644 --- a/src/commands/clean.ts +++ b/src/commands/clean.ts @@ -2,6 +2,7 @@ import { Engine } from '../lib/engine.ts' import { Command } from '../deps.ts' export const clean = new Command() + .description('Clean') .option('--dry-run', 'Dry run', { default: false }) .action(async (options) => { await Engine.runClean(options) diff --git a/src/commands/debug/debug-config.ts b/src/commands/debug/debug-config.ts index a7a90f8..33dba70 100644 --- a/src/commands/debug/debug-config.ts +++ b/src/commands/debug/debug-config.ts @@ -1,15 +1,13 @@ +import { cmd } from '../../cmd.ts' import { Command } from '../../deps.ts' import { config } from '../../lib/config.ts' -import { CliOptions, GlobalOptions } from '../../lib/types.ts' - -export type DebugConfigOptions = typeof debugConfig extends Command ? Options - : never +import type { CliOptions, GlobalOptions } from '../../lib/types.ts' export const debugConfig = new Command() - .option('-r, --render', 'Render the config with substitutions') .description('debug config') + .option('-r, --render', 'Render the config with substitutions') .action((options) => { - const { render } = options as DebugConfigOptions & GlobalOptions + const { render } = options const cfg = config.get(options as CliOptions) if (render) { diff --git a/src/commands/debug/index.ts b/src/commands/debug/index.ts index 8b5a153..e83f292 100644 --- a/src/commands/debug/index.ts +++ b/src/commands/debug/index.ts @@ -1,5 +1,5 @@ import { Command } from '../../deps.ts' -import { GlobalOptions } from '../../lib/types.ts' +import type { GlobalOptions } from '../../lib/types.ts' import { debugConfig } from './debug-config.ts' diff --git a/src/commands/engine/index.ts b/src/commands/engine/index.ts index 34ed9fe..2171767 100644 --- a/src/commands/engine/index.ts +++ b/src/commands/engine/index.ts @@ -1,10 +1,10 @@ import { Command } from '../../deps.ts' -import { 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' +import type { GlobalOptions } from '../../lib/types.ts' export const engine = new Command() .description('engine') diff --git a/src/commands/engine/install.ts b/src/commands/engine/install.ts index 2263716..c65efbf 100644 --- a/src/commands/engine/install.ts +++ b/src/commands/engine/install.ts @@ -1,10 +1,8 @@ import { Command, ValidationError } from '../../deps.ts' import { cloneRepo, runEngineSetup } from '../../lib/utils.ts' -import { CliOptions } from '../../lib/types.ts' +import type { CliOptions } from '../../lib/types.ts' import { config } from '../../lib/config.ts' - -export type InstallOptions = typeof install extends Command ? Options - : never +import { cmd } from '../../cmd.ts' export const install = new Command() .description('install engine from a source repository') @@ -38,36 +36,37 @@ export const install = new Command() force, dryRun, setup, - } = options as InstallOptions + } = options const cfg = config.get(options as CliOptions) - source = source || cfg.engine.gitSource - destination = destination || cfg.engine.path - if (!source) { + const newSource = source || cfg.engine.gitSource + const newDestination = destination || cfg.engine.path + + if (!newSource) { throw new ValidationError('missing source') } - if (!destination) { + if (!newDestination) { throw new ValidationError('missing destination') } try { - await Deno.mkdir(destination) + await Deno.mkdir(newDestination) } catch (e) { if (e instanceof Deno.errors.AlreadyExists) { if (force && !dryRun) { - console.log(`Deleting ${destination}`) - await Deno.remove(destination, { recursive: true }) + console.log(`Deleting ${newDestination}`) + await Deno.remove(newDestination, { recursive: true }) } else { // Exit with a message instead of error so we can chain this install command console.log( - `Destination ${destination} already exists, use --force to overwrite.`, + `Destination ${newDestination} already exists, use --force to overwrite.`, ) return } } } const clonedPath = await cloneRepo({ - source, - destination, + source: newSource, + destination: newDestination, branch, useMirror: false, dryRun, diff --git a/src/commands/engine/setup.ts b/src/commands/engine/setup.ts index 04fbf9b..9f9d2df 100644 --- a/src/commands/engine/setup.ts +++ b/src/commands/engine/setup.ts @@ -1,12 +1,12 @@ import { Command } from '../../deps.ts' import { config } from '../../lib/config.ts' -import { CliOptions, GlobalOptions } from '../../lib/types.ts' +import type { CliOptions, GlobalOptions } from '../../lib/types.ts' import { runEngineSetup } from '../../lib/utils.ts' -export type SetupOptions = typeof setup extends Command ? Options +export type SetupOptions = typeof setup extends Command ? Options : never -export const setup = new Command() +export const setup = new Command() .description('run a managed engine setup') .option('-s, --gitdepends', 'install git dependencies (ie Setup.bat)') .option( diff --git a/src/commands/engine/update.ts b/src/commands/engine/update.ts index 1480cea..4e46b29 100644 --- a/src/commands/engine/update.ts +++ b/src/commands/engine/update.ts @@ -1,12 +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 type { CliOptions, GlobalOptions } from '../../lib/types.ts' -export type UpdateOptions = typeof update extends Command ? Options - : never - -export const update = new Command() +export const update = new Command() .description('update engine to a specific checkout') .env( 'RUNREAL_GIT_CLEAN_FLAGS=', @@ -38,7 +35,7 @@ export const update = new Command() setup, gitCleanFlags, dryRun, - } = options as UpdateOptions + } = options const cfg = config.get(options as CliOptions) const isRepo = await isGitRepo(cfg.engine.path) if (!isRepo) { diff --git a/src/commands/engine/version.ts b/src/commands/engine/version.ts index f09fc04..eb4789b 100644 --- a/src/commands/engine/version.ts +++ b/src/commands/engine/version.ts @@ -1,11 +1,9 @@ import { Command } from '../../deps.ts' import { config } from '../../lib/config.ts' -import { CliOptions, GlobalOptions } from '../../lib/types.ts' +import type { GlobalOptions, CliOptions } from '../../lib/types.ts' import { createEngine } from '../../lib/engine.ts' import { logger } from '../../lib/logger.ts' - -export type VersionOptions = typeof version extends Command ? Options - : never +import { cmd } from '../../cmd.ts' export const version = new Command() .description('print the engine version') diff --git a/src/commands/gen.ts b/src/commands/gen.ts index 40d71ba..de62424 100644 --- a/src/commands/gen.ts +++ b/src/commands/gen.ts @@ -2,10 +2,6 @@ import { Command } from '../deps.ts' import { createEngine, Engine } from '../lib/engine.ts' import { exec, findProjectFile } from '../lib/utils.ts' -export type GenOptions = typeof gen extends Command, [], void> - ? Options - : never - export const gen = new Command() .description('generate') .option('-p, --project-path ', 'Path to project folder', { diff --git a/src/commands/init.ts b/src/commands/init.ts index 9beed6b..5b97071 100644 --- a/src/commands/init.ts +++ b/src/commands/init.ts @@ -1,11 +1,9 @@ +import { cmd } from '../cmd.ts' 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 ? Options - : never - export const init = new Command() .description('init') .action(async ({ projectPath, enginePath }) => { diff --git a/src/commands/pkg.ts b/src/commands/pkg.ts index cfb7916..9543af2 100644 --- a/src/commands/pkg.ts +++ b/src/commands/pkg.ts @@ -2,7 +2,7 @@ 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 type { CliOptions, GlobalOptions } from '../lib/types.ts' const defaultBCRArgs = [ '-build', @@ -41,9 +41,6 @@ const profiles = { 'server': serverBCRArgs, } -export type PkgOptions = typeof pkg extends Command ? Options - : never - export const pkg = new Command() .description('package') .type('Configuration', new EnumType(EngineConfiguration)) @@ -57,7 +54,7 @@ export const pkg = new Command() .option('-d, --dry-run', 'Dry run') .option('--profile ', 'Build profile', { default: 'client', required: true }) .action(async (options) => { - const { platform, configuration, dryRun, profile, archiveDirectory, zip } = options as PkgOptions + const { platform, configuration, dryRun, profile, archiveDirectory, zip } = options const { engine: { path: enginePath }, project: { path: projectPath } } = config.get(options as CliOptions) const literal = pkg.getLiteralArgs().map((arg) => arg.toLowerCase()) @@ -79,13 +76,13 @@ export const pkg = new Command() 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 } @@ -101,7 +98,7 @@ export const pkg = new Command() const zipArgs = [ `-add=${expectedArchivePath}`, `-archive=${expectedArchivePath}.zip`, - `-compression=5`, + '-compression=5', ] await engine.runUAT(['ZipUtils', ...zipArgs]) } diff --git a/src/commands/uat.ts b/src/commands/uat.ts index 13c61d3..9dbefe1 100644 --- a/src/commands/uat.ts +++ b/src/commands/uat.ts @@ -2,10 +2,7 @@ import { Command } from '../deps.ts' import { createEngine, 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' - -export type UatOptions = typeof uat extends Command ? Options - : never +import type { CliOptions, GlobalOptions } from '../lib/types.ts' export const uat = new Command() .description('uat') diff --git a/src/commands/ubt.ts b/src/commands/ubt.ts index d16e3d7..e52b89f 100644 --- a/src/commands/ubt.ts +++ b/src/commands/ubt.ts @@ -1,11 +1,9 @@ import { Command } from '../deps.ts' -import { createEngine, EngineConfiguration, EnginePlatform, EngineTarget } from '../lib/engine.ts' +import { createEngine } from '../lib/engine.ts' import { findProjectFile } from '../lib/utils.ts' import { config } from '../lib/config.ts' -import { CliOptions, GlobalOptions } from '../lib/types.ts' - -export type UbtOptions = typeof ubt extends Command ? Options - : never +import type { CliOptions, GlobalOptions } from '../lib/types.ts' +import { cmd } from '../cmd.ts' export const ubt = new Command() .description('ubt') diff --git a/src/commands/workflow/exec.ts b/src/commands/workflow/exec.ts index 2745228..016052b 100644 --- a/src/commands/workflow/exec.ts +++ b/src/commands/workflow/exec.ts @@ -1,12 +1,9 @@ import { Command, EnumType, ValidationError } from '../../deps.ts' import { config } from '../../lib/config.ts' import { cmd } from '../../cmd.ts' -import { CliOptions, GlobalOptions } from '../../lib/types.ts' +import type { CliOptions, GlobalOptions } from '../../lib/types.ts' import { exec as execCmd, randomBuildkiteEmoji } from '../../lib/utils.ts' -import { getSubstitutions, render } from '../../lib/template.ts' - -export type ExecOptions = typeof exec extends Command ? Options - : never +import { render } from '../../lib/template.ts' enum Mode { Local = 'local', diff --git a/src/commands/workflow/index.ts b/src/commands/workflow/index.ts index be0d064..98c2c25 100644 --- a/src/commands/workflow/index.ts +++ b/src/commands/workflow/index.ts @@ -1,5 +1,5 @@ import { Command } from '../../deps.ts' -import { GlobalOptions } from '../../lib/types.ts' +import type { GlobalOptions } from '../../lib/types.ts' import { exec } from './exec.ts' diff --git a/src/lib/config.ts b/src/lib/config.ts index 07c76f7..02e6cef 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -1,6 +1,5 @@ import { deepmerge, dotenv, parse, path, ulid, ValidationError, z } from '../deps.ts' -import { CliOptions, RunrealConfig } from '../lib/types.ts' -import { execSync } from '../lib/utils.ts' +import type { CliOptions, RunrealConfig } from '../lib/types.ts' import { ConfigSchema, InternalSchema } from '../lib/schema.ts' import { Git, Perforce, Source } from './source.ts' import { normalizePaths, renderConfig } from './template.ts' @@ -103,7 +102,7 @@ export class Config { private async readConfigFile(configPath: string): Promise | null> { try { - const data = await Deno.readTextFile(path.resolve(configPath)) as string + const data = await Deno.readTextFile(path.resolve(configPath)) const parsed = parse(data) as unknown return parsed as RunrealConfig } catch (e) { /* pass */ } @@ -119,6 +118,7 @@ export class Config { if (!picked[section as keyof RunrealConfig]) { picked[section as keyof RunrealConfig] = {} as any } + ;(picked[section as keyof RunrealConfig] as any)[property] = cliOptions[cliOption as keyof CliOptions] } } @@ -127,19 +127,19 @@ export class Config { } private resolvePaths(config: Partial) { - if (config.engine && config.engine.path) { + if (config.engine?.path) { config.engine.path = path.resolve(config.engine.path) } - if (config.engine && config.engine.gitDependenciesCachePath) { + if (config.engine?.gitDependenciesCachePath) { config.engine.gitDependenciesCachePath = path.resolve(config.engine.gitDependenciesCachePath) } - if (config.project && config.project.path) { + if (config.project?.path) { config.project.path = path.resolve(config.project.path) } - if (config.project && config.project.buildPath) { + if (config.project?.buildPath) { config.project.buildPath = path.resolve(config.project.buildPath) } @@ -155,7 +155,8 @@ export class Config { safeRef, git, } - } else if (this.config.project?.repoType === 'perforce') { + } + if (this.config.project?.repoType === 'perforce') { const { safeRef, perforce } = this.getPerforceBuildMetadata(cwd) return { safeRef, @@ -241,9 +242,9 @@ export class Config { } catch (e) { if (e instanceof z.ZodError) { const errors = e.errors.map((err) => { - return ' config.' + err.path.join('.') + ' is ' + err.message + return ` config.${err.path.join('.')} is ${err.message}` }) - throw new ValidationError('Invalid config: \n' + errors.join('\n')) + throw new ValidationError(`Invalid config: \n${errors.join('\n')}`) } throw new ValidationError('Invalid config') } diff --git a/src/lib/engine.ts b/src/lib/engine.ts index accbc97..f59f4fe 100644 --- a/src/lib/engine.ts +++ b/src/lib/engine.ts @@ -1,4 +1,4 @@ -import { globber, path } from '../deps.ts' +import { globber, path, z } from '../deps.ts' import { copyBuildGraphScripts, exec, findProjectFile } from './utils.ts' import { config } from './config.ts' @@ -164,7 +164,7 @@ export abstract class Engine { const args = ['-Mode=QueryTargets', `-Project=${projectFile}`] await this.ubt(args, { quiet: true }) try { - const targetInfoJson = path.resolve(projectPath + '\\Intermediate\\TargetInfo.json') + const targetInfoJson = path.resolve(`${projectPath}\\Intermediate\\TargetInfo.json`) const { Targets } = JSON.parse(Deno.readTextFileSync(targetInfoJson)) const targets = Targets.map((target: TargetInfo) => target.Name) return targets @@ -264,7 +264,7 @@ class WindowsEngine extends Engine { const args = ['-Mode=QueryTargets'] await this.ubt(args, { quiet: true }) try { - const targetInfoJson = path.resolve(this.enginePath + '\\Engine\\Intermediate\\TargetInfo.json') + const targetInfoJson = path.resolve(`${this.enginePath}\\Engine\\Intermediate\\TargetInfo.json`) const { Targets } = JSON.parse(Deno.readTextFileSync(targetInfoJson)) const targets = Targets.map((target: TargetInfo) => target.Name) return targets @@ -327,7 +327,7 @@ class MacosEngine extends Engine { const args = ['-Mode=QueryTargets'] await this.ubt(args, { quiet: true }) try { - const targetInfoJson = path.resolve(this.enginePath + '/Engine/Intermediate/TargetInfo.json') + const targetInfoJson = path.resolve(`${this.enginePath}/Engine/Intermediate/TargetInfo.json`) const { Targets } = JSON.parse(Deno.readTextFileSync(targetInfoJson)) const targets = Targets.map((target: TargetInfo) => target.Name) return targets @@ -390,7 +390,7 @@ class LinuxEngine extends Engine { const args = ['-Mode=QueryTargets'] await this.ubt(args, { quiet: true }) try { - const targetInfoJson = path.resolve(this.enginePath + '/Engine/Intermediate/TargetInfo.json') + const targetInfoJson = path.resolve(`${this.enginePath}/Engine/Intermediate/TargetInfo.json`) const { Targets } = JSON.parse(Deno.readTextFileSync(targetInfoJson)) const targets = Targets.map((target: TargetInfo) => target.Name) return targets diff --git a/src/lib/logger.ts b/src/lib/logger.ts index 45a16c5..36a0bcc 100644 --- a/src/lib/logger.ts +++ b/src/lib/logger.ts @@ -49,10 +49,10 @@ class Logger { this.logLevel = level } - private formatMessage(level: LogLevel, message: any) { + private formatMessage(level: LogLevel, message: string) { const timestamp = new Date().toISOString() const messageStr = typeof message === 'object' ? `\n${Deno.inspect(message, { colors: true })}` : message - let levelStr + let levelStr: string switch (level) { case LogLevel.INFO: levelStr = fmt.bold(fmt.green(level)) @@ -93,21 +93,21 @@ class Logger { return level >= this.logLevel } - info(message: any) { + info(message: string) { if (!this.shouldLog(LogLevel.INFO)) return const formatted = this.formatMessage(LogLevel.INFO, message) console.log(formatted) this.writeToFile(formatted) } - error(message: any) { + error(message: string) { if (!this.shouldLog(LogLevel.ERROR)) return const formatted = this.formatMessage(LogLevel.ERROR, message) console.error(formatted) this.writeToFile(formatted) } - debug(message: any) { + debug(message: string) { if (!this.shouldLog(LogLevel.DEBUG)) return const formatted = this.formatMessage(LogLevel.DEBUG, message) console.log(formatted) diff --git a/src/lib/schema.ts b/src/lib/schema.ts index 71f01a9..e746d04 100644 --- a/src/lib/schema.ts +++ b/src/lib/schema.ts @@ -46,7 +46,7 @@ export const ConfigSchema = z.object({ }), workflows: z.array( z.object({ - id: z.string().regex(new RegExp('^[a-zA-Z0-9][a-zA-Z0-9\\-]*$')).optional().describe('Workflow id'), + id: z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9\-]*$/).optional().describe('Workflow id'), name: z.string().describe('Workflow name'), steps: z.array( z.object({ diff --git a/src/lib/source.ts b/src/lib/source.ts index 85843eb..7987709 100644 --- a/src/lib/source.ts +++ b/src/lib/source.ts @@ -25,7 +25,7 @@ abstract class Base { } export class Perforce extends Base { - executable: string = 'p4' + executable = 'p4' clientName: string constructor(cwd: string) { super(cwd) @@ -86,7 +86,8 @@ export class Perforce extends Base { return destination } postClone(): void { - return this.sync() + this.sync() + return } sync(): void { execSync(this.executable, ['sync'], { cwd: this.cwd, quiet: false }) @@ -97,7 +98,7 @@ export class Perforce extends Base { } export class Git extends Base { - executable: string = 'git' + executable = 'git' branch(): string { // On Buildkite, use the BUILDKITE_BRANCH env var as we may be in a detached HEAD state if (Deno.env.get('BUILDKITE_BRANCH')) { diff --git a/src/lib/template.ts b/src/lib/template.ts index e3740ca..9687edc 100644 --- a/src/lib/template.ts +++ b/src/lib/template.ts @@ -1,4 +1,4 @@ -import { RunrealConfig } from './types.ts' +import type { RunrealConfig } from './types.ts' import { path } from '../deps.ts' import { formatIsoTimestamp } from './utils.ts' @@ -72,10 +72,12 @@ function renderItems( if (typeof item === 'string') { // Replace placeholders in strings return replace(placeholderRegex, item, substitutions) - } else if (Array.isArray(item)) { + } + if (Array.isArray(item)) { // Recursively process each item in an array return item.map((subItem) => renderItems(subItem, substitutions, replace)) - } else if (typeof item === 'object' && item !== null) { + } + if (typeof item === 'object' && item !== null) { // Recursively process each property in an object const result: Record = {} for (const key of Object.keys(item)) { diff --git a/src/lib/types.ts b/src/lib/types.ts index 122dd0b..646e138 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -1,22 +1,14 @@ -import { Command, z } from '../deps.ts' -import { cmd } from '../cmd.ts' +import type { Command, z } from '../deps.ts' +import type { cmd } from '../cmd.ts' -import { DebugConfigOptions } from '../commands/debug/debug-config.ts' -import { SetupOptions } from '../commands/engine/setup.ts' -import { InstallOptions } from '../commands/engine/install.ts' -import { UpdateOptions } from '../commands/engine/update.ts' -import { ConfigSchema, InternalSchema } from './schema.ts' +import type { ConfigSchema, InternalSchema } from './schema.ts' export type GlobalOptions = typeof cmd extends Command> ? Options : never export type CliOptions = Partial< - & GlobalOptions - & DebugConfigOptions - & SetupOptions - & InstallOptions - & UpdateOptions + GlobalOptions > type InternalRunrealConfig = z.infer diff --git a/src/lib/utils.ts b/src/lib/utils.ts index c36a801..0fec54e 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,6 +1,6 @@ import { mergeReadableStreams, path, xml2js } from '../deps.ts' -import { createEngine, EngineConfiguration, EnginePlatform, EngineTarget } from './engine.ts' -import { GitIgnoreFiles, UeDepsManifest } from './types.ts' +import { createEngine } from './engine.ts' +import type { GitIgnoreFiles, UeDepsManifest } from './types.ts' export async function exec( cmd: string, @@ -92,12 +92,10 @@ export async function getHomeDir(): Promise { if (homeDir) { return homeDir - } else { - throw new Error('Could not determine the home directory.') } - } else { - throw new Error('Permission denied: Cannot access environment variables.') + throw new Error('Could not determine the home directory.') } + throw new Error('Permission denied: Cannot access environment variables.') } export function getHomeDirSync(): string { @@ -108,12 +106,10 @@ export function getHomeDirSync(): string { if (homeDir) { return homeDir - } else { - throw new Error('Could not determine the home directory.') } - } else { - throw new Error('Permission denied: Cannot access environment variables.') + throw new Error('Could not determine the home directory.') } + throw new Error('Permission denied: Cannot access environment variables.') } export async function createConfigDir(): Promise { @@ -139,9 +135,8 @@ export async function readConfigFile(): Promise> { } catch (error) { if (error instanceof Deno.errors.NotFound) { return {} - } else { - throw error } + throw error } } diff --git a/tests/config.test.ts b/tests/config.test.ts index 5b4bdb9..56a38b4 100644 --- a/tests/config.test.ts +++ b/tests/config.test.ts @@ -1,8 +1,8 @@ import { assert, assertEquals } from '@std/assert' import { Config } from '../src/lib/config.ts' import { path, ulid } from '../src/deps.ts' -import { CliOptions } from '../src/lib/types.ts' import { FakeTime } from '@std/testing/time' +import type { CliOptions } from '../src/lib/types.ts' Deno.test('Config.create should initialize with default values', async () => { using time = new FakeTime()