-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrender-templates.js
38 lines (34 loc) · 1.2 KB
/
render-templates.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
const fs = require('fs-extra');
const mustache = require('mustache');
module.exports = function(callback) {
(async () => {
const networkType = await web3.eth.net.getNetworkType();
const templateData = { network: networkType === 'private' ? 'development' : networkType };
for(const contractName of [
'DCorp',
]) {
const { abi } = fs.readJsonSync(`build/contracts/${contractName}.json`);
fs.outputJsonSync(`abis/${contractName}.json`, abi, { spaces: 2 });
const C = artifacts.require(contractName);
try {
const { address } = C;
templateData[contractName] = {
address,
addressLowerCase: address.toLowerCase(),
startBlock: (
await web3.eth.getTransactionReceipt(C.transactionHash)
).blockNumber,
};
} catch (e) {}
}
for (const templatedFileDesc of [
['subgraph', 'yaml'],
]) {
const template = fs.readFileSync(`${templatedFileDesc[0]}.template.${templatedFileDesc[1]}`).toString();
fs.writeFileSync(
`${templatedFileDesc[0]}.${templatedFileDesc[1]}`,
mustache.render(template, templateData),
);
}
})().then(() => callback(), callback);
};