File: update_installer_version.js

package info (click to toggle)
python-mne 1.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 131,492 kB
  • sloc: python: 213,302; javascript: 12,910; sh: 447; makefile: 144
file content (61 lines) | stat: -rw-r--r-- 2,702 bytes parent folder | download
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
/* inspired by https://tobiasahlin.com/blog/move-from-jquery-to-vanilla-javascript/ */

function documentReady(callback) {
    if (document.readyState != "loading") callback();
    else document.addEventListener("DOMContentLoaded", callback);
}

async function getRelease() {
    result = await fetch("https://api.github.com/repos/mne-tools/mne-installers/releases/latest");
    data = await result.json();
    return data;
}
async function warnVersion() {
    data = await getRelease();
    // Take v1.5.1 for example and change to 1.5
    ids = ["linux-installers", "macos-intel-installers", "macos-apple-installers", "windows-installers"];
    warn = false;
    ids.forEach((id) => {
        label_id = document.getElementById(id);
        // tab is immediately after label
        children = [].slice.call(label_id.parentNode.children);
        div = children[children.indexOf(label_id) + 1];
        a = div.children[0].children[0];  // div->p->a
        ending = a.href.split("-").slice(-1)[0];  // Should be one of: ["macOS_Intel.pkg", "macOS_M1.pkg", "Linux.sh", "Windows.exe"]
        data["assets"].every((asset) => {
            // find the matching asset
            if (!asset["browser_download_url"].endsWith(ending)) {
                return true;  // continue
            }
            old_stem = a.href.split("/").slice(-1)[0];
            new_stem = asset["browser_download_url"].split("/").slice(-1)[0];
            a.href = asset["browser_download_url"];
            // also replace the command on Linux
            if (ending === "Linux.sh") {
                code = document.getElementById("codecell0");
            }
            if (!warn) {
                // MNE-Python-1.5.1_0-Linux.sh to 1.5 for example
                old_ver = old_stem.split("-").slice(2)[0].split("_")[0].split(".").slice(0, 2).join(".");
                new_ver = new_stem.split("-").slice(2)[0].split("_")[0].split(".").slice(0, 2).join(".");
                if (old_ver !== new_ver) {
                    warn = `The installers below are for version ${new_ver} as ${old_ver} is no longer supported`;
                }
            }
            return false;  // do not continue
        });
    });
    if (warn) {
        let outer = document.createElement("div");
        let title = document.createElement("p");
        let inner = document.createElement("p");
        outer.setAttribute("class", "admonition warning");
        title.setAttribute("class", "admonition-title");
        title.innerText = "Warning";
        inner.innerText = warn;
        outer.append(title, inner);
        document.querySelectorAll('.install-selector-tabset')[0].before(outer);
    }
}

documentReady(warnVersion);