mirror of
https://github.com/toddbluhm/env-cmd.git
synced 2025-12-08 18:23:33 +00:00
ADD default .env file as a fallback
If a repository contains a `.env` example file or - in case of a private repository - a `.env` file with production values, a developer can add a local (e.g. `.env.local` file to `.gitignore`) and feed it to `env-cmd`. So in development a custom local configuration can be used, but in production, `env-cmd` falls back to `.env`
This commit is contained in:
parent
104475c11d
commit
1dff4fa2a3
12
lib/index.js
12
lib/index.js
@ -4,7 +4,8 @@ const spawn = require('cross-spawn').spawn
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
const rcFileLocation = path.join(process.cwd(), '.env-cmdrc')
|
||||
|
||||
const envFilePathDefault = path.join(process.cwd(), '.env')
|
||||
|
||||
function EnvCmd (args) {
|
||||
// First Parse the args from the command line
|
||||
const parsedArgs = ParseArgs(args)
|
||||
@ -133,8 +134,13 @@ function UseCmdLine (parsedArgs) {
|
||||
let file
|
||||
try {
|
||||
file = fs.readFileSync(envFilePath, { encoding: 'utf8' })
|
||||
} catch (e) {
|
||||
throw new Error(`Error! Could not find or read file at ${envFilePath}`)
|
||||
} catch (err) {
|
||||
console.error(`Error! Could not find or read file at ${envFilePath}`)
|
||||
try {
|
||||
file = fs.readFileSync(envFilePathDefault)
|
||||
} catch (e) {
|
||||
throw new Error(`Error! Could not fallback to find or read file at ${envFilePathDefault}`)
|
||||
}
|
||||
}
|
||||
|
||||
const ext = path.extname(envFilePath).toLowerCase()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user