-
Notifications
You must be signed in to change notification settings - Fork 12
/
check_npm_package_versions.html
134 lines (125 loc) · 5.35 KB
/
check_npm_package_versions.html
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<!doctype html>
<html lang="en" dir="ltr">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Checks publication of packages to npm</title>
<!--
| Copyright 2020 Esri
|
| Licensed under the Apache License, Version 2.0 (the "License");
| you may not use this file except in compliance with the License.
| You may obtain a copy of the License at
|
| http://www.apache.org/licenses/LICENSE-2.0
|
| Unless required by applicable law or agreed to in writing, software
| distributed under the License is distributed on an "AS IS" BASIS,
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
| See the License for the specific language governing permissions and
| limitations under the License.
-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://esri.github.io/calcite-bootstrap/styles/calcite-bootstrap.min.css">
<style>
html {
padding:16px;
}
table, th, td {
border: 1px solid lightgray;
}
th, td {
padding: 10px;
}
th, td {
width: 100px;
text-align: center;
}
th.package, td.package {
width: 220px;
text-align: left;
}
.good {
color: green;
font-weight: bold;
}
.good:before {
content: "\2714";
}
.bad {
color: red;
font-weight: bold;
}
.bad:before {
content: "\2716";
}
</style>
</head>
<body>
<div id="output">Fetching...</div>
<script>
let currentVersion = "";
fetch("package.json").then(
package_file => package_file.json()
).then(
package_json => {
currentVersion = package_json.version;
html = "<b>Current repository version: " + currentVersion + "</b><br><br>" +
"<table><tr><th class='package'>Package in unpkg</th><th>esm</th><th>cjs</th></tr>";
html += addPackageVersionsToTable("@esri/solution-common", "common");
html += addPackageVersionsToTable("@esri/solution-creator", "creator");
html += addPackageVersionsToTable("@esri/solution-deployer", "deployer");
html += addPackageVersionsToTable("@esri/solution-feature-layer", "feature-layer");
html += addPackageVersionsToTable("@esri/solution-file", "file");
html += addPackageVersionsToTable("@esri/solution-form", "form");
html += addPackageVersionsToTable("@esri/solution-group", "group");
html += addPackageVersionsToTable("@esri/solution-hub-types", "hub-types");
html += addPackageVersionsToTable("@esri/solution-simple-types", "simple-types");
html += addPackageVersionsToTable("@esri/solution-storymap", "storymap");
html += addPackageVersionsToTable("@esri/solution-velocity", "velocity");
html += addPackageVersionsToTable("@esri/solution-viewer", "viewer");
html += addPackageVersionsToTable("@esri/solution-web-experience", "web-experience");
html += addPackageVersionsToTable("@esri/solution-web-tool", "web-tool");
html += addPackageVersionsToTable("@esri/solution-workflow", "workflow");
html += "</table>";
const resultsElement = document.getElementById("output");
resultsElement.innerHTML = html;
window.getComputedStyle(resultsElement, null);
}
);
function addPackageVersionsToTable(packageName, packageFileName) {
setTimeout(() => addSpecificPackageVersionToTable(packageName, packageFileName, false), 10);
setTimeout(() => addSpecificPackageVersionToTable(packageName, packageFileName, true), 10);
return "<tr><td class='package'><a href='https://www.npmjs.com/package/" + packageName + "' target='_blank'>" + packageName + "</td><td id='" +
packageFileName + "_esm'></td><td id='" + packageFileName + "_cjs'></td></tr>";
}
function addSpecificPackageVersionToTable(packageName, packageFileName, useCJS) {
fetch("https://unpkg.com/" + packageName).then(
packageFile => {
const packageUrl = packageFile.url;
const iVersionStart = packageUrl.indexOf(packageName) + packageName.length + 1;
const iVersionEnd = packageUrl.indexOf("/", iVersionStart);
let packageVersion = packageUrl.substring(iVersionStart, iVersionEnd);
if (packageVersion === "dist") {
packageVersion = "<i>none</i>";
} else if (packageVersion !== currentVersion) {
packageVersion = "<span class='bad'> " + packageVersion + "</span>";
} else {
const versionRoot = packageUrl.substring(0, iVersionEnd);
const urlToFetch = versionRoot + (useCJS ? "/dist/cjs/index.js" : "/dist/esm/index.js");
fetch(urlToFetch).then(
packageVersionFile => {
if (packageVersionFile.status === 404) {
packageVersion = "<span class='bad'> " + packageVersion + "</span>";
} else {
packageVersion = "<span class='good'> " + packageVersion + "</span>";
}
document.getElementById(packageFileName + (useCJS ? "_cjs" : "_esm")).innerHTML = packageVersion;
}
);
}
}
);
}
</script>
</body>
</html>