-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
90 lines (74 loc) · 3.47 KB
/
script.js
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
85
86
87
88
89
90
async function fetchDriverLatestVersion() {
const response = await fetch("https://api.github.com/repos/zwave-js/node-zwave-js/releases");
const responseJson = await response.json();
return responseJson.filter(r => !r.prerelease)[0].tag_name;
}
async function fetchHAZUIAddonLatestVersion() {
const response = await fetch("https://api.github.com/repos/hassio-addons/addon-zwave-js-ui/releases");
const responseJson = await response.json();
return responseJson.filter(r => !r.prerelease)[0].tag_name;
}
async function fetchZUILatestVersion() {
const response = await fetch("https://api.github.com/repos/zwave-js/zwave-js-ui/releases");
const responseJson = await response.json();
return responseJson.filter(r => !r.prerelease)[0].tag_name;
}
async function fetchHAZUIAddonZUIVersion(version) {
const Dockerfile = await fetch(`https://raw.githubusercontent.com/hassio-addons/addon-zwave-js-ui/${version}/zwave-js-ui/Dockerfile`);
const DockerfileText = await Dockerfile.text();
// ARG ZWAVE_JS_UI_VERSION="v8.18.0"
const regex = /ARG ZWAVE_JS_UI_VERSION="(.*)"/gm;
const match = regex.exec(DockerfileText);
return match?.[1];
}
async function fetchHACoreAddonVersion() {
const response = await fetch(`https://raw.githubusercontent.com/home-assistant/addons/master/zwave_js/config.yaml`);
const responseText = await response.text();
// version: 0.1.83
const regex = /^version: (.*)$/gm;
const match = regex.exec(responseText);
return match?.[1];
}
async function fetchHACoreAddonDriverVersion() {
const response = await fetch(`https://raw.githubusercontent.com/home-assistant/addons/master/zwave_js/build.yaml`);
const responseText = await response.text();
// ZWAVEJS_VERSION: 10.22.3
const regex = /ZWAVEJS_VERSION: (.*)/gm;
const match = regex.exec(responseText);
return match?.[1];
}
async function fetchZUIDriverVersion(version) {
const response = await fetch(`https://raw.githubusercontent.com/zwave-js/zwave-js-ui/${version}/package.json`);
const responseJson = await response.json();
return responseJson.dependencies["zwave-js"].replace(/^[^~]/, "v");
}
async function fetchDriver() {
const driverVersion = await fetchDriverLatestVersion();
document.getElementById("driver__version").innerText = driverVersion;
}
async function fetchHAZUIAddon() {
const haAddonVersion = await fetchHAZUIAddonLatestVersion();
const haAddonZUIVersion = await fetchHAZUIAddonZUIVersion(haAddonVersion);
const zwavejsVersion = await fetchZUIDriverVersion(haAddonZUIVersion);
document.getElementById("ha-addon__version").innerText = haAddonVersion;
document.getElementById("ha-addon__zui-version").innerText = haAddonZUIVersion;
document.getElementById("ha-addon__driver-version").innerText = zwavejsVersion;
}
async function fetchZUI() {
const zuiVersion = await fetchZUILatestVersion();
const zwavejsVersion = await fetchZUIDriverVersion(zuiVersion);
document.getElementById("zui__version").innerText = zuiVersion;
document.getElementById("zui__driver-version").innerText = zwavejsVersion;
}
async function fetchHACoreAddon() {
const addonVersion = await fetchHACoreAddonVersion();
const zwavejsVersion = await fetchHACoreAddonDriverVersion();
document.getElementById("ha-core__version").innerText = addonVersion;
document.getElementById("ha-core__driver-version").innerText = zwavejsVersion;
}
document.addEventListener("DOMContentLoaded", () => {
fetchDriver().catch(console.error);
fetchHAZUIAddon().catch(console.error);
fetchZUI().catch(console.error);
fetchHACoreAddon().catch(console.error);
});