重构后台管理服务并推进渐进式类型化
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
// @ts-check
|
||||
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import process from 'node:process'
|
||||
import { createRequire } from 'node:module'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
/** @typedef {import('../types/runtime-config.js').AgisoMessagingShopsConfig} AgisoMessagingShopsConfig */
|
||||
/** @typedef {import('../types/runtime-config.js').RuntimeConfig} RuntimeConfig */
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const CURRENT_DIR = path.dirname(fileURLToPath(import.meta.url))
|
||||
export const PROJECT_ROOT = path.resolve(CURRENT_DIR, '../..')
|
||||
@@ -15,9 +20,9 @@ loadEnvFiles([
|
||||
path.join(PROJECT_ROOT, '.env'),
|
||||
])
|
||||
|
||||
const defaultConfig = loadConfig(path.join(CONFIG_ROOT, 'default.cjs'))
|
||||
const defaultConfig = /** @type {RuntimeConfig} */ (loadConfig(path.join(CONFIG_ROOT, 'default.cjs')))
|
||||
|
||||
export const runtimeConfig = applyEnvOverrides(defaultConfig)
|
||||
export const runtimeConfig = /** @type {RuntimeConfig} */ (applyEnvOverrides(defaultConfig))
|
||||
|
||||
function loadConfig(configPath) {
|
||||
if (!fs.existsSync(configPath)) {
|
||||
@@ -381,6 +386,7 @@ function parseJsonArray(rawValue) {
|
||||
}
|
||||
|
||||
function normalizeAgisoMessagingShops(rawValue) {
|
||||
/** @type {AgisoMessagingShopsConfig} */
|
||||
const output = {}
|
||||
|
||||
for (const [shopId, config] of Object.entries(rawValue || {})) {
|
||||
@@ -389,6 +395,7 @@ function normalizeAgisoMessagingShops(rawValue) {
|
||||
continue
|
||||
}
|
||||
|
||||
/** @type {AgisoMessagingShopsConfig[string]} */
|
||||
const next = {}
|
||||
const enabled = normalizeBooleanLike(config.enabled)
|
||||
if (enabled !== null) {
|
||||
|
||||
Reference in New Issue
Block a user