This repository has been archived by the owner on Feb 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen-locals.js
94 lines (69 loc) · 2.56 KB
/
gen-locals.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const axios = require('axios').default;
const { Octokit } = require("@octokit/rest");
const fs = require('fs');
const filesize = require('filesize');
const moment = require('moment')
const path = require('path')
function dirPath(p) {
return path.join(__dirname, p)
}
const DATEFMT = "dddd, MMMM Do YYYY, H:mm:ss"
const github = new Octokit({
userAgent: 'vgmstream-dl v1.0.0',
auth: process.env.GITHUB_API_KEY
});
const regex = /[^0-9a-f]*/gm;
const pug = require('pug');
const genIndex = pug.compileFile(dirPath('src/index.pug'));
(async () => {
console.debug("Getting Windows commit...")
var winRequest = await axios.get("https://vgmstream-builds.s3-us-west-1.amazonaws.com/latest_id_win", {
responseType: 'text'
})
var winCommitHash = winRequest.data.replace(regex, "")
console.debug("Getting Linux commit...")
var lxRequest = await axios.get("https://vgmstream-builds.s3-us-west-1.amazonaws.com/latest_id_lx", {
responseType: 'text'
})
var lxCommitHash = lxRequest.data.replace(regex, "")
console.debug("Getting Windows commit info from GitHub...")
var winCommit = (await github.rest.git.getCommit({
owner: 'vgmstream',
repo: 'vgmstream',
commit_sha: winCommitHash,
})).data
winCommit.fmtDate = moment.utc(winCommit.committer.date).format(DATEFMT)
console.debug("Getting Linux commit info from GitHub...")
var lxCommit = (await github.rest.git.getCommit({
owner: 'vgmstream',
repo: 'vgmstream',
commit_sha: lxCommitHash,
})).data
lxCommit.fmtDate = moment.utc(lxCommit.committer.date).format(DATEFMT)
console.log("Getting filesizes...")
var urls = {
winCmd: `https://cdn.vgmstream.org/${winCommit.sha}/windows/vgmstream-win.zip`,
winFb2k: `https://cdn.vgmstream.org/${winCommit.sha}/windows/foo_input_vgmstream.fb2k-component`,
lx: `https://cdn.vgmstream.org/${lxCommit.sha}/linux/vgmstream-linux-cli.tar.gz`
}
var fileSizes = {}
for (const url in urls) {
var cl = (await axios.head(urls[url])).headers['content-length']
fileSizes[url] = {
raw: parseInt(cl),
formatted: filesize(parseInt(cl))
}
}
var locals = {
winCommit,
lxCommit,
urls,
fileSizes,
env: process.env,
currentDate: moment.utc().format(DATEFMT)
}
fs.writeFileSync("src/index.html", genIndex(locals))
var safelocals = locals
delete safelocals.env
fs.writeFileSync("static/data.json", JSON.stringify(safelocals, null, 4))
})()