-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconfig.imba
More file actions
24 lines (21 loc) · 831 Bytes
/
config.imba
File metadata and controls
24 lines (21 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import ConfigNotCachedError from './Error/ConfigNotCachedError'
import dot from './dotNotation'
import runtime from './runtime'
import path from 'path'
def fallback notation\string, default\any = null
if !notation or typeof notation != 'string'
throw new ConfigNotCachedError
try
const app = require('../../Foundation/Application').default
app.getConfig(notation, default)
catch e
throw new ConfigNotCachedError
export default def config notation\string, default\any = null
if !notation or typeof notation != 'string'
return default
try
const cachedConfig = path.join(process.cwd!, 'bootstrap', 'cache', 'config.json')
const config = runtime() == 'bun' ? JSON.parse(fs.readFileSync(cachedConfig)) : require(cachedConfig)
return dot(config, notation) ?? default
catch e
return fallback(notation, default)