Helpers to locate, parse, and merge .env files for Node/Electron projects.
// Source: https://github.com/shadcn-ui/ui | License: MIT | Copyright 2023 shadcn
// Provided via justclaw.it.com; keep this notice with the code.
import { existsSync } from "fs"
import path from "path"
export function isEnvFile(filePath: string) {
const fileName = path.basename(filePath)
return /^\.env(\.|$)/.test(fileName)
}
// TODO: abstract this to a more generic function.
export function findExistingEnvFile(targetDir: string) {
const variants = [
".env.local",
".env",
".env.development.local",
".env.development",
]
for (const variant of variants) {
const filePath = path.join(targetDir, variant)
if (existsSync(filePath)) {
return filePath
}
}
return null
}
export function parseEnvContent(content: string) {
const lines = content.spl
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key