Skip to content

Commit 1d4b9f1

Browse files
author
Dmitri Farkov
committed
Revamp default config / schema
1 parent bba46dd commit 1d4b9f1

6 files changed

+116
-24
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
dist
22
node_modules
3-
config.yml
3+
config.dev.yml

default-config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ log: debug
22
api:
33
templates:
44
mqtt:
5+
port: 1883
56
onvif:

package-lock.json

+103-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"eslint-plugin-import": "2.20.1",
2121
"i": "0.3.6",
2222
"lodash.at": "4.6.0",
23+
"merge-deep": "3.0.2",
2324
"nodemon": "2.0.2",
2425
"npm": "6.14.4",
2526
"onvif": "0.6.2",

src/Config.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import fs, { exists } from 'fs';
44
import yaml from 'yaml';
55
import process from 'process';
66
import validator from './ConfigValidator';
7+
import merge from 'merge-deep';
78
import logger, { setLoggingLevel } from './Logger';
89

910
const DEFAULT_CONFIG_PATH = path.resolve(__dirname, '../default-config.yml');
@@ -67,13 +68,12 @@ class Config {
6768
const defaultConfig = this._loadDefaultConfig();
6869
const userConfig = this._loadUserConfig();
6970

70-
const mergedConfig = {
71-
...defaultConfig,
72-
...userConfig
73-
};
71+
const mergedConfig = merge(
72+
defaultConfig,
73+
userConfig
74+
);
7475

7576
this._validate(mergedConfig);
76-
7777
return mergedConfig;
7878
};
7979

src/ConfigValidator.js

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ const configSchema = new Schema({
2828
host: {
2929
required: true,
3030
},
31+
port: {
32+
required: true,
33+
},
34+
username: String,
35+
password: String,
3136
},
3237
onvif: {
3338
type: Array,

0 commit comments

Comments
 (0)