mirror of
https://github.com/refactorinqq/SLC-1.8.9.git
synced 2024-11-10 11:21:32 +01:00
159 lines
3.6 KiB
JavaScript
159 lines
3.6 KiB
JavaScript
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");
|
|
if (!fs.existsSync(`./jars/Client.jar`)) {
|
|
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");
|
|
await unzip(`./jars/Client.jar`, tempPaths.jar);
|
|
console.log("Extracting Wrapper");
|
|
await unzip(assetsPaths.wrapper, tempPaths.jar);
|
|
|
|
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",
|
|
fs.createReadStream(buildPath + `/client-${version}.jar`)
|
|
);
|
|
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();
|