-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathget-assets.ts
51 lines (44 loc) · 1.1 KB
/
get-assets.ts
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
export type Release = {
assets: Array<{
browser_download_url: string
name: string
size: number
}>
html_url: string
name: string
published_at: string
}
export type Asset = {
href?: string
size?: string
}
const formatSize = (size: number): string => `${(size / 1e6).toPrecision(3)} MB`
export const getAssets = ({
assets,
}: Release): { linux: Asset; noJre: Asset; windows: Asset } => {
const linuxRaw = assets.find(({ name }) => name.includes("linux"))
const noJreRaw = assets.find(({ name }) => name.includes("no-jre"))
const windowsRaw = assets.find(({ name }) => name.includes("win"))
let linux = {}
let noJre = {}
let windows = {}
if (linuxRaw != null) {
linux = {
href: linuxRaw.browser_download_url,
size: formatSize(linuxRaw.size),
}
}
if (noJreRaw != null) {
noJre = {
href: noJreRaw.browser_download_url,
size: formatSize(noJreRaw.size),
}
}
if (windowsRaw != null) {
windows = {
href: windowsRaw.browser_download_url,
size: formatSize(windowsRaw.size),
}
}
return { linux, noJre, windows }
}