mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 02:14:01 +00:00
Release God's Eye View as open source
This commit is contained in:
1 parent
a5aaea7e16
commit
880a672b5e
433 files changed
+219893
-23
No files matched your search
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env node
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { loadEnv } from 'vite';
|
||||
|
||||
/**
|
||||
* Read one dotenv key with Vite's parser; no file content is executed.
|
||||
*
|
||||
* Reports what the FILES say. `loadEnv` lets `process.env` override the parsed
|
||||
* files, so an inherited export — an empty one above all, which is how a shell
|
||||
* says "unset" to this script's callers — would otherwise mask the value the
|
||||
* user wrote down. The key is hidden for the duration of the read and restored
|
||||
* afterwards, leaving the caller's environment untouched.
|
||||
*/
|
||||
export function readDotenvValue(variableName, rootDir = process.cwd(), mode = 'development') {
|
||||
const key = String(variableName || '').trim();
|
||||
if (!/^[A-Z_][A-Z0-9_]*$/i.test(key)) return '';
|
||||
const inherited = Object.prototype.hasOwnProperty.call(process.env, key)
|
||||
? process.env[key]
|
||||
: undefined;
|
||||
if (inherited !== undefined) delete process.env[key];
|
||||
try {
|
||||
const env = loadEnv(mode, path.resolve(rootDir), '');
|
||||
return String(env[key] ?? '');
|
||||
} finally {
|
||||
if (inherited !== undefined) process.env[key] = inherited;
|
||||
}
|
||||
}
|
||||
|
||||
const invokedPath = process.argv[1] ? path.resolve(process.argv[1]) : '';
|
||||
if (invokedPath === fileURLToPath(import.meta.url)) {
|
||||
process.stdout.write(readDotenvValue(process.argv[2], process.argv[3] || process.cwd()));
|
||||
}
|
||||
Reference in new issue
Block a user