chore: checkpoint admin restore state
This commit is contained in:
+19
-10
@@ -4,18 +4,27 @@ import { fileURLToPath } from 'node:url';
|
||||
|
||||
const projectRoot = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
|
||||
function loadEnvFile(filePath) {
|
||||
if (!fs.existsSync(filePath)) return;
|
||||
for (const line of fs.readFileSync(filePath, 'utf8').split('\n')) {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed || trimmed.startsWith('#')) continue;
|
||||
const eq = trimmed.indexOf('=');
|
||||
if (eq < 0) continue;
|
||||
const key = trimmed.slice(0, eq).trim();
|
||||
const value = trimmed.slice(eq + 1).trim();
|
||||
if (!process.env[key]) process.env[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
export function loadProjectEnv() {
|
||||
for (const file of ['.env', '.env.local']) {
|
||||
const filePath = path.join(projectRoot, file);
|
||||
if (!fs.existsSync(filePath)) continue;
|
||||
for (const line of fs.readFileSync(filePath, 'utf8').split('\n')) {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed || trimmed.startsWith('#')) continue;
|
||||
const eq = trimmed.indexOf('=');
|
||||
if (eq < 0) continue;
|
||||
const key = trimmed.slice(0, eq).trim();
|
||||
const value = trimmed.slice(eq + 1).trim();
|
||||
if (!process.env[key]) process.env[key] = value;
|
||||
loadEnvFile(path.join(projectRoot, file));
|
||||
}
|
||||
const memindRoot = process.env.MEMIND_LIB_ROOT?.trim();
|
||||
if (memindRoot) {
|
||||
for (const file of ['.env', '.env.local']) {
|
||||
loadEnvFile(path.join(memindRoot, file));
|
||||
}
|
||||
}
|
||||
return projectRoot;
|
||||
|
||||
Reference in New Issue
Block a user