mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 00:38:43 +00:00
refactor: change .env to be dotenv (#1341)
This commit is contained in:
@@ -27,7 +27,7 @@ assignees: jef
|
|||||||
## Environment
|
## Environment
|
||||||
|
|
||||||
**OS:**
|
**OS:**
|
||||||
**.env file:**
|
**dotenv file:**
|
||||||
|
|
||||||
```dotenv
|
```dotenv
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -4,9 +4,8 @@
|
|||||||
build/
|
build/
|
||||||
node_modules/
|
node_modules/
|
||||||
|
|
||||||
.env*
|
.env
|
||||||
.*env
|
dotenv
|
||||||
!.env-example
|
|
||||||
success-*.png
|
success-*.png
|
||||||
|
|
||||||
*.wav
|
*.wav
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ You do not need any computer skills, smarts, or anything of that nature. You are
|
|||||||
- To checkout a particular reference, use `git checkout <ref name>` after cloning.
|
- To checkout a particular reference, use `git checkout <ref name>` after cloning.
|
||||||
- Navigate to this project by entering `cd streetmerchant`.
|
- Navigate to this project by entering `cd streetmerchant`.
|
||||||
- Run `npm install`.
|
- Run `npm install`.
|
||||||
- Make a copy of `.env-example` and name it `.env`.
|
- Make a copy of `dotenv-example` and name it `dotenv`.
|
||||||
- Edit the `.env` file to your liking using a text editor (like [vscode](https://code.visualstudio.com/)).
|
- Edit the `dotenv` file to your liking using a text editor (like [vscode](https://code.visualstudio.com/)).
|
||||||
- Run `npm run start` to start.
|
- Run `npm run start` to start.
|
||||||
|
|
||||||
At any point you want the program to stop, use ++ctrl+c++.
|
At any point you want the program to stop, use ++ctrl+c++.
|
||||||
@@ -40,22 +40,22 @@ Available via GitHub Container Registry.
|
|||||||
```sh
|
```sh
|
||||||
# to run docker nightly
|
# to run docker nightly
|
||||||
docker run --cap-add=SYS_ADMIN \
|
docker run --cap-add=SYS_ADMIN \
|
||||||
-it --rm --env-file ./.env \
|
-it --rm --env-file ./dotenv \
|
||||||
ghcr.io/jef/streetmerchant:nightly
|
ghcr.io/jef/streetmerchant:nightly
|
||||||
|
|
||||||
# to test notifications
|
# to test notifications
|
||||||
docker run --cap-add=SYS_ADMIN \
|
docker run --cap-add=SYS_ADMIN \
|
||||||
-it --rm --env-file ./.env \
|
-it --rm --env-file ./dotenv \
|
||||||
ghcr.io/jef/streetmerchant:nightly test:notification:production
|
ghcr.io/jef/streetmerchant:nightly test:notification:production
|
||||||
```
|
```
|
||||||
|
|
||||||
## Customization
|
## Customization
|
||||||
|
|
||||||
To customize streetmerchant, make a copy of `.env-example` as `.env` and make any changes to your liking. View [Reference](reference/application.md) for more information on variables and their usage.
|
To customize streetmerchant, make a copy of `dotenv-example` as `dotenv` and make any changes to your liking. View [Reference](reference/application.md) for more information on variables and their usage.
|
||||||
|
|
||||||
???+ tip
|
???+ tip
|
||||||
All environment variables are optional.
|
All environment variables are optional.
|
||||||
|
|
||||||
## For developers
|
## For developers
|
||||||
|
|
||||||
The command `npm run start:dev` can be used instead of `npm run start` to automatically restart the project when filesystem changes are detected in the `src/` folder or `.env` file.
|
The command `npm run start:dev` can be used instead of `npm run start` to automatically restart the project when filesystem changes are detected in the `src/` folder or `dotenv` file.
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ As a last case scenario, use `PUPPETEER_EXECUTABLE_PATH`. This will use your com
|
|||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
`.env`:
|
`dotenv`:
|
||||||
|
|
||||||
```
|
```
|
||||||
PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome-stable
|
PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome-stable
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# ** All configuration variables are optional **
|
# ** All configuration variables are optional **
|
||||||
# Read https://github.com/jef/streetmerchant#customization for help on customizing this file
|
# Copy this file and name it as `dotenv` (without backticks)
|
||||||
#############################################################################################
|
# Read https://jef.codes/streetmerchant/getting-started/#customization for help on customizing this file
|
||||||
|
########################################################################################################
|
||||||
|
|
||||||
ASCII_BANNER=""
|
ASCII_BANNER=""
|
||||||
ASCII_COLOR=""
|
ASCII_COLOR=""
|
||||||
+1
-1
@@ -3,6 +3,6 @@
|
|||||||
"ext": "ts",
|
"ext": "ts",
|
||||||
"watch": [
|
"watch": [
|
||||||
"src/",
|
"src/",
|
||||||
".env"
|
"dotenv"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-6
@@ -1,10 +1,14 @@
|
|||||||
import {banner} from './banner';
|
import {banner} from './banner';
|
||||||
|
|
||||||
import {config as config_} from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {readFileSync} from 'fs';
|
import {readFileSync} from 'fs';
|
||||||
|
|
||||||
config_({path: path.resolve(__dirname, '../.env')});
|
if (path.resolve(__dirname, '../dotenv').length > 0) {
|
||||||
|
dotenv.config({path: path.resolve(__dirname, '../dotenv')});
|
||||||
|
} else {
|
||||||
|
dotenv.config({path: path.resolve(__dirname, '../.env')});
|
||||||
|
}
|
||||||
|
|
||||||
console.info(
|
console.info(
|
||||||
banner.render(
|
banner.render(
|
||||||
@@ -66,8 +70,8 @@ function envOrNumber(environment: string | undefined, number?: number): number {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns environment variable, given number, or default number,
|
* Returns environment variable, given number, or default number,
|
||||||
* while handling .env input errors for a Min/Max pair.
|
* while handling dotenv input errors for a Min/Max pair.
|
||||||
* .env errors handled:
|
* dotenv errors handled:
|
||||||
* - Min/Max swapped (Min larger than Max, Max smaller than Min)
|
* - Min/Max swapped (Min larger than Max, Max smaller than Min)
|
||||||
* - Min larger than default Max when no Max defined
|
* - Min larger than default Max when no Max defined
|
||||||
* - Max smaller than default Min when no Min defined
|
* - Max smaller than default Min when no Min defined
|
||||||
@@ -106,8 +110,8 @@ function envOrNumberMin(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns environment variable, given number, or default number,
|
* Returns environment variable, given number, or default number,
|
||||||
* while handling .env input errors for a Min/Max pair.
|
* while handling dotenv input errors for a Min/Max pair.
|
||||||
* .env errors handled:
|
* dotenv errors handled:
|
||||||
* - Min/Max swapped (Min larger than Max, Max smaller than Min)
|
* - Min/Max swapped (Min larger than Max, Max smaller than Min)
|
||||||
* - Min larger than default Max when no Max defined
|
* - Min larger than default Max when no Max defined
|
||||||
* - Max smaller than default Min when no Min defined
|
* - Max smaller than default Min when no Min defined
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
import {startAPIServer, stopAPIServer} from './web';
|
import {config} from './config'; // Needs to be loaded first
|
||||||
|
import {startAPIServer, stopAPIServer} from './web'; // eslint-disable-line sort-imports
|
||||||
import {Browser} from 'puppeteer';
|
import {Browser} from 'puppeteer';
|
||||||
import {config} from './config';
|
|
||||||
import {getSleepTime} from './util';
|
import {getSleepTime} from './util';
|
||||||
import {logger} from './logger';
|
import {logger} from './logger';
|
||||||
import puppeteer from 'puppeteer-extra';
|
import puppeteer from 'puppeteer-extra';
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ function generateTopic(link: Link, store: Store, topic: string): string {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic protection against sending credentials in the clear over public networks.
|
* Basic protection against sending credentials in the clear over public networks.
|
||||||
* - Returns 'true' if password is supplied in .env but address/URL is not part of a private network
|
* - Returns 'true' if password is supplied in dotenv but address/URL is not part of a private network
|
||||||
* - Private networks evaluated: Class A, B, or C private IP's or linklocal URL ("*.local")
|
* - Private networks evaluated: Class A, B, or C private IP's or linklocal URL ("*.local")
|
||||||
* - TLS could be implemented, however, the majority of MQTT services on the internet do not require user authentication.
|
* - TLS could be implemented, however, the majority of MQTT services on the internet do not require user authentication.
|
||||||
* - If you find a 'cloud' MQTT broker requiring authentication for publishing alerts, consider using another MQTT service (for now).
|
* - If you find a 'cloud' MQTT broker requiring authentication for publishing alerts, consider using another MQTT service (for now).
|
||||||
|
|||||||
Reference in New Issue
Block a user