1 |
|
2 | var EOL, colors, lstatSync, readFileSync, _ref;
|
3 |
|
4 | _ref = require('fs'), lstatSync = _ref.lstatSync, readFileSync = _ref.readFileSync;
|
5 |
|
6 | EOL = require('os').EOL;
|
7 |
|
8 | colors = require('colors');
|
9 |
|
10 | module.exports.environment = function(altEnv) {
|
11 | var content, envFile, error, ext, key, line, m, stat, value, _i, _len, _ref1, _ref2;
|
12 | ext = altEnv || 'test';
|
13 | envFile = ".env." + ext;
|
14 | try {
|
15 | stat = lstatSync(envFile);
|
16 | } catch (_error) {
|
17 | error = _error;
|
18 | if (error.errno === 34) {
|
19 | console.log('ipso:', ("warning: missing " + envFile).yellow);
|
20 | return;
|
21 | }
|
22 | }
|
23 | content = readFileSync(envFile, 'utf8');
|
24 | _ref1 = content.split(EOL);
|
25 | for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
26 | line = _ref1[_i];
|
27 | if (line === '') {
|
28 | continue;
|
29 | }
|
30 | if (line.match(/^#/)) {
|
31 | console.log('ipso:', ("warning: commented line in " + envFile).yellow);
|
32 | continue;
|
33 | }
|
34 | _ref2 = line.match(/^(.*?)\=(.*)$/), m = _ref2[0], key = _ref2[1], value = _ref2[2];
|
35 | value = value.replace(/^\'/, '');
|
36 | value = value.replace(/\'$/, '');
|
37 | value = value.replace(/\"$/, '');
|
38 | value = value.replace(/^\"/, '');
|
39 | if (key === 'NODE_ENV' && value === 'production') {
|
40 | console.log('ipso:', ("warning: " + envFile + " is PRODUCTION").yellow);
|
41 | }
|
42 | process.env[key] = value;
|
43 | }
|
44 | return console.log('ipso:', ("loaded " + envFile).green);
|
45 | };
|