-
Notifications
You must be signed in to change notification settings - Fork 1
/
createFiles.js
75 lines (68 loc) · 2.07 KB
/
createFiles.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const fs = require("fs");
const contractsDirectory = "./src/contracts/";
const tokensDirectory = "./src/tokens/";
function createContractFiles() {
if (!fs.existsSync("./dist/contracts")) {
fs.mkdirSync("./dist/contracts");
}
fs.readdirSync(contractsDirectory).forEach(folder => {
let newArr = [];
if (!fs.existsSync(`./dist/contracts/${folder}`)) {
fs.mkdirSync(`./dist/contracts/${folder}`);
}
fs.readdirSync(`${contractsDirectory}/${folder}`).forEach(file => {
const obj = JSON.parse(
fs.readFileSync(`${contractsDirectory}/${folder}/${file}`, "utf8")
);
newArr.push(obj);
});
const writeArray = newArr.sort(function(a, b) {
let aSym = a.name.toLowerCase();
let bSym = b.name.toLowerCase();
return aSym < bSym ? -1 : aSym > bSym ? 1 : 0;
});
fs.writeFileSync(
`./dist/contracts/${folder}/contract-abi-${folder}.min.json`,
JSON.stringify(writeArray)
);
fs.writeFileSync(
`./dist/contracts/${folder}/contract-abi-${folder}.json`,
JSON.stringify(writeArray)
);
});
}
function createTokenFiles() {
if (!fs.existsSync("./dist/tokens")) {
fs.mkdirSync("./dist/tokens");
}
fs.readdirSync(tokensDirectory).forEach(folder => {
let newArr = [];
if (!fs.existsSync(`./dist/tokens/${folder}`)) {
fs.mkdirSync(`./dist/tokens/${folder}`);
}
fs.readdirSync(`${tokensDirectory}/${folder}`).forEach(file => {
const obj = JSON.parse(
fs.readFileSync(`${tokensDirectory}/${folder}/${file}`, "utf8")
);
newArr.push(obj);
});
const writeArray = newArr.sort(function(a, b) {
let aSym = a.symbol.toLowerCase();
let bSym = b.symbol.toLowerCase();
return aSym < bSym ? -1 : aSym > bSym ? 1 : 0;
});
fs.writeFileSync(
`./dist/tokens/${folder}/tokens-${folder}.min.json`,
JSON.stringify(writeArray)
);
fs.writeFileSync(
`./dist/tokens/${folder}/tokens-${folder}.json`,
JSON.stringify(writeArray)
);
});
}
function run() {
createContractFiles();
createTokenFiles();
}
run();