-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.js
36 lines (30 loc) · 868 Bytes
/
build.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
const fs = require('fs')
function loadMetadata(folder) {
let pools = []
fs.readdirSync(folder).forEach(function(file) {
if (file.match(/\.json$/) !== null) {
let data = require(folder + file)
if (Array.isArray(data)) pools = [...pools, ...data]
else pools.push(data)
}
})
return pools
}
const poolMetadata = __dirname + '/metadata/'
const pools = loadMetadata(poolMetadata)
const poolModule = "module.exports = "+JSON.stringify(pools)
fs.writeFile(__dirname + '/out/index.js', poolModule, (err) => {
if (err) {
throw err
}
})
const poolList = JSON.stringify(pools.reduce((l, p) => {
if (p.addresses) l[p.addresses['ROOT_CONTRACT']] = p
if (!p.addresses) l[p.metadata.slug] = p
return l
},{}))
fs.writeFile(__dirname + '/out/pools.json', poolList, (err) => {
if (err) {
throw err
}
})