Archived
0
0
Fork 0

chore: added better config parsing

This commit is contained in:
Daryl Ronningen 2021-06-18 03:29:38 -07:00
parent a1eb102850
commit 4abce7160f
Signed by: Daryl Ronningen
GPG key ID: FD23F0C934A5EC6B
9 changed files with 26 additions and 50 deletions

2
.gitignore vendored
View file

@ -673,5 +673,5 @@ DerivedData/
*.rdb
# ---> Project
config.json
config/default.json
!.yarn/releases

View file

@ -1,4 +0,0 @@
{
"token": "",
"loglevel": ""
}

View file

@ -0,0 +1,4 @@
{
"token": "",
"loglevel": "info"
}

3
config/tests.json Normal file
View file

@ -0,0 +1,3 @@
{
"loglevel": "verbose"
}

View file

@ -18,18 +18,18 @@
"compile:dev": "tsc",
"compile:prod": "rollup -c --compact",
"commit": "commit",
"coverage": "nyc yarn run test",
"coverage": "NODE_CONFIG_ENV=tests nyc yarn run test",
"lint": "eslint --format=pretty src/**/*.ts",
"lint:save": "eslint --format=pretty --save src/**/*.ts",
"postinstall": "husky install",
"release:alpha": "standard-version --prelease alpha -s",
"release:beta": "standard-version --prelease beta -s",
"release:full": "standard-version -s",
"run:dev": "node dist/src/index.js --dev",
"run:prod": "node dist/index.js",
"test": "mocha -r ts-node/register -r tsconfig-paths/register tests/**/*.test.ts",
"watch:bot": "nodemon dist/src/index.js --dev",
"watch:rollup": "tsc --watch",
"run:dev": "NODE_CONFIG_ENV=dev node dist/src/index.js",
"run:prod": "NODE_CONFIG_ENV=production node dist/index.js",
"test": "NODE_CONFIG_ENV=tests mocha -r ts-node/register -r tsconfig-paths/register tests/**/*.test.ts",
"watch:bot": "NODE_CONFIG_ENV=dev nodemon dist/src/index.js --dev",
"watch:rollup": "rollup -c --compact --watch",
"watch:tsc": "tsc --watch"
},
"dependencies": {
@ -51,7 +51,6 @@
"terminal-link": "^3.0.0",
"tslib": "^2.3.0",
"utf-8-validate": "^5.0.5",
"yargs": "^17.0.1",
"zlib-sync": "^0.1.7"
},
"devDependencies": {
@ -62,6 +61,7 @@
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-typescript": "^8.2.1",
"@types/chai": "^4.2.18",
"@types/config": "^0.0.38",
"@types/eslint": "^7.2.13",
"@types/figlet": "^1.5.1",
"@types/gradient-string": "^1",
@ -71,7 +71,6 @@
"@types/node": "^15.12.2",
"@types/rimraf": "^3",
"@types/sinon": "^10.0.2",
"@types/yargs": "^17",
"@typescript-eslint/eslint-plugin": "^4.27.0",
"@typescript-eslint/parser": "^4.27.0",
"@typescript-eslint/typescript-estree": "^4.27.0",

View file

@ -19,9 +19,9 @@ require('module-alias/register');
import { Client } from 'discord.js';
import figlet from 'figlet';
import gradient from 'gradient-string';
// import config from 'config';
import { debug, error, info } from '@utils/logger';
import { ELoggingScope } from '@utils/types';
//import { token } from '../config.json';
debug('Starting bot... Please wait!', ELoggingScope.Startup);

View file

@ -15,8 +15,8 @@
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
*/
import chalk from 'chalk';
import config from 'config';
import { DateTime } from 'luxon';
import { loglevel } from '@/config.json';
import type { ELoggingScope } from './types';
@ -29,7 +29,7 @@ let warnLevel = false;
let errorLevel = false;
let fatalLevel = false;
switch (loglevel.toLowerCase()) {
switch ((config.get('loglevel') as string).toLowerCase()) {
case 'verbose':
verboseLevel = true;
debugLevel = true;

View file

@ -80,6 +80,5 @@
},
"include": [
"src/**/*.ts",
"*.json"
]
}

View file

@ -795,6 +795,13 @@ __metadata:
languageName: node
linkType: hard
"@types/config@npm:^0.0.38":
version: 0.0.38
resolution: "@types/config@npm:0.0.38"
checksum: a2f6d0d174cba2b2bcd11e666508e63734d72339b9c8a208ec113521311b30097e6968e47b2c605e1d3251f7e24fa78edbae4041b699577a3522a74c486c8233
languageName: node
linkType: hard
"@types/emscripten@npm:^1.38.0":
version: 1.39.4
resolution: "@types/emscripten@npm:1.39.4"
@ -1010,22 +1017,6 @@ __metadata:
languageName: node
linkType: hard
"@types/yargs-parser@npm:*":
version: 20.2.0
resolution: "@types/yargs-parser@npm:20.2.0"
checksum: 54cf3f8d2c7db47e200e8c96e05b3b33ee554e78d29f3db55f04ca4b86dc6b8ff6b1349f5772268ce2d365cde0a0f4fdd92bf5933c2be2c1ea3f19f0b4599e1f
languageName: node
linkType: hard
"@types/yargs@npm:^17":
version: 17.0.0
resolution: "@types/yargs@npm:17.0.0"
dependencies:
"@types/yargs-parser": "*"
checksum: a9963dd351737a4f03eeda631848e1e0a8d687a8d463c882a5446ca0b420cd78b7b1c87e22e7a48429809281dd9dd1c0bfe8442100d4172919c30c7294f11e8b
languageName: node
linkType: hard
"@typescript-eslint/eslint-plugin@npm:^4.27.0":
version: 4.27.0
resolution: "@typescript-eslint/eslint-plugin@npm:4.27.0"
@ -1541,6 +1532,7 @@ __metadata:
"@rollup/plugin-json": ^4.1.0
"@rollup/plugin-typescript": ^8.2.1
"@types/chai": ^4.2.18
"@types/config": ^0.0.38
"@types/eslint": ^7.2.13
"@types/figlet": ^1.5.1
"@types/gradient-string": ^1
@ -1550,7 +1542,6 @@ __metadata:
"@types/node": ^15.12.2
"@types/rimraf": ^3
"@types/sinon": ^10.0.2
"@types/yargs": ^17
"@typescript-eslint/eslint-plugin": ^4.27.0
"@typescript-eslint/parser": ^4.27.0
"@typescript-eslint/typescript-estree": ^4.27.0
@ -1589,7 +1580,6 @@ __metadata:
typescript: ^4.3.3
typescript-eslint-language-service: ^4.1.4
utf-8-validate: ^5.0.5
yargs: ^17.0.1
zlib-sync: ^0.1.7
languageName: unknown
linkType: soft
@ -8034,21 +8024,6 @@ typescript@^4.3.3:
languageName: node
linkType: hard
"yargs@npm:^17.0.1":
version: 17.0.1
resolution: "yargs@npm:17.0.1"
dependencies:
cliui: ^7.0.2
escalade: ^3.1.1
get-caller-file: ^2.0.5
require-directory: ^2.1.1
string-width: ^4.2.0
y18n: ^5.0.5
yargs-parser: ^20.2.2
checksum: 4ffffa5a82647e5d07840b64bed88c365b901d3d4a4c51745dddb10d177902d85014026d7224aae18c42df9ca3f75a41c5aff556e5342e2f8ffc5177d149cd17
languageName: node
linkType: hard
"yn@npm:3.1.1":
version: 3.1.1
resolution: "yn@npm:3.1.1"