-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
98 lines (81 loc) · 3.88 KB
/
script.js
File metadata and controls
98 lines (81 loc) · 3.88 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
function stripV(version) {
return version?.replace(/^v/, "");
}
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 fetchHAZUIAppLatestVersion() {
const response = await fetch("https://api.github.com/repos/hassio-addons/app-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 fetchHAZUIAppZUIVersion(version) {
const Dockerfile = await fetch(`https://raw.githubusercontent.com/hassio-addons/app-zwave-js-ui/${version}/zwave-js-ui/Dockerfile`);
const DockerfileText = await Dockerfile.text();
// ARG ZWAVE_JS_UI_VERSION="11.11.0"
const regex = /ARG ZWAVE_JS_UI_VERSION="(.*)"/gm;
const match = regex.exec(DockerfileText);
const zuiVersion = match?.[1];
return zuiVersion && !zuiVersion.startsWith("v") ? `v${zuiVersion}` : zuiVersion;
}
async function fetchHACoreAppVersion() {
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 fetchHACoreAppZUIVersion() {
const response = await fetch(`https://raw.githubusercontent.com/home-assistant/addons/master/zwave_js/build.yaml`);
const responseText = await response.text();
// ZWAVEJS_UI_VERSION: 11.11.0
const regex = /ZWAVEJS_UI_VERSION: (.*)/gm;
const match = regex.exec(responseText);
const zuiVersion = match?.[1];
return zuiVersion && !zuiVersion.startsWith("v") ? `v${zuiVersion}` : zuiVersion;
}
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 "v" + responseJson.dependencies["zwave-js"].replace(/^[^0-9]*/, "");
}
async function fetchDriver() {
const driverVersion = await fetchDriverLatestVersion();
document.getElementById("driver__version").innerText = stripV(driverVersion);
}
async function fetchHAZUIApp() {
const haAppVersion = await fetchHAZUIAppLatestVersion();
const haAppZUIVersion = await fetchHAZUIAppZUIVersion(haAppVersion);
const zwavejsVersion = await fetchZUIDriverVersion(haAppZUIVersion);
document.getElementById("ha-app__version").innerText = stripV(haAppVersion);
document.getElementById("ha-app__zui-version").innerText = stripV(haAppZUIVersion);
document.getElementById("ha-app__driver-version").innerText = stripV(zwavejsVersion);
}
async function fetchZUI() {
const zuiVersion = await fetchZUILatestVersion();
const zwavejsVersion = await fetchZUIDriverVersion(zuiVersion);
document.getElementById("zui__version").innerText = stripV(zuiVersion);
document.getElementById("zui__driver-version").innerText = stripV(zwavejsVersion);
}
async function fetchHACoreApp() {
const appVersion = await fetchHACoreAppVersion();
const zuiVersion = await fetchHACoreAppZUIVersion();
const zwavejsVersion = await fetchZUIDriverVersion(zuiVersion);
document.getElementById("ha-core__version").innerText = stripV(appVersion);
document.getElementById("ha-core__zui-version").innerText = stripV(zuiVersion);
document.getElementById("ha-core__driver-version").innerText = stripV(zwavejsVersion);
}
document.addEventListener("DOMContentLoaded", () => {
fetchDriver().catch(console.error);
fetchHAZUIApp().catch(console.error);
fetchZUI().catch(console.error);
fetchHACoreApp().catch(console.error);
});