MCPcopy
hub / github.com/toddbluhm/env-cmd / getEnvFile

Function getEnvFile

src/get-env-vars.ts:26–72  ·  view source on GitHub ↗
(
  { filePath, fallback, verbose }: { filePath?: string, fallback?: boolean, verbose?: boolean },
)

Source from the content-addressed store, hash-verified

24}
25
26export async function getEnvFile(
27 { filePath, fallback, verbose }: { filePath?: string, fallback?: boolean, verbose?: boolean },
28): Promise<Environment> {
29 // Use env file
30 if (filePath !== undefined) {
31 try {
32 const env = await getEnvFileVars(filePath)
33 if (verbose === true) {
34 console.info(`Found .env file at path: ${filePath}`)
35 }
36 return env
37 }
38 catch (error) {
39 if (isLoaderError(error)) {
40 throw error
41 }
42
43 if (verbose === true) {
44 console.info(`Failed to find .env file at path: ${filePath}`)
45 }
46 // Ignore error as we are just trying this location
47 }
48 if (fallback !== true) {
49 throw new Error(`Failed to find .env file at path: ${filePath}`)
50 }
51 }
52
53 // Use the default env file locations
54 for (const path of ENV_FILE_DEFAULT_LOCATIONS) {
55 try {
56 const env = await getEnvFileVars(path)
57 if (verbose === true) {
58 console.info(`Found .env file at default path: ${path}`)
59 }
60 return env
61 }
62 catch {
63 // Ignore error because we are just trying this location
64 }
65 }
66
67 const error = `Failed to find .env file at default paths: [${ENV_FILE_DEFAULT_LOCATIONS.join(',')}]`
68 if (verbose === true) {
69 console.info(error)
70 }
71 throw new Error(error)
72}
73
74export async function getRCFile(
75 { environments, filePath, verbose }: { environments: string[], filePath?: string, verbose?: boolean },

Callers 1

getEnvVarsFunction · 0.85

Calls 2

getEnvFileVarsFunction · 0.85
isLoaderErrorFunction · 0.85

Tested by

no test coverage detected