import path from 'node:path'
import { fileURLToPath } from 'node:url'

import { createDefaultRuntimeConfig } from './defaults.js'
import { applyEnvOverrides } from './env-overrides.js'
import { loadEnvFiles } from './runtime-env.js'

const CURRENT_DIR = path.dirname(fileURLToPath(import.meta.url))
export const PROJECT_ROOT = path.resolve(CURRENT_DIR, '../..')
const WORKSPACE_ROOT = path.resolve(PROJECT_ROOT, '../..')

loadEnvFiles([path.join(WORKSPACE_ROOT, '.env'), path.join(PROJECT_ROOT, '.env')])

export const runtimeConfig = applyEnvOverrides(createDefaultRuntimeConfig(PROJECT_ROOT))
