From 6a7594fa320fc4ef3d97fda71c658eeefc4c842a Mon Sep 17 00:00:00 2001 From: Ralf Vogler Date: Mon, 9 Jan 2023 10:56:18 +0100 Subject: [PATCH] use dotenv for loading env vars from data/config.env --- README.md | 6 ++++-- config.js | 11 ++++++----- package-lock.json | 14 ++++++++++++++ package.json | 1 + 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f6e78f1..49d06ac 100644 --- a/README.md +++ b/README.md @@ -46,9 +46,9 @@ After login, the script will just continue claiming the current games. If it sti ### Options Options are set via [environment variables](https://kinsta.com/knowledgebase/what-is-an-environment-variable/) which can be set in many ways and allow for flexible configuration. -TODO: On the first run, the script will guide you through configuration and save all settings to a `.env` file. You can edit this file directly or run `node fgc config` to run the configuration assistant again. +TODO: On the first run, the script will guide you through configuration and save all settings to `data/config.env`. You can edit this file directly or run `node fgc config` to run the configuration assistant again. -The available options/variables and their default values are: +Available options/variables and their default values: | Option | Default | Description | |--------------- |--------- |------------------------------------------------------------------------ | @@ -65,6 +65,8 @@ The available options/variables and their default values are: | GOG_EMAIL | | GOG email for login. Overrides EMAIL. | | GOG_PASSWORD | | GOG password for login. Overrides PASSWORD. | +See `config.js` for all options. + #### Other ways to set options On Linux/macOS you can prefix the variables you want to set, for example `EMAIL=foo@bar.baz SHOW=1 node epic-games` will show the browser and skip asking you for your login email. For Docker you can pass variables using `-e VAR=VAL`, for example `docker run -e EMAIL=foo@bar.baz ...` or using `--env-file` (see [docs](https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file)). If you are using [docker compose](https://docs.docker.com/compose/environment-variables/), you can put them in the `environment:` section. diff --git a/config.js b/config.js index 51e4dcb..e0873b5 100644 --- a/config.js +++ b/config.js @@ -1,15 +1,16 @@ -// import * as dotenv from 'dotenv'; -// dotenv.config({ path: 'data/config.env' }); +import * as dotenv from 'dotenv'; +dotenv.config({ path: 'data/config.env' }); // loads env vars from file - will not set vars that are already set, i.e., can overwrite values from file by prefixing, e.g., VAR=VAL node ... +// Options - also see table in README.md export const cfg = { debug: process.env.PWDEBUG == '1', // runs non-headless and opens https://playwright.dev/docs/inspector dryrun: process.env.DRYRUN == '1', // don't claim anything show: process.env.SHOW == '1', // run non-headless get headless() { return !this.debug && !this.show }, - width: Number(process.env.WIDTH) || 1280, - height: Number(process.env.HEIGHT) || 1280, + width: Number(process.env.WIDTH) || 1280, // width of the opened browser + height: Number(process.env.HEIGHT) || 1280, // height of the opened browser timeout: (Number(process.env.TIMEOUT) || 20) * 1000, // 20s, default for playwright is 30s - novnc_port: process.env.NOVNC_PORT, + novnc_port: process.env.NOVNC_PORT, // running in docker if set eg_email: process.env.EG_EMAIL || process.env.EMAIL, eg_password: process.env.EG_PASSWORD || process.env.PASSWORD, pg_email: process.env.PG_EMAIL || process.env.EMAIL, diff --git a/package-lock.json b/package-lock.json index cd6b762..5f5954b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "cross-env": "^7.0.3", + "dotenv": "^16.0.3", "lowdb": "^5.0.5", "playwright": "^1.29.0", "prompts": "^2.4.2", @@ -125,6 +126,14 @@ "node": ">=0.10.0" } }, + "node_modules/dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", + "engines": { + "node": ">=12" + } + }, "node_modules/for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", @@ -693,6 +702,11 @@ "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz", "integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==" }, + "dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==" + }, "for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", diff --git a/package.json b/package.json index e2d288b..7720bf5 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "type": "module", "dependencies": { "cross-env": "^7.0.3", + "dotenv": "^16.0.3", "lowdb": "^5.0.5", "playwright": "^1.29.0", "prompts": "^2.4.2",