-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
recreateFiles.js
86 lines (81 loc) · 2.66 KB
/
recreateFiles.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
76
77
78
79
80
81
82
83
84
85
86
const fs = require('fs');
const web3 = require('web3');
const utils = web3.utils;
const contractsDirectory = './src/contracts';
const tokensDirectory = './src/tokens';
const iconsDirectory = './src/icons';
function recreateContractFiles() {
fs.readdirSync(contractsDirectory).forEach(folderFile => {
fs.readdirSync(`${contractsDirectory}/${folderFile}`).forEach(file => {
const newFile = JSON.parse(
fs.readFileSync(`${contractsDirectory}/${folderFile}/${file}`)
);
const currentAddress = newFile.address;
newFile.address = utils.toChecksumAddress(currentAddress);
fs.unlinkSync(`${contractsDirectory}/${folderFile}/${file}`);
fs.writeFileSync(
`${contractsDirectory}/${folderFile}/${utils.toChecksumAddress(
file.replace('.json', '')
)}.json`,
JSON.stringify(newFile)
);
});
});
}
function recreateTokenFiles() {
fs.readdirSync(tokensDirectory).forEach(folderFile => {
fs.readdirSync(`${tokensDirectory}/${folderFile}`).forEach(file => {
const newFile = JSON.parse(
fs.readFileSync(`${tokensDirectory}/${folderFile}/${file}`)
);
const currentAddress = newFile.address;
newFile.address = utils.toChecksumAddress(currentAddress);
fs.unlinkSync(`${tokensDirectory}/${folderFile}/${file}`);
fs.writeFileSync(
`${tokensDirectory}/${folderFile}/${utils.toChecksumAddress(
file.replace('.json', '')
)}.json`,
JSON.stringify(newFile)
);
});
});
}
function recreateIconFiles() {
const date = new Date();
const dateT = date.getTime();
fs.readdirSync(iconsDirectory).forEach(imgFile => {
const findAddressStart = imgFile.indexOf('-0x');
const foundAddress =
findAddressStart !== -1
? imgFile.substr(findAddressStart + 1, imgFile.length)
: null;
const address = foundAddress
? foundAddress.replace(/(?<name>.png|.svg)/g, '')
: imgFile;
const extension = imgFile.substring(imgFile.length - 4, imgFile.length);
try {
if (utils.isAddress(address) && foundAddress) {
const checksumAddress = utils.toChecksumAddress(address);
const newName = `${imgFile.substring(
0,
findAddressStart
)}-${dateT}-${checksumAddress}${extension}`;
fs.rename(
`${tokensDirectory}/${imgFile}`,
`${tokensDirectory}/${newName}`,
function(err) {
if (err) console.log('ERROR: ', err);
}
);
}
} catch (e) {
console.log(e);
}
});
}
function recreateFiles() {
recreateContractFiles();
recreateTokenFiles();
}
module.exports = recreateFiles;
// recreateIconFiles();