Skip to content

Commit

Permalink
chore: add example 1
Browse files Browse the repository at this point in the history
with incomplete output atm
  • Loading branch information
chrisbbreuer committed Nov 7, 2024
1 parent de495ee commit e0820a6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
24 changes: 24 additions & 0 deletions fixtures/input/example-0001.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { resolve } from 'node:path'
import process from 'node:process'
import { deepMerge } from './utils'

export interface ConfigOptions<T> {
name: string
cwd?: string
defaultConfig: T
}

export async function loadConfig<T extends Record<string, unknown>>({ name, cwd, defaultConfig }: ConfigOptions<T>): Promise<T> {
const c = cwd ?? process.cwd()
const configPath = resolve(c, `${name}.config`)

try {
const importedConfig = await import(configPath)
const loadedConfig = importedConfig.default || importedConfig
return deepMerge(defaultConfig, loadedConfig)
}
catch (error) {
console.error(`Error loading config from ${configPath}:`, error)
return defaultConfig
}
}
6 changes: 6 additions & 0 deletions fixtures/output/example-0001.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export declare interface ConfigOptions<T> {
name: string
cwd?: string
defaultConfig: T
}
export declare function loadConfig<T extends Record<string, unknown>>({ name, cwd, defaultConfig }: ConfigOptions<T>): Promise<T>;

0 comments on commit e0820a6

Please sign in to comment.