-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate-generator.ts
50 lines (40 loc) · 1.28 KB
/
template-generator.ts
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 mustache = require("mustache");
const fs = require("fs");
const networks = JSON.parse(fs.readFileSync("networks.json", "utf8"));
const selectedNetworkKey = process.argv[2] || "matic"; // matic || base || real
const selectedNetworkConfig = networks[selectedNetworkKey];
if (!selectedNetworkConfig) {
console.error(
`Configuration for network "${selectedNetworkKey}" not found in networks.json`
);
process.exit(1);
}
const templates = {
basic: "templates/basic.yaml.mustache",
real: "templates/real.yaml.mustache",
network: "templates/network.mustache",
};
const getTemplateContent = (templatePath) =>
fs.readFileSync(templatePath, "utf8");
const template = getTemplateContent(
selectedNetworkKey === "real" ? templates.real : templates.basic
);
const networkToDeployTemplate = getTemplateContent(templates.network);
const templateData = {
network: selectedNetworkKey,
address: selectedNetworkConfig.address,
startBlock: selectedNetworkConfig.startBlock,
};
fs.writeFileSync(
"subgraph.yaml",
mustache.render(template, templateData),
"utf8"
);
fs.writeFileSync(
"src/utils/network.ts",
mustache.render(networkToDeployTemplate, { network: selectedNetworkKey }),
"utf8"
);
console.log(
`subgraph.yaml for network ${selectedNetworkKey} created successfully!`
);