-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathsubnets.mjs
More file actions
executable file
·84 lines (67 loc) · 2.46 KB
/
subnets.mjs
File metadata and controls
executable file
·84 lines (67 loc) · 2.46 KB
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
#!/usr/bin/env node
import { writeFileSync } from "node:fs";
import { join } from "node:path";
const JUNO_SUBNET_ID =
"6pbhf-qzpdk-kuqbr-pklfa-5ehhf-jfjps-zsj6q-57nrl-kzhpd-mu7hc-vae";
const getJunoSubnet = async () => {
const response = await fetch(
"https://ic-api.internetcomputer.org/api/v3/subnets/6pbhf-qzpdk-kuqbr-pklfa-5ehhf-jfjps-zsj6q-57nrl-kzhpd-mu7hc-vae"
);
if (!response.ok) {
throw new Error("Fetching the Dashboard API failed!");
}
const metadata = await response.json();
return {
subnetId: JUNO_SUBNET_ID,
specialization: "Juno's Subnet",
...(metadata !== undefined && {
// The dashboard was instructed long ago to display verified_application as application
type:
metadata.subnet_type === "verified_application"
? "application"
: metadata.subnet_type,
canisters: {
stopped: metadata.stopped_canisters,
running: metadata.running_canisters
},
nodes: {
up: metadata.up_nodes,
total: metadata.total_nodes
}
})
};
};
const listSubnets = async () => {
const response = await fetch(
"https://raw.githubusercontent.com/junobuild/juno/refs/heads/main/src/frontend/src/lib/env/subnets.json"
);
if (!response.ok) {
throw new Error("Fetching the Dashboard API failed!");
}
return await response.json();
};
const capitalize = (text) => {
const [firstLetter, ...rest] = text;
return `${firstLetter.toUpperCase()}${rest.join("")}`;
};
const generateMarkdown = (subnets) => {
let markdown =
"| Subnet ID | Type | Canisters (Running/Stopped) | Nodes (Up/Total) |\n";
markdown +=
"|-----------|----------------|---------------------|------------------|\n";
subnets.forEach(({ subnetId, specialization, canisters, nodes }) => {
markdown += `| ${subnetId} | ${specialization !== undefined ? capitalize(specialization) : ""} | ${canisters !== undefined ? `${canisters.running}/${canisters.stopped}` : ""} | ${nodes !== undefined ? `${nodes.up}/${nodes.total}` : ""} |\n`;
});
return markdown;
};
const junoSubnet = await getJunoSubnet();
const subnets = await listSubnets();
subnets.sort(({ specialization: a }, { specialization: b }) =>
(b ?? "").localeCompare(a ?? "")
);
const markdown = generateMarkdown([
junoSubnet,
...subnets.filter(({ subnetId }) => subnetId !== JUNO_SUBNET_ID)
]);
const SUBNETS_FILE = join(process.cwd(), "docs", "components", "subnets.md");
writeFileSync(SUBNETS_FILE, markdown, "utf8");