-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplugin.publish.mjs
executable file
·85 lines (70 loc) · 2.24 KB
/
plugin.publish.mjs
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
#!/bin/node
import process from 'process';
import fs from 'fs';
const token = process.env['GITHUB_TOKEN'];
const client = new Github(token);
const fileName = 'plugin.zip';
const repoName = 'ILadis/ts3-qs4sd';
const releaseInfo = {
'name': 'Latest Devbuild',
'body': ''
+ 'This is the latest automatically built version of the plugin. It can be manually installed by selecting "Install Plugin \n'
+ 'from ZIP File" in the DeckyLoader developer settings menu.\n'
+ '\n'
+ 'Note: This version should be considered unstable since it may contain work in progress.',
'tag_name': 'latest',
'target_commitish': 'master',
'prerelease': true,
};
const releases = await client.request({
method: 'GET',
path: `https://api.github.com/repos/${repoName}/releases`
});
var releaseId = releases.find(release => release.name == releaseInfo.name)?.id;
if (releaseId) {
await client.request({
method: 'DELETE',
path: `https://api.github.com/repos/${repoName}/releases/${releaseId}`
});
await client.request({
method: 'DELETE',
path: `https://api.github.com/repos/${repoName}/git/refs/tags/latest`
});
}
const release = await client.request({
method: 'POST',
path: `https://api.github.com/repos/${repoName}/releases`,
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(releaseInfo),
});
var releaseId = release.id;
const stream = fs.createReadStream(fileName);
const stats = fs.statSync(fileName);
await client.request({
method: 'POST',
path: `https://uploads.github.com/repos/${repoName}/releases/${releaseId}/assets?name=${fileName}`,
headers: {
'Content-Type': 'application/octet-stream',
'Content-Length': stats.size,
},
body: stream,
});
function Github(token) {
return { request };
async function request({ method, path, headers, body }) {
var headers = new Headers(headers);
headers.append('Accept', 'application/vnd.github+json');
headers.append('Authorization', `Bearer ${token}`);
const request = new Request(path, { method, body, headers, duplex: 'half' });
const response = await fetch(request);
var body = await response.text();
if (!response.ok) {
throw new Error(body);
}
if (body.length > 0) {
return JSON.parse(body);
}
}
}