Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 66b83f2

Browse files
author
Je
committed
refactor: improve config loading
1 parent 7f6213f commit 66b83f2

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

project.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ export class Project {
7272
},
7373
env: {}
7474
}
75-
log.info(colors.bold('Aleph.js'))
7675
this.ready = (async () => {
7776
const t = performance.now()
7877
await this._loadConfig()
@@ -417,20 +416,22 @@ export class Project {
417416
for await (const { path: p } of walk(this.srcDir, { includeDirs: false, exts: ['.js', '.mjs', '.ts', '.json'], skip: [/\.d\.ts$/i], maxDepth: 1 })) {
418417
const name = path.basename(p)
419418
if (name.split('.')[0] === 'config') {
420-
log.info(colors.bold(' Config'))
421-
log.info(' ⚙️', name)
422-
if (name.endsWith('.json')) {
419+
if (reModuleExt.test(name)) {
420+
const { default: conf } = await import('file://' + p)
421+
if (util.isPlainObject(conf)) {
422+
Object.assign(config, conf)
423+
Object.assign(this.config, { __file: name })
424+
}
425+
} else if (name.endsWith('.json')) {
423426
try {
424427
const conf = JSON.parse(await Deno.readTextFile(p))
425-
Object.assign(config, conf)
428+
if (util.isPlainObject(conf)) {
429+
Object.assign(config, conf)
430+
Object.assign(this.config, { __file: name })
431+
}
426432
} catch (e) {
427433
log.fatal('parse config.json:', e.message)
428434
}
429-
} else {
430-
const { default: conf } = await import('file://' + p)
431-
if (util.isPlainObject(conf)) {
432-
Object.assign(config, conf)
433-
}
434435
}
435436
}
436437
}
@@ -559,6 +560,11 @@ export class Project {
559560
const { renderPage, renderHead } = await import('file://' + this.#modules.get('//deno.land/x/aleph/renderer.js')!.jsFile)
560561
this.#renderer = { renderPage, renderHead }
561562

563+
log.info(colors.bold('Aleph.js'))
564+
if ('__file' in this.config) {
565+
log.info(colors.bold(' Config'))
566+
log.info(' ⚙️', this.config['__file'])
567+
}
562568
log.info(colors.bold(' Global'))
563569
if (this.#modules.has('/app.js')) {
564570
log.info(' ✓', 'Custom App')

0 commit comments

Comments
 (0)