forked from alkem-io/client-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
50 lines (39 loc) · 1.47 KB
/
gulpfile.js
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
48
49
50
const dotenvFlow = require('dotenv-flow');
const dotenvExpand = require('dotenv-expand');
fs = require('fs');
path = require('path');
const CONFIG_TEXT = `window._env_ = `;
const CONFIG_FILE_NAME = 'env-config.js';
function buildConfiguration(cb) {
const initialConfig = dotenvFlow.config({
silent: true
});
dotenvExpand(initialConfig);
const env = process.env;
let configuration = {};
const nodeEnv = env.NODE_ENV ? env.NODE_ENV : 'development';
console.info(`Building for : '${nodeEnv}'`);
Object.keys(env).forEach(function (key) {
if (key.startsWith('REACT_APP')) {
configuration[key] = env[key];
console.info(`${key}: ${env[key]}`);
}
});
configuration['REACT_APP_GRAPHQL_ENDPOINT'] =
configuration['REACT_APP_GRAPHQL_ENDPOINT'] ||
(nodeEnv === 'production' ? '/graphql' : 'http://localhost:4000/graphql');
const envBasePath = path.join(__dirname, '.env.deployment', '.env.base');
let envBase = fs.createWriteStream(envBasePath, { flags: 'w' });
Object.keys(configuration).forEach(k => {
envBase.write(`${k}=${configuration[k]}\n`);
});
envBase.end();
console.info(`Write in: ${envBasePath}`);
const envConfigPath = path.join(__dirname, '/public', CONFIG_FILE_NAME);
fs.writeFile(envConfigPath, `${CONFIG_TEXT}${JSON.stringify(configuration, null, 2)}`, () => {
console.info(`Write in: ${envConfigPath}`);
cb();
});
}
exports.buildConfiguration = buildConfiguration;
exports.default = buildConfiguration;