-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
75 lines (70 loc) · 1.71 KB
/
index.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
const xml = require("xml");
const { mkdir, writeFile } = require("fs/promises");
const baseUrl = "https://storage.googleapis.com/flutter_infra_release/releases";
const query = ["windows", "macos", "linux"];
async function fetchRelease(os) {
const response = await fetch(`${baseUrl}/releases_${os}.json`);
const data = await response.json();
const releases = data["releases"];
const result = [];
for (const release of releases) {
result.push({
item: [
{
title: `Flutter v${release["version"]} has been released`,
},
{
link: `https://docs.flutter.dev/release/archive?tab=${os}`,
},
{
description: `Hash: ${release["hash"]}, Dart SDK Version: ${release["dart_sdk_version"]}.`,
},
{
pubDate: release["release_date"],
},
],
});
}
return result;
}
function buildRss(os, items) {
const rss = [
{
rss: [
{ _attr: { version: "2.0" } },
{
channel: [
{
title: `Flutter releases for ${os}`,
},
{
link: "https://docs.flutter.dev/release/release-notes",
},
{
description: "",
},
{
lastBuildDate: new Date().toISOString(),
},
...items,
],
},
],
},
];
return xml(rss, { declaration: true });
}
(async function () {
try {
await mkdir("dist");
} catch (e) {
if (e.code !== "EEXIST") {
throw e;
}
}
for (const e of query) {
const items = await fetchRelease(e);
const result = buildRss(e, items);
await writeFile(`dist/releases_${e}.xml`, result);
}
})();