-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Expand file tree
/
Copy pathfetch-warp-releases.js
More file actions
136 lines (108 loc) · 3.61 KB
/
Copy pathfetch-warp-releases.js
File metadata and controls
136 lines (108 loc) · 3.61 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
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
135
136
import fs from "fs";
import YAML from "yaml";
import { marked } from "marked";
const BASE_URL = "https://downloads.cloudflareclient.com/v1";
const platforms = await fetch(`${BASE_URL}/platforms`)
.then((res) => res.json())
.then((data) => data.result);
fs.writeFileSync(
"./src/util/warp-platforms.json",
JSON.stringify(platforms, null, "\t"),
"utf-8",
);
const linuxDistributions = ["Ubuntu", "Debian", "CentOS", "Fedora"];
const linesToRemove = [
"For related Cloudflare for Teams documentation please see: https://developers.cloudflare.com/cloudflare-one/connections/connect-devices/warp",
"For Zero Trust documentation please see: <https://developers.cloudflare.com/cloudflare-one/connections/connect-devices/warp>",
"For Zero Trust documentation please see: <https://developers.cloudflare.com/cloudflare-one/team-and-resources/devices/cloudflare-one-client/>",
"For related Consumer documentation please see: https://developers.cloudflare.com/warp-client/",
"For Consumer documentation please see: <https://developers.cloudflare.com/warp-client/>",
"For Consumer documentation please see: <https://developers.cloudflare.com/warp-client>",
];
for (const { platform, display_name } of platforms) {
const isLinux = linuxDistributions.some((dist) =>
display_name.includes(dist),
);
for (const track of ["ga", "beta"]) {
fetch(`${BASE_URL}/update/json/${platform}/${track}`)
.then((res) => res.json())
.then((data) => {
if (!data.items) {
console.warn(
`${track} has no releases: ${JSON.stringify(data, null, 2)}`,
);
return;
}
data.items.forEach((item) => {
let folder = `./src/content/warp-releases/`;
if (isLinux) {
folder += `linux/${track}`;
} else {
folder += `${platform}/${track}`;
}
const path = `${folder}/${item.version}.yaml`;
if (!fs.existsSync(folder)) {
fs.mkdirSync(folder, { recursive: true });
}
if (fs.existsSync(path)) {
if (isLinux) {
const existingFile = YAML.parse(fs.readFileSync(path, "utf-8"));
existingFile.linuxPlatforms ??= {};
if (!existingFile.linuxPlatforms[platform]) {
console.log(
`Adding ${platform} to Linux ${track} ${item.version}.`,
);
existingFile.linuxPlatforms[platform] = item.packageSize;
} else {
console.log(
`${platform} already exists in Linux ${track} ${item.version}.`,
);
}
fs.writeFileSync(
path,
YAML.stringify(existingFile, { blockQuote: "literal" }),
"utf-8",
);
} else {
console.log(
`${platform} ${track} ${item.version} already exists.`,
);
}
return;
}
console.log(`Saving ${platform} ${track} ${item.version}.`);
let markdown = item.releaseNotes;
markdown.replace(/\r\n/g, "\n");
for (const line of linesToRemove) {
markdown = markdown.replace(line, "");
}
markdown = markdown.trim();
const tokens = marked.lexer(markdown);
marked.walkTokens(tokens, (token) => {
if (token.type === "heading") {
token.type = "strong";
token.raw = `**${token.text}**\n`;
delete token.depth;
}
});
const releaseNotes = tokens.reduce((s, t) => s + t.raw, "");
const platformName = isLinux ? "Linux" : data.platformName;
fs.writeFileSync(
path,
YAML.stringify(
{
...item,
releaseNotes,
platformName,
linuxPlatforms: isLinux
? { [platform]: item.packageSize }
: undefined,
},
{ blockQuote: "literal" },
),
"utf-8",
);
});
});
}
}