-
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathpatreonBuild.js
More file actions
226 lines (205 loc) · 6.69 KB
/
Copy pathpatreonBuild.js
File metadata and controls
226 lines (205 loc) · 6.69 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
let _ = require("lodash");
let async = require("async");
const fs = require("fs");
var BuildVersion = false;
var BuildNumber = "";
function lines(text) {
return text.split("\n");
}
function updateToc(path, filename, done) {
fs.readFile(`.release/${path}/${filename}.toc`, "utf8", (err, data) => {
if (err) {
console.log(`Unable to read ${path}/${filename}`);
console.error(err);
return done(err);
}
var tocLines = lines(data);
var tocIndex = _.findIndex(tocLines, function (o) {
return o.startsWith("## Version:");
});
var version = `${tocLines[tocIndex]}-PatronBuild`.replace(
/(\r\n|\n|\r)/gm,
""
);
// version = version.replace("3.2", "3.3.0-midnight-beta-0")
tocLines[tocIndex] = version;
if (!BuildVersion) {
BuildVersion = version;
console.log(`BuildVersion set to ${BuildVersion}`);
var n = BuildVersion.split(" ");
console.log(n);
BuildNumber = n[n.length - 1];
}
fs.writeFile(
`.release/${path}/${filename}.toc`,
`${tocLines.join("\n")}`,
(err) => {
if (err) {
return done(err);
}
console.log(`Updated ${path}/${filename}`);
return done();
}
);
});
}
function addExtras(done) {
const srcDir = `./GSE_QoL`;
const destDir = `./.release/GSE_QoL`;
fs.cpSync(srcDir, destDir, { recursive: true });
return done();
}
// GSE_QoL is excluded from the BigWigs packager via .pkgmeta `ignore:`,
// so its `## Version: @project-version@` token never gets substituted by
// the packager. addExtras above just cpSync's the source folder (token
// and all). Here we copy the resolved Version line from GSE/GSE.toc —
// which BigWigs DID substitute, and which updateToc(GSE) further
// appended `-PatronBuild` to in this waterfall — onto the QoL toc so
// patrons get the same versioned suffix as the rest of the bundle.
function syncQoLVersionFromGSE(done) {
const gseTocPath = `./.release/GSE/GSE.toc`;
const qolTocPath = `./.release/GSE_QoL/GSE_QoL.toc`;
fs.readFile(gseTocPath, "utf8", (err, gseData) => {
if (err) {
console.log(`[syncQoLVersion] cannot read ${gseTocPath}`);
return done(err);
}
const versionLine = lines(gseData).find((l) =>
l.startsWith("## Version:")
);
if (!versionLine) {
return done(new Error(`No "## Version:" line in ${gseTocPath}`));
}
fs.readFile(qolTocPath, "utf8", (err2, qolData) => {
if (err2) {
console.log(`[syncQoLVersion] cannot read ${qolTocPath}`);
return done(err2);
}
const qolLines = lines(qolData);
const idx = qolLines.findIndex((o) => o.startsWith("## Version:"));
if (idx < 0) {
return done(new Error(`No "## Version:" line in ${qolTocPath}`));
}
const cleanedVersion = versionLine.replace(/(\r\n|\n|\r)/gm, "");
qolLines[idx] = cleanedVersion;
fs.writeFile(qolTocPath, qolLines.join("\n"), (err3) => {
if (err3) return done(err3);
console.log(
`[syncQoLVersion] GSE_QoL.toc Version set to: ${cleanedVersion}`
);
return done();
});
});
});
}
function createArchive(done) {
const archiver = require("archiver");
const output = fs.createWriteStream(`GSE-${BuildNumber}.zip`);
const archive = archiver("zip", {
zlib: { level: 9 }, // Sets the compression level.
});
output.on("close", function () {
console.log(archive.pointer() + " total bytes");
console.log(
"archiver has been finalized and the output file descriptor has closed."
);
return done();
});
output.on("end", function () {
console.log("Data has been drained");
});
archive.pipe(output);
archive.directory(".release", false);
archive.finalize();
}
function publishArchive(done) {
const {
EmbedBuilder,
WebhookClient,
AttachmentBuilder,
} = require("discord.js");
const hook = new WebhookClient({ url: process.env.DISCORD_WEBHOOK });
// Direct image URL on GitHub raw — replaces the old forgecdn URL with
// the same shape (no redirects, stable Content-Type: image/png). The
// file is the one committed to this repo at GSE_GUI/Assets, so a
// rebrand is "push a new logo, embed updates on the next build".
// Point at GSE_Menu_Logo.png — the wide-finish wrench that reads better
// at the embed-thumbnail size than the square dark icon does. Same
// GitHub raw shape (direct image, no redirects) so Discord's embed
// proxy is happy with it.
const LOGO_URL = "https://raw.githubusercontent.com/TimothyLuke/GSE-Advanced-Macro-Compiler/master/GSE_GUI/Assets/GSE_Menu_Logo.png";
const embed = new EmbedBuilder()
.setAuthor({
name: "GSE Updater",
iconURL: LOGO_URL,
url: "https://github.com/TimothyLuke/GSE-Advanced-Macro-Compiler",
})
.addFields({
name: "New GSE Update",
value: `${BuildNumber} Released`,
inline: true,
})
.setColor("#00b0f4")
.setThumbnail(LOGO_URL)
.setTimestamp();
var file = new AttachmentBuilder(`./GSE-${BuildNumber}.zip`);
try {
// username + avatarURL override the webhook's default identity per
// message, so the bot's avatar matches the embed even if the webhook
// was created with the old hex logo in the Discord server settings.
hook.send({
username: "GSE Build Bot",
avatarURL: LOGO_URL,
embeds: [embed],
files: [file],
}).then(function() {
console.log('[pat] Discord webhook sent');
return done();
}).catch(function(err) {
console.log('[pat] Discord webhook failed:', err.message);
return done();
});
} catch (err) {
console.log(err);
return done(err);
}
}
function deleteExistingZips(done) {
fs.readdir(".release", (err, files) => {
for (const file of files) {
console.log(`Processing File .release/${file}`);
if (file.endsWith("zip")) {
// Move the original BigWigs zip to root so publish step can upload it too
fs.renameSync(`.release/${file}`, `./${file}`);
console.log(`Moved .release/${file} to ./${file}`);
return done();
}
if (file.endsWith("json")) {
return fs.unlink(`.release/${file}`, done);
}
}
return done();
});
}
function closeMessage(done) {
console.log("Patron Build Complete");
return done();
}
async.waterfall(
[
async.apply(updateToc, "GSE", "GSE"),
async.apply(updateToc, "GSE_GUI", "GSE_GUI"),
async.apply(updateToc, "GSE_LDB", "GSE_LDB"),
async.apply(updateToc, "GSE_Utils", "GSE_Utils"),
async.apply(updateToc, "GSE_Options", "GSE_Options"),
deleteExistingZips,
addExtras,
syncQoLVersionFromGSE,
createArchive,
publishArchive,
closeMessage,
],
function (err) {
console.log(err);
}
);