37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { readFileSync } from 'node:fs'
|
|
|
|
export interface AppBranding {
|
|
brandName: string
|
|
institutionName: string
|
|
productName: string
|
|
shortName: string
|
|
tagline: string
|
|
description: string
|
|
}
|
|
|
|
interface AppSettings {
|
|
Branding?: Partial<Record<keyof AppBranding | Capitalize<keyof AppBranding>, unknown>>
|
|
}
|
|
|
|
const appsettings = JSON.parse(
|
|
readFileSync(new URL('../src/Jiaowu.Api/appsettings.json', import.meta.url), 'utf8'),
|
|
) as AppSettings
|
|
|
|
function required(field: keyof AppBranding): string {
|
|
const pascalCase = `${field.charAt(0).toUpperCase()}${field.slice(1)}` as Capitalize<keyof AppBranding>
|
|
const value = appsettings.Branding?.[pascalCase] ?? appsettings.Branding?.[field]
|
|
if (typeof value !== 'string' || !value.trim()) {
|
|
throw new Error(`appsettings.json 中缺少 Branding:${pascalCase}。`)
|
|
}
|
|
return value.trim()
|
|
}
|
|
|
|
export const branding: Readonly<AppBranding> = Object.freeze({
|
|
brandName: required('brandName'),
|
|
institutionName: required('institutionName'),
|
|
productName: required('productName'),
|
|
shortName: required('shortName'),
|
|
tagline: required('tagline'),
|
|
description: required('description'),
|
|
})
|