-
Notifications
You must be signed in to change notification settings - Fork 9
/
config.js
40 lines (29 loc) · 1.15 KB
/
config.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
const fs = require('fs');
const testConfig = { test: {} };
exports.read = () => Object.keys(testConfig.test).length > 0 ? testConfig : JSON.parse(fs.readFileSync('config.json').toString());
exports.write = (newConfig) => {
const oldConfig = this.read();
fs.writeFileSync('config.json', JSON.stringify({ ...oldConfig, ...newConfig }, null, 2));
};
exports.deploy = async (name, network, act) => {
const oldConfig = this.read();
if (!oldConfig[network]) {
oldConfig[network] = {};
}
if (!oldConfig[network][name]) {
oldConfig[network][name] = {};
}
if (network === 'test') {
testConfig.test[name] = {};
await act(testConfig.test[name]);
return testConfig;
}
if (!oldConfig[network][name].deployed || network === "rskRegtest") {
await act(oldConfig[network][name]);
oldConfig[network][name].deployed = true;
this.write(oldConfig)
} else {
console.warn(`${name} has already be deployed [address: ${oldConfig[network][name].address}]. If you want to deploy it, please set deployed attribute to false on config.json file.`)
}
return this.read();
}