开始多平台 多店铺整改

This commit is contained in:
yml
2026-04-08 22:21:11 +08:00
parent d5b10e3f7f
commit a2b09c89e8
40 changed files with 1750 additions and 685 deletions
+59 -4
View File
@@ -7,13 +7,17 @@ import { fileURLToPath } from 'node:url'
const require = createRequire(import.meta.url)
const CURRENT_DIR = path.dirname(fileURLToPath(import.meta.url))
export const PROJECT_ROOT = path.resolve(CURRENT_DIR, '../..')
const WORKSPACE_ROOT = path.resolve(PROJECT_ROOT, '../..')
const CONFIG_ROOT = path.join(PROJECT_ROOT, 'config')
const defaultConfig = loadConfig(path.join(CONFIG_ROOT, 'default.cjs'))
const localConfig = loadConfig(path.join(CONFIG_ROOT, 'local.cjs'))
const mergedConfig = deepMerge(defaultConfig, localConfig)
loadEnvFiles([
path.join(WORKSPACE_ROOT, '.env'),
path.join(PROJECT_ROOT, '.env'),
])
export const runtimeConfig = applyEnvOverrides(mergedConfig)
const defaultConfig = loadConfig(path.join(CONFIG_ROOT, 'default.cjs'))
export const runtimeConfig = applyEnvOverrides(defaultConfig)
function loadConfig(configPath) {
if (!fs.existsSync(configPath)) {
@@ -24,6 +28,57 @@ function loadConfig(configPath) {
return isPlainObject(loaded) ? loaded : {}
}
function loadEnvFiles(filePaths) {
for (const filePath of filePaths) {
loadEnvFile(filePath)
}
}
function loadEnvFile(filePath) {
if (!fs.existsSync(filePath)) {
return
}
const rawText = fs.readFileSync(filePath, 'utf8')
const lines = rawText.split(/\r?\n/)
for (const rawLine of lines) {
const line = rawLine.trim()
if (!line || line.startsWith('#')) {
continue
}
const separatorIndex = line.indexOf('=')
if (separatorIndex <= 0) {
continue
}
const key = line.slice(0, separatorIndex).trim()
if (!key || key in process.env) {
continue
}
const value = parseEnvValue(line.slice(separatorIndex + 1))
process.env[key] = value
}
}
function parseEnvValue(rawValue) {
const value = String(rawValue || '').trim()
if (!value) {
return ''
}
const quote = value[0]
if ((quote === '"' || quote === "'") && value.endsWith(quote)) {
return value.slice(1, -1)
}
return value
}
function applyEnvOverrides(baseConfig) {
const nextConfig = deepMerge(baseConfig, {})