forked from vekexasia/dpos-tools-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildArtifacts.ts
39 lines (35 loc) · 1.59 KB
/
buildArtifacts.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
import * as jsYaml from 'js-yaml';
import * as fs from 'fs';
const writeData = (baseDir: string, coin: string, key: string, content: any) => {
if (typeof(content) === 'undefined' || content === null) {
return;
}
fs.writeFileSync(`${baseDir}/${key}.json`, JSON.stringify(content, null, 2));
fs.writeFileSync(`${baseDir}/${key}.min.json`, JSON.stringify(content));
fs.writeFileSync(`${baseDir}/${key}.js`, `__${coin}_${key}(${JSON.stringify(content, null, 2)});`);
fs.writeFileSync(`${baseDir}/${key}.min.js`, `__${coin}_${key}(${JSON.stringify(content)});`);
}
fs.readdirSync(__dirname)
.filter((item) => /.yml$/.test(item))
.filter((item) => item !== '.travis.yml')
.forEach((ymlFile) => {
const content: string = fs.readFileSync(`${__dirname}/${ymlFile}`, 'utf8') as string;
const [coin] = ymlFile.split('.');
const allContent:any = jsYaml.load(content);
const baseDir = `${__dirname}/artifacts/${coin}`;
console.log(`Generating infos for ${ymlFile} - ${coin}`);
fs.mkdirSync(baseDir);
writeData(baseDir, coin, 'indexedReqs', allContent.indexedRequirements);
writeData(baseDir, coin, 'groups', allContent.groups);
writeData(baseDir, coin, 'pools', allContent.pools);
writeData(baseDir, coin, 'allInfos', allContent);
writeData(baseDir, coin, 'coinData', {
node: allContent.node,
epoch: allContent.epoch,
numForgers: allContent.numForgers,
maxVotes: allContent.maxVotes,
blockExplorer: allContent.blockExplorer,
blockTime: allContent.blockTime,
addressRegex: allContent.addressRegex,
});
});