-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstoreDeploymentData.js
More file actions
35 lines (31 loc) · 899 Bytes
/
Copy pathstoreDeploymentData.js
File metadata and controls
35 lines (31 loc) · 899 Bytes
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
const fs = require('fs');
function storeDeploymentData(
contractName,
contractAddress,
deployer,
deploymentHash,
deploymentFile
) {
const deploymentData = {
[contractName]: {
address: contractAddress,
deployer: deployer,
deploymentHash: deploymentHash,
},
};
if (!fs.existsSync(deploymentFile)) {
fs.closeSync(fs.openSync(deploymentFile, 'w'));
}
const file = fs.readFileSync(deploymentFile);
if (file.length == 0) {
fs.writeFileSync(deploymentFile, JSON.stringify([deploymentData]));
console.log(`Saved deployment data to a new file: ${deploymentFile}`);
} else {
const json = JSON.parse(file.toString());
json.push(deploymentData);
console.log(json);
fs.writeFileSync(deploymentFile, JSON.stringify(json));
console.log(`Deployment data saved to: ${deploymentFile}`);
}
}
module.exports = storeDeploymentData;