This repository has been archived by the owner on Feb 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
release.js
176 lines (159 loc) · 4.69 KB
/
release.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
170
171
172
173
174
175
176
const {
mkdirSync,
writeFileSync,
readFile,
writeFile,
readFileSync,
} = require("fs");
const { copySync } = require("fs-extra");
const { join, dirname, basename } = require("path");
const { execFile, execFileSync } = require("child_process");
const { rimraf } = require("rimraf");
const parseArgs = require("minimist");
const { Octokit } = require("octokit");
const moment = require("moment/moment");
const ownerName = "ffrostflame";
const repo = "BridgeNet2";
const cliArgs = parseArgs(process.argv.slice(2), {
version: {
short: "v",
type: "string",
},
});
const versionString = cliArgs.v;
async function buildStandalone() {
return new Promise((resolve) => {
const projectName = basename(dirname(__filename));
const srcDir = join(projectName, "../src");
const packageDir = join(projectName, "../Packages");
const destinationDir = join(projectName, "../standalone");
const destSrcDir = join(destinationDir, "./src");
const standaloneProject = join(projectName, "../standalone.project.json");
mkdirSync(destinationDir);
mkdirSync(destSrcDir);
writeFileSync(
join(destinationDir, "./init.luau"),
"return require(script.src)"
);
writeFileSync(
standaloneProject,
`{"name": "${projectName}","tree": {"$path" : "standalone"}}`
);
copySync(packageDir, destinationDir);
copySync(srcDir, destSrcDir);
execFile(
"rojo",
["build", "-o=standalone.rbxm", "standalone.project.json"],
() => {
rimraf(destinationDir)
.catch((err) => {
console.log(err);
})
.then(() => {
rimraf(standaloneProject);
resolve();
});
}
);
});
}
// absolutely love javascript
let githubAuthToken = readFileSync(
`${process.env.USERPROFILE}\\github_auth`.replace(/\\/g, "/")
).toString();
const octokit = new Octokit({
auth: githubAuthToken,
});
readFile("wally.toml", (err, contents) => {
if (err) {
console.log(err);
} else {
let wallyString = contents.toString();
let start = wallyString.search('version = "');
let startVersionString = wallyString.lastIndexOf('"', start + 11) + 1;
let endVersionString = wallyString.indexOf('"', startVersionString + 3);
let sectionToReplace = wallyString.slice(
startVersionString,
endVersionString
);
writeFile(
"wally.toml",
wallyString.replace(sectionToReplace, versionString),
(err) => {
if (err) {
console.log(err);
} else {
execFileSync("wally.exe", ["publish"]);
}
}
);
}
});
readFile("CHANGELOG.md", (err, contents) => {
if (err) {
console.log(err);
} else {
let changelogString = contents.toString();
let latestStart = changelogString.search(`## version ${versionString}`);
changelogString = changelogString.replace(
`## version ${versionString}`,
`## [version ${versionString}](${"testurl"})`
);
let endOfVersionLine = changelogString.indexOf("\n", latestStart) - 1;
changelogString = [
changelogString.slice(0, endOfVersionLine),
`: ${moment().format("l")}`,
changelogString.slice(endOfVersionLine + 1),
].join("");
let latestChangelog = changelogString.slice(
latestStart,
changelogString.indexOf("\n## ", latestStart + 5)
);
console.log(latestChangelog);
octokit
.request("POST /repos/{owner}/{repo}/releases", {
owner: ownerName,
repo: repo,
tag_name: `v${versionString}`,
target_commitish: "master",
name: `v${versionString}`,
body: latestChangelog,
draft: false,
prerelease: false,
make_latest: "false",
generate_release_notes: false,
headers: {
"X-GitHub-Api-Version": "2022-11-28",
},
})
.then((response) => {
changelogString.replace(
`testurl`,
response.data.url
);
writeFile("CHANGELOG.md", changelogString, (err) => {
if (err) {
console.log(err);
} else {
let releaseId = response.data.id;
buildStandalone().then(() => {
readFile("standalone.rbxm", (err, rbxmContents) => {
if (err) {
console.log(err);
} else {
octokit.rest.repos
.uploadReleaseAsset({
owner: ownerName,
repo: repo,
release_id: releaseId,
name: "standalone.rbxm",
data: rbxmContents,
})
}
});
});
}
});
});
}
});