-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.ts
43 lines (37 loc) · 1.37 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* eslint-disable @typescript-eslint/no-var-requires */
import { ISingleHostConfig } from 'influx'
import { CloudOptions } from 'meross-cloud-ts'
export type APP_ENV = 'development' | 'production' | 'test'
export type DB_CHOICE = 'influx'
const ENV = process.env.NODE_ENV === 'production' ? 'production' : (process.env.NODE_ENV ?? 'development') as APP_ENV
// use of file .env.environment file **only** outside production
if (ENV !== 'production') require('dotenv').config({ path: `.env.${ENV}` })
export function isEmpty (value: any): boolean {
if (value === undefined) return true
if (value === null) return true
if (typeof value === 'string' && value === '') return true
return false
}
const influxConfig: ISingleHostConfig = {}
;[
{ env: 'INFLUX_USERNAME', key: 'username' },
{ env: 'INFLUX_PASSWORD', key: 'password' },
{ env: 'INFLUX_HOST', key: 'host' },
{ env: 'INFLUX_PORT', key: 'port' },
{ env: 'INFLUX_PROTOCOL', key: 'protocol' },
{ env: 'INFLUX_DATABASE', key: 'database' },
].forEach(({ env, key }) => {
if (!isEmpty(process.env[env])) influxConfig[key] = process.env[env]
})
const merossConfig: CloudOptions = {
email: process.env.MEROSS_EMAIL!,
password: process.env.MEROSS_PASSWORD!,
}
export default {
merossConfig,
whichDb: 'influx' as DB_CHOICE,
influxConfig,
influxOptions: {
measurement: process.env.INFLUX_MEASUREMENT ?? 'meross',
},
}