-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRepository.imba
More file actions
47 lines (31 loc) · 1.3 KB
/
Repository.imba
File metadata and controls
47 lines (31 loc) · 1.3 KB
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
44
45
46
47
import dotenv from 'dotenv'
import fs from 'fs'
import isEmpty from '../Support/Helpers/isEmpty'
import isString from '../Support/Helpers/isString'
import path from 'path'
export default class Repository
prop variables\object = {}
def constructor root\string
let env = process.env.BUILD_ENV ? ".{process.env.BUILD_ENV}" : ''
const envPath = path.join root, ".env{env}"
env = fs.existsSync(envPath) ? envPath : path.join(root, '.env')
dotenv.config({
path: env,
quiet: true,
})
delete process.env.BUILD_ENV
self.variables = process.env
def get key\string, default\any = null
if !isString(key) then throw new TypeError 'Expected string.'
let output = self.variables[key]
# if (output !== undefined && output !== null) && output.startsWith('${') && output.endsWith('}')
# output = self.variables[output.slice(2, -1)]
if isString output
const results = output.match(/\$\{(.*?)\}/g)
if !isEmpty(results)
for variable in results
output = output.replace(variable, self.variables[variable.slice(2, -1)])
# results.forEach do(variable)
# output = output.replace(variable, self.variables[variable.slice(2, -1)])
if isEmpty(output) then return default
['true', 'false'].includes(output.toLowerCase!) ? output = JSON.parse(output) : (output === 'null' ? null : output)