flnxi-Wu/lib/configLoader.ts
WuYongJie 5f2ba48532
Some checks failed
CI Check / check (push) Has been cancelled
优化模板管理器拖拽交互体验
- 移除高亮卡片效果,避免与虚位卡片视觉重复
- 松开鼠标后立即更新布局,不再等待动画完成
- 优化拖拽动画效果,使用弹性缓动函数
- 更新 CHANGELOG.md 记录本次优化
2025-11-20 11:24:25 +08:00

44 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import fs from 'fs'
import path from 'path'
/**
* 读取根目录的 config-bianliang.env 并注入到 process.env
* - 仅在变量未设置时写入,绝不覆盖真实环境变量或 .env 值
* - 支持以 # 开头的注释,空行会被忽略
* - 行格式 KEY=VALUE,等号右侧原样接收(去除收尾空白)
*/
export function loadPortableEnvIfPresent(): void {
try {
const root = process.cwd()
const envFile = path.join(root, 'config-bianliang.env')
if (!fs.existsSync(envFile)) return
const content = fs.readFileSync(envFile, 'utf8')
const lines = content.split(/\r?\n/)
for (const rawLine of lines) {
const line = rawLine.trim()
if (!line || line.startsWith('#')) continue
const eqIndex = line.indexOf('=')
if (eqIndex <= 0) continue
const key = line.slice(0, eqIndex).trim()
const value = line.slice(eqIndex + 1).trim()
if (!key) continue
if (process.env[key] === undefined || process.env[key] === '') {
process.env[key] = value
}
}
} catch {
// 静默失败,避免影响运行
}
}
const configLoader = { loadPortableEnvIfPresent }
export default configLoader