Files
ChatApp/apps/mobile/scripts/check-env.mjs
T

39 lines
1.2 KiB
JavaScript

#!/usr/bin/env node
// Compares apps/mobile/.env.example with .env.local. Surfaces missing keys
// so an onboarding dev doesn't ship a build that white-screens.
import { existsSync, readFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
const here = dirname(fileURLToPath(import.meta.url));
const mobileRoot = resolve(here, '..');
const examplePath = resolve(mobileRoot, '.env.example');
const localPath = resolve(mobileRoot, '.env.local');
if (!existsSync(localPath)) {
console.error('No .env.local found at ' + localPath);
console.error('Copy .env.example to .env.local and fill in values.');
process.exit(1);
}
function keysOf(path) {
return new Set(
readFileSync(path, 'utf8')
.split('\n')
.map((line) => line.trim())
.filter((line) => line.length > 0 && !line.startsWith('#'))
.map((line) => line.split('=', 1)[0]),
);
}
const exampleKeys = keysOf(examplePath);
const localKeys = keysOf(localPath);
const missing = [...exampleKeys].filter((k) => !localKeys.has(k));
if (missing.length > 0) {
console.error('Missing keys in .env.local: ' + missing.join(', '));
process.exit(1);
}
console.log('env-ok: all .env.example keys present in .env.local');