harsta
Version:
Harsta is a contract development tool based on Hardhat, designed to streamline the development, testing, and referencing of contracts, addresses, ABIs, and contract instances.
31 lines (25 loc) • 774 B
text/typescript
import consola from 'consola'
import { createJiti } from 'jiti'
import { resolve } from 'pathe'
export type UserInputConfig = Record<string, any>
export interface ResolvedConfig<T extends UserInputConfig = UserInputConfig> {
config: T
configFile: string
}
export function loadConfig<T extends UserInputConfig = UserInputConfig>(options: { name: string, cwd: string }): ResolvedConfig<T> {
const { name, cwd } = options
const filePath = resolve(cwd, `${name}.config.ts`)
let data = {} as T
try {
const jiti = createJiti(__dirname, { interopDefault: true })
data = jiti(filePath)
}
catch (error) {
consola.log(error)
consola.debug(`Failed to load config file: ${filePath}`)
}
return {
config: data,
configFile: filePath,
}
}