32 lines
935 B
Bash
Executable File
32 lines
935 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# Loads variables from .env into the current shell via Node.
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
ENV_FILE="$ROOT/.env"
|
|
|
|
if [[ ! -f "$ENV_FILE" ]]; then
|
|
echo ".env nicht gefunden: $ENV_FILE" >&2
|
|
exit 1
|
|
fi
|
|
|
|
eval "$(
|
|
node --input-type=module -e "
|
|
import { readFileSync } from 'node:fs';
|
|
process.loadEnvFile('$ENV_FILE');
|
|
const content = readFileSync('$ENV_FILE', 'utf8');
|
|
for (const line of content.split('\n')) {
|
|
const trimmed = line.trim();
|
|
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
const eq = trimmed.indexOf('=');
|
|
if (eq === -1) continue;
|
|
const key = trimmed.slice(0, eq).trim();
|
|
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) continue;
|
|
const value = process.env[key];
|
|
if (value !== undefined) {
|
|
process.stdout.write('export ' + key + '=' + JSON.stringify(value) + ';');
|
|
}
|
|
}
|
|
"
|
|
)"
|