-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtemplatify.js
52 lines (46 loc) · 1.49 KB
/
templatify.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const Handlebars = require('handlebars');
const fs = require('fs-extra');
const path = require('path');
const yaml = require('js-yaml');
const { t } = require('typy');
function getNetworkNameForSubgraph() {
switch (process.env.SUBGRAPH) {
case undefined:
case 'tomafrench/notestream':
return 'mainnet';
case 'tomafrench/notestream-goerli':
return 'goerli';
case 'tomafrench/notestream-kovan':
return 'kovan';
case 'tomafrench/notestream-rinkeby':
return 'rinkeby';
case 'tomafrench/notestream-ropsten':
return 'ropsten';
case 'tomafrench/notestream-local':
return 'local';
default:
return null;
}
}
(async () => {
const networksFilePath = path.join(__dirname, 'networks.yaml');
const networks = yaml.load(
await fs.readFile(networksFilePath, { encoding: 'utf-8' }),
);
const networkName = process.env.NETWORK_NAME || getNetworkNameForSubgraph();
const network = t(networks, networkName).safeObject;
if (t(network).isFalsy) {
throw new Error(
'Please set either a "NETWORK_NAME" or a "SUBGRAPH" environment variable',
);
}
const subgraphTemplateFilePath = path.join(
__dirname,
'subgraph.template.yaml',
);
const source = await fs.readFile(subgraphTemplateFilePath, 'utf-8');
const template = Handlebars.compile(source);
const result = template(network);
await fs.writeFile(path.join(__dirname, 'subgraph.yaml'), result);
console.log('🎉 subgraph.yaml successfully generated');
})();