SLC-1.8.9/autobuilder/index.js

159 lines
3.6 KiB
JavaScript
Raw Permalink Normal View History

2023-06-28 19:06:07 +02:00
const fs = require("fs");
const fse = require("fs-extra");
const { unzip } = require("./utils");
const { zip } = require("zip-a-folder");
const axios = require("axios");
const FormData = require("form-data");
const assetsPaths = {
"1.8.9": "./assets/1.8.9.jar",
libs: "../libs",
wrapper: "./assets/launchwrapper.jar",
};
const jarsPaths = {};
const tempPaths = {
default: "./temp",
jar: "./temp/jar/",
};
const buildPath = "./build";
async function build() {
const version = process.argv[3];
const branch = process.argv[5];
const commit = process.argv[7];
const login = process.env.LOGIN;
const password = process.env.PASSWORD;
if (!version) {
console.log("Please, enter a version");
return;
}
if (!branch) {
console.log("Please, enter a branch");
return;
}
if (!commit) {
console.log("Please, enter a branch");
return;
}
if (!login || !password) {
console.log("Please, enter login and password");
return;
}
console.log(
`Silent Client AutoBuilder (MC Version: ${version}, branch: ${branch})`
);
console.log("Checking Jars");
2023-07-07 16:58:37 +02:00
if (!fs.existsSync(`./jars/Client.jar`)) {
2023-06-28 19:06:07 +02:00
console.error("JAR file does not exist.");
return;
}
console.log("Checking assets");
if (!fs.existsSync(assetsPaths[version])) {
console.error("Assets file does not exist.");
return;
}
console.log("Cleaning up temp directory");
try {
await fs.promises.rm(tempPaths.default, {
recursive: true,
force: true,
});
} catch {}
console.log("Extracting JAR");
2023-07-08 08:55:28 +02:00
await unzip(`./jars/Client.jar`, tempPaths.jar);
2023-06-28 20:46:18 +02:00
console.log("Extracting Wrapper");
await unzip(assetsPaths.wrapper, tempPaths.jar);
2023-06-28 19:06:07 +02:00
const libs = await fs.promises.readdir(assetsPaths.libs);
for (const lib of libs) {
console.log(`Extracting ${lib}`);
await unzip(assetsPaths.libs + `/${lib}`, tempPaths.jar);
}
console.log("Cleaning up extra files in JAR");
try {
await fs.promises.rm(tempPaths.jar + "App.class", {
recursive: true,
force: true,
});
} catch {}
try {
await fs.promises.rm(tempPaths.jar + "Start.class", {
recursive: true,
force: true,
});
} catch {}
try {
await fs.promises.rm(tempPaths.jar + ".DS_Store", {
recursive: true,
force: true,
});
} catch {}
try {
await fs.promises.rm(tempPaths.jar + "build_data.json", {
recursive: true,
force: true,
});
} catch {}
await fs.promises.writeFile(
tempPaths.jar + "build_data.json",
JSON.stringify({
commit,
branch,
})
);
console.log("Cleaning up build directory");
try {
await fs.promises.rm(buildPath, {
recursive: true,
force: true,
});
} catch {}
await fs.promises.mkdir(buildPath, { recursive: true });
console.log("Building JAR File");
await zip(tempPaths.jar, buildPath + `/client-${version}.jar`);
console.log("Uploading build to Silent Client Servers");
try {
const formData = new FormData();
formData.append(
"jar",
2023-06-28 19:10:37 +02:00
fs.createReadStream(buildPath + `/client-${version}.jar`)
2023-06-28 19:06:07 +02:00
);
formData.append("version", commit);
formData.append("branch", branch);
formData.append("commit", commit);
formData.append("description", "");
formData.append("mcVersion", version);
formData.append("sendToTelegram", "0");
const { data: auth } = await axios.post(
"https://api.silentclient.net/auth/login",
{ email: login, password: password }
);
await axios.post(
"https://api.silentclient.net/updates/update_version",
formData,
{
headers: {
Authorization: `Bearer ${auth.auth.token}`,
},
}
);
} catch (error) {
console.log(`Error: ${error}`);
console.log(error.response.data);
return;
}
console.log("Build completed successfully!");
}
build();