From 54faa5c873c52d62a304dcada9e31ff2ee359f72 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Thu, 3 Sep 2020 08:28:57 +0200 Subject: [PATCH] Use config package's multi-directory built-in support This avoids full object overriding when you just want to set specific fields --- config/default.ts | 4 ++-- config/production.ts | 4 ++-- config/test.ts | 4 ++-- package.json | 2 +- src/main.ts | 6 ++++++ tsconfig.json | 3 +-- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/config/default.ts b/config/default.ts index 8f2cf14..aed8601 100644 --- a/config/default.ts +++ b/config/default.ts @@ -1,4 +1,4 @@ -export default Object.assign(require("wms-core/config/default").default, { +export default { app: { name: 'Example App', contact_email: 'contact@example.net' @@ -42,4 +42,4 @@ export default Object.assign(require("wms-core/config/default").default, { cache: false }, approval_mode: false, -}); \ No newline at end of file +} diff --git a/config/production.ts b/config/production.ts index d3ba121..4143867 100644 --- a/config/production.ts +++ b/config/production.ts @@ -1,4 +1,4 @@ -export default Object.assign(require("wms-core/config/production").default, { +export default { log_level: "DEBUG", db_log_level: "ERROR", public_url: "https://watch-my.stream", @@ -12,4 +12,4 @@ export default Object.assign(require("wms-core/config/production").default, { secure: true, allow_invalid_tls: false } -}); \ No newline at end of file +} diff --git a/config/test.ts b/config/test.ts index 149ace2..61f7c4a 100644 --- a/config/test.ts +++ b/config/test.ts @@ -1,4 +1,4 @@ -export default Object.assign(require("wms-core/config/test").default, { +export default { mysql: { host: "localhost", user: "root", @@ -6,4 +6,4 @@ export default Object.assign(require("wms-core/config/test").default, { database: "wms2_test", create_database_automatically: true } -}); \ No newline at end of file +} diff --git a/package.json b/package.json index beda726..312a920 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "test": "jest --verbose --runInBand", "dist-webpack": "webpack --mode production", - "dist": "tsc && npm run dist-webpack", + "dist": "(test ! -d dist || rm -r dist) && tsc && npm run dist-webpack && mkdir -p dist/core-config && cp -r node_modules/wms-core/config/* dist/core-config/", "dev": "concurrently -k -n \"Typescript,Node,Webpack,Maildev\" -p \"[{name}]\" -c \"blue,green,red,yellow\" \"tsc --watch\" \"nodemon\" \"webpack --watch --mode development\" \"maildev\"", "start": "yarn dist && node dist/main.js" }, diff --git a/src/main.ts b/src/main.ts index 1706351..17025eb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,3 +1,9 @@ +// Load config from specified path or default + wms-core/config (default defaults) +process.env['NODE_CONFIG_DIR'] = + (process.env['NODE_CONFIG_DIR'] || './config/') + + require('path').delimiter + + __dirname + '/core-config/'; + import Logger from "wms-core/Logger"; import App from "./App"; import config from "config"; diff --git a/tsconfig.json b/tsconfig.json index a6bf63a..803227e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,6 @@ ] }, "include": [ - "src/**/*", - "node_modules/wms-core" + "src/**/*" ] } \ No newline at end of file