forked from dragonswap-app/assets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
precommit.ts
44 lines (37 loc) · 1.18 KB
/
precommit.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
39
40
41
42
43
44
import * as fs from "fs";
import * as path from "path";
import { fileURLToPath } from "url";
import { isAddress, getAddress } from "viem";
import { tokensSchema } from "./tokensSchema.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const logosDir = path.join(__dirname, "../logos");
const tokenList = JSON.parse(
fs.readFileSync(path.join(__dirname, "../tokenlist-sei-mainnet.json"), "utf8")
);
const val = tokensSchema.safeParse(tokenList);
if (!val.success) {
throw new Error(`Invalid tokens.json: ${val.error.message}`);
}
fs.readdir(logosDir, (err, files) => {
if (err) {
throw new Error(`Error reading directory: ${err}`);
}
files.forEach((file) => {
const filePath = path.join(logosDir, file);
fs.stat(filePath, (err, stats) => {
if (err) {
throw new Error(`Error getting file stats: ${err}`);
}
if (stats.isDirectory()) {
if (file !== "MISSING_TOKEN" && !isAddress(file, { strict: true })) {
throw new Error(
`${file} is not checksum encoded! Here's the encoded version: ${getAddress(
file
)}`
);
}
}
});
});
});