Skip to content

Commit

Permalink
order ZLS install artifacts by OS
Browse files Browse the repository at this point in the history
See #4
  • Loading branch information
Techatrix committed Aug 30, 2024
1 parent 58a5f75 commit 3092467
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions assets/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function formatBytes(bytes, decimals = 2) {
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
}

function createBinaryTable(json) {
function createBinaryTable(entries) {
const heading = document.createElement("tr");
for (const item of ["OS", "Arch", "Filename", "Signature", "Size"]) {
const th = document.createElement("th");
Expand All @@ -58,7 +58,7 @@ function createBinaryTable(json) {

const tbody = document.createElement("tbody");

for (const [key, value] of Object.entries(json)) {
for (const [key, value] of entries) {
if (key === "version") continue;
if (key === "date") continue;

Expand Down Expand Up @@ -164,7 +164,25 @@ async function update() {
return false;
}

const table = createBinaryTable(json);
const { date, version, ...artifacts } = json;

const sortScore = {
windows: 1,
macos: 2,
linux: 3,
wasi: 4,
};

const artifactEntries = Object.entries(artifacts);
artifactEntries.sort(([lhs], [rhs]) => {
const lhsOS = lhs.split("-")[1];
const rhsOS = rhs.split("-")[1];
const lhsScore = sortScore[lhsOS] ?? 5;
const rhsScore = sortScore[rhsOS] ?? 5;
return lhsScore > rhsScore;
});

const table = createBinaryTable(artifactEntries);
prebuiltBinaryTable.innerHTML = table.outerHTML;

buildFromSourceResult.style.display = "none";
Expand Down Expand Up @@ -235,4 +253,4 @@ zigVersion.value = params["zig_version"] ?? "";

if (params["zig_version"]) {
update();
}
}

0 comments on commit 3092467

Please sign in to comment.