-
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
Russell Green
committed
Jun 20, 2023
1 parent
c5d74e6
commit dfb68f5
Showing
5 changed files
with
45 additions
and
5 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
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
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
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
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,32 @@ | ||
const fs = require("fs"); | ||
const { env } = require("process"); | ||
const { version } = require("./package.json"); | ||
const configEnvName = "RPC_CONFIG"; | ||
const configJson = env[configEnvName]; | ||
const nodeEnv = env["NODE_ENV"]; | ||
const configFilePath = "./data/config.json"; | ||
|
||
function initializeConfig() { | ||
const hasConfig = Boolean(configJson); | ||
const message = hasConfig | ||
? `Config env variable '${CONFIG_ENV_VAR_NAME}' exists. File will be written to disk.` | ||
: `No value found for config env variable '${CONFIG_ENV_VAR_NAME}'. Skipping writing config file.`; | ||
|
||
console.log(message); | ||
if (hasConfig) { | ||
saveConfig(config); | ||
} | ||
} | ||
|
||
function saveConfig() { | ||
const configJson = env[CONFIG_ENV_VAR_NAME]; | ||
fs.writeFileSync(configFilePath, configJson); | ||
console.log(`Config file written to '${configFilePath}'`); | ||
} | ||
|
||
function initialize() { | ||
console.log(`Initializing app version '${version}' in '${nodeEnv}' mode.`); | ||
initializeConfig(); | ||
} | ||
|
||
initialize(); |