-
Notifications
You must be signed in to change notification settings - Fork 3
/
bundle-publish.js
53 lines (46 loc) · 1.46 KB
/
bundle-publish.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
const { Octokit } = require('@octokit/core');
const globber = require('glob');
const { readFile } = require('fs');
const pattern = './@(dist)/**/*.@(user|meta).js';
const glob = (globPattern) => new Promise((r) => {
globber(globPattern, (_, s) => r(s));
});
const auth = process.env.PERSONAL_ACCESS_TOKEN;
const octokit = new Octokit({
auth,
});
glob(pattern)
.then((files) => {
const upload = function upload(i = 0) {
if (i < files.length) {
const file = files[i];
readFile(file, (err, contentBuffer) => {
if (err) {
console.error(err);
} else {
const content = contentBuffer.toString();
const gistIdMatch = content.match(/downloadURL.*joshparkerj\/([^/]*)/);
if (gistIdMatch) {
const gistId = gistIdMatch[1];
const description = content.match(/description\s+(.*)/)[1];
const filename = file.includes('meta') ? content.match(/updateURL.*raw\/([^/]*)/)[1] : content.match(/downloadURL.*raw\/([^/]*)/)[1];
octokit.request(`PATCH /gists/${gistId}`, {
gist_id: gistId,
description,
files: {
[filename]: {
filename,
content,
},
},
})
.then(() => {
upload(i + 1);
});
}
}
});
}
};
upload();
});