1 | import * as fs from 'fs'
|
2 | import type { ValuesOf } from '@naturalcycles/js-lib'
|
3 | import 'dotenv/config'
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | export function requireEnvKeys<T extends readonly string[]>(
|
13 | ...keys: T
|
14 | ): { [k in ValuesOf<T>]: string } {
|
15 |
|
16 | return keys.reduce((r, k) => {
|
17 | const v = process.env[k]
|
18 | if (!v) throw new Error(`${k} env variable is required, but missing`)
|
19 | r[k as ValuesOf<T>] = v
|
20 | return r
|
21 | }, {} as { [k in ValuesOf<T>]: string })
|
22 | }
|
23 |
|
24 | export function requireFileToExist(filePath: string): void {
|
25 | if (!fs.existsSync(filePath)) {
|
26 | throw new Error(`Required file should exist: ${filePath}`)
|
27 | }
|
28 | }
|