-
Notifications
You must be signed in to change notification settings - Fork 8
/
templatify.ts
67 lines (59 loc) · 1.93 KB
/
templatify.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import * as yaml from 'js-yaml';
import * as Handlebars from 'handlebars';
import * as fs from 'fs-extra';
import * as path from 'path';
const config = {
templatedFiles: [
'activity-subgraph/subgraph.yaml',
'polymarket-subgraph/subgraph.yaml',
'pnl-subgraph/subgraph.yaml',
'oi-subgraph/subgraph.yaml',
'common/constants.ts',
],
};
Handlebars.registerHelper('lowercase', function (str) {
if (str && typeof str == 'string') {
return str.toLowerCase();
}
return '';
});
// function getNetworkNameForSubgraph(): string | null {
// switch (process.env.SUBGRAPH) {
// case 'tomafrench/polymarket':
// return 'mainnet';
// case 'TokenUnion/polymarket':
// return 'mainnet';
// case 'TokenUnion/polymarket-matic':
// return 'matic';
// case 'TokenUnion/polymarket-mumbai':
// return 'mumbai';
// default:
// return null;
// }
// }
(async (): Promise<void> => {
console.log('Starting...');
const networksFilePath = path.join(__dirname, 'networks.yaml');
const networks: any = yaml.load(
await fs.readFile(networksFilePath, { encoding: 'utf-8' }),
);
const networkName = process.argv[2];
console.log(`Network: ${networkName}`);
const network = { ...networks[networkName || ''], networkName };
if (!networkName) {
throw new Error(
'Please set either a "NETWORK_NAME" or a "SUBGRAPH" environment variable',
);
}
// eslint-disable-next-line no-restricted-syntax
for (const templatedFile of config.templatedFiles) {
console.log(templatedFile);
const templatedFileDesc = templatedFile.split('.');
const template = fs
.readFileSync(`${templatedFileDesc[0]}.template.${templatedFileDesc[1]}`)
.toString();
const result = Handlebars.compile(template, {})(network);
fs.writeFileSync(`${templatedFileDesc[0]}.${templatedFileDesc[1]}`, result);
}
console.log(`🎉 subgraph successfully generated for ${networkName}\n`);
})();