-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
49 lines (43 loc) · 1.23 KB
/
deploy.js
File metadata and controls
49 lines (43 loc) · 1.23 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
48
49
'use strict';
const fsReadFilePromise = require(`fs-readfile-promise`)
, fs = require(`fs`)
, configPath = `./config.json`
, encoding = `utf8`
;
if (false === fs.existsSync(configPath)) {
fs.writeFileSync(configPath, JSON.stringify({}));
}
Promise.all([
fsReadFilePromise(`./config.json.dist`, encoding)
, fsReadFilePromise(configPath, encoding)
]).then(values => {
let distConfig = JSON.parse(values[0])
, config = JSON.parse(values[1])
, wasChanged = false
;
for (let parameterName in distConfig) {
if (false === (parameterName in config)) {
config[parameterName] = distConfig[parameterName] in process.env
? process.env[distConfig[parameterName]]
: distConfig[parameterName]
;
wasChanged = true;
}
}
if (false === wasChanged) {
console.info(`Config Deploy: No new parameters added - skipped.`);
return;
}
fs.writeFile(
configPath,
JSON.stringify(config),
encoding,
function (err) {
if (err) {
console.error(err);
} else {
console.info(`Config Deploy: deployed.`)
}
}
);
});