-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 💡 .env change to production default env file
BREAKING CHANGE: 🧨 .env change to production default env file, keep docker .env compatible, and follow dotenv recommended @link https://github.com/motdotla/dotenv#should-i-have-multiple-env-files
- Loading branch information
Showing
6 changed files
with
95 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
# PROD **00 | ||
# DEV **07 | ||
|
||
__ENV__=prod | ||
|
||
# PROJECT | ||
SITE_NAME=Leaa | ||
API_URL=http://localhost:5000 | ||
|
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 |
---|---|---|
@@ -1,44 +1,36 @@ | ||
const dotenv = require('dotenv'); | ||
/* eslint-disable no-underscore-dangle */ | ||
|
||
const ip = require('ip'); | ||
const childProcess = require('child_process'); | ||
|
||
const { WPCONST } = require('./_const'); | ||
const { getVersion } = require('../cli/get-build-info'); | ||
|
||
function getEnvInfo() { | ||
const envPath = `${WPCONST.ROOT_DIR}/${WPCONST.__DEV__ ? '.env' : '.env.production'}`; | ||
const env = dotenv.config({ path: envPath }).parsed; | ||
|
||
// DEV, Change API_URL to IP Address | ||
if (WPCONST.__DEV__) env.API_URL = env.API_URL.replace('localhost', ip.address()); | ||
|
||
return env; | ||
} | ||
|
||
const env = getEnvInfo(); | ||
const getGitVersion = (childProcess.execSync('git rev-parse HEAD') || '').toString().substr(0, 4); | ||
const getVersion = `v${process.env.npm_package_version} (${getGitVersion})`; | ||
|
||
function showEnvInfo() { | ||
// emoji for CLI | ||
const serverBaseByText = `${env.SERVER_PROTOCOL}://${ip.address() || env.SERVER_HOST}:${env.SERVER_PORT}`; | ||
const serverBaseByText = `${WPCONST.SERVER_PROTOCOL}://${ip.address() || WPCONST.SERVER_HOST}:${WPCONST.SERVER_PORT}`; | ||
const serverBaseByEmoji = `✨✨ \x1b[00;45;9m${serverBaseByText}\x1b[0m ✨✨`; | ||
const serverEnv = `${env.NODE_ENV !== 'production' ? '🚀' : '🔰'} ${(env.NODE_ENV || 'NOT-ENV').toUpperCase()}`; | ||
const serverEnv = `${WPCONST.__DEV__ ? '🚀' : '🔰'} ${(WPCONST.__ENV__ || 'NOT-ENV').toUpperCase()}`; | ||
|
||
console.log( | ||
`\n\n\n\n> 🌈 DEBUG ${env.DEBUG_MODE === 'true' ? '✅' : '➖'} / DEMO ${env.DEMO_MODE === 'true' ? '✅' : '➖'}`, | ||
`\n\n\n\n> 🌈 DEBUG ${WPCONST.DEBUG_MODE === 'true' ? '✅' : '⛔️'} / DEMO ${ | ||
WPCONST.DEMO_MODE === 'true' ? '✅' : '⛔' | ||
} / ${WPCONST.__ENV__} / ${WPCONST.ENV_FILE_NAME}`, | ||
); | ||
|
||
console.log(`\n\n> ${serverEnv} / URL ${serverBaseByEmoji}`); | ||
console.log(`\n> ${serverEnv} / URL ${serverBaseByEmoji}`); | ||
|
||
console.log('\n> 📮 ENVDATA'); | ||
console.log(' - NAME ', `${env.SITE_NAME}`); | ||
console.log(' - VERSION ', getVersion); | ||
console.log(''); | ||
console.log(' - API_URL ', `${env.API_URL}`); | ||
console.log('\n> 📮 ENVINFO'); | ||
console.log(' - NAME ', `${WPCONST.SITE_NAME} ${getVersion}`); | ||
console.log(' - API ', `${WPCONST.API_URL}`); | ||
console.log(''); | ||
console.log(' - DEV_PREFIX ', `${WPCONST.DEV_PREFIX}`); | ||
console.log(' - CHUNK_HASH ', `${WPCONST.CHUNK_HASH}`); | ||
console.log(' - PUBLIC_DIR ', `${WPCONST.PUBLIC_DIR}`); | ||
console.log(' - BUILD_DIR ', `${WPCONST.BUILD_DIR}`); | ||
console.log(' - PREFIX ', `${WPCONST.DEV_PREFIX}`); | ||
console.log(' - CHUNK ', `${WPCONST.CHUNK_HASH}`); | ||
console.log(' - PUBLIC_DIR ', `${WPCONST.PUBLIC_DIR}`); | ||
console.log(' - BUILD_DIR ', `${WPCONST.BUILD_DIR}`); | ||
console.log('\n\n\n'); | ||
} | ||
|
||
module.exports = { showEnvInfo, getVersion, getEnvInfo }; | ||
module.exports = { showEnvInfo, getVersion }; |
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