-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathpatreonBuild.js
169 lines (152 loc) · 4.23 KB
/
patreonBuild.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
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
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,
""
);
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();
}
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 });
const embed = new EmbedBuilder()
// .setTitle(`GSE ${BuildVersion}`)
.setAuthor({
name: "GSE Updater",
iconURL:
"https://media.forgecdn.net/attachments/372/575/gse2-logo-dark-2x.png",
url: "https://github.com/TimothyLuke/GSE-Advanced-Macro-Compiler.com",
})
// .setURL(
// "https://www.https://github.com/TimothyLuke/GSE-Advanced-Macro-Compiler.com"
// )
.addFields({
name: "New GSE Update",
value: `${BuildNumber} Released`,
inline: true,
})
// .addField("Second field", "this is not inline")
.setColor("#00b0f4")
.setThumbnail(
"https://media.forgecdn.net/attachments/372/575/gse2-logo-dark-2x.png"
)
// .setDescription("Oh look a description :)")
// .setImage("https://cdn.discordapp.com/embed/avatars/0.png")
// .setFooter(
// "Hey its a footer",
// "https://cdn.discordapp.com/embed/avatars/0.png"
// )
.setTimestamp();
var file = new AttachmentBuilder(`./GSE-${BuildNumber}.zip`);
try {
hook.send({
embeds: [embed],
files: [file],
});
//hook.sendFile(`GSE-${BuildNumber}.zip`).then(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")) {
return fs.unlink(`.release/${file}`, 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,
createArchive,
publishArchive,
closeMessage,
],
function (err) {
console.log(err);
}
);