UNPKG

1.12 kBtext/coffeescriptView Raw
1{lstatSync, readFileSync} = require 'fs'
2{EOL} = require 'os'
3colors = require 'colors'
4
5module.exports.environment = (altEnv) ->
6
7 ext = altEnv || 'test'
8 envFile = ".env.#{ ext }"
9 try stat = lstatSync envFile
10 catch error
11 if error.errno == 34
12 console.log 'ipso:', "warning: missing #{envFile}".yellow
13 return
14
15 content = readFileSync envFile, 'utf8'
16 for line in content.split EOL
17
18 if line is ''
19 #console.log 'ipso:', "warning: empty line in #{envFile}".yellow
20 continue
21
22 if line.match /^#/
23 console.log 'ipso:', "warning: commented line in #{envFile}".yellow
24 continue
25
26 [m,key,value] = line.match /^(.*?)\=(.*)$/
27 value = value.replace /^\'/, ''
28 value = value.replace /\'$/, ''
29 value = value.replace /\"$/, ''
30 value = value.replace /^\"/, ''
31
32 if key is 'NODE_ENV' and value is 'production'
33 console.log 'ipso:', "warning: #{envFile} is PRODUCTION".yellow
34
35 process.env[key] = value
36
37 console.log 'ipso:', "loaded #{envFile}".green
38