-
Notifications
You must be signed in to change notification settings - Fork 10
/
sync-v2.cjs
45 lines (40 loc) · 1.17 KB
/
sync-v2.cjs
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
const fs = require("fs");
const SUPPORTED_NETWORKS = ["polkadot", "ethereum", "kusama"];
const TEMPLATE = {
baseUrl: "https://raw.githubusercontent.com",
branch: "master",
cdn: {
jsDelivr: "https://cdn.jsdelivr.net/gh",
statically: "https://cdn.statically.io/gh",
},
path: "v2",
repository: "galacticcouncil/intergalactic-asset-metadata",
items: [],
};
const getResource = (network, predicate) => {
try {
const files = fs.readdirSync(TEMPLATE.path + "/" + network, {
recursive: true,
});
const assets = files.filter((path) => predicate(path));
return assets
.filter((path) => /.(jpg|png|svg)$/.test(path))
.map((i) => network + "/" + i);
} catch (err) {
console.error(err);
return [];
}
};
const writeResource = (name, predicate) => {
const resources = SUPPORTED_NETWORKS.map((n) => getResource(n, predicate))
.flat()
.sort();
const resourcesJson = JSON.stringify(
{ ...TEMPLATE, items: resources },
null,
2
);
fs.writeFileSync(name, resourcesJson);
};
writeResource("assets-v2.json", (path) => path.includes("/assets/"));
writeResource("chains-v2.json", (path) => !path.includes("/assets/"));