forked from trustwallet/tokens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (37 loc) · 1.13 KB
/
index.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
const fs = require('fs')
const pngExp = /\.png$/
const upperCaseExp = /[A-F]/
const OxExp = /^0x/
const addressExp = /[0-9a-f]{40}$/i
const exitWithMsg = msg => {
console.log(msg)
process.exit(1)
}
const isAddress = address => addressExp.test(address)
const isFilePng = name => pngExp.test(name)
const remotePngExtension = string => string.replace(/.png$/, '')
const tokens = fs.readdirSync('./tokens')
tokens.forEach(token => {
const address = remotePngExtension(token)
if (!isFilePng(token)) {
exitWithMsg(`${token} image must be png`)
}
if (upperCaseExp.test(address)) {
exitWithMsg(`${address} image must be in lowercase`)
}
if (!OxExp.test(address)) {
exitWithMsg(`'${address}' must start with 0x`)
}
if (!isAddress(address)) {
exitWithMsg(`${address} image must have length 42 instead have ${address.length}`)
}
})
const checkRootDirectory = () => {
fs.readdirSync(".").forEach(file => {
if(isFilePng(file)) {
exitWithMsg(`Move ${file} to ./tokens folder`)
}
})
}
checkRootDirectory()
console.log(`Passed all tests`)