-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mark Hanna
committed
Jul 23, 2024
1 parent
af3e6b4
commit 934f893
Showing
2 changed files
with
39 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { writeFileSync } from 'node:fs'; | ||
|
||
import dotenv from 'dotenv'; | ||
|
||
import packageJson from '../package.json' with { type: 'json' }; | ||
|
||
const defaultEnv = `PROJECT_NAME = "${packageJson.name}" | ||
MODE = "development" | ||
PORT = "8080"`; | ||
|
||
function init() { | ||
try { | ||
// If no .env file exists, create one first | ||
writeFileSync('.env', defaultEnv, { flag: 'wx' }); | ||
console.log('Creating default .env file'); | ||
} catch (e) { | ||
// If a .env file exists, just continue | ||
} | ||
|
||
dotenv.config(); | ||
} | ||
|
||
export function getEnv(): Partial<Record<string, string>> { | ||
init(); | ||
|
||
return process.env; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters