const fs = require('fs'); const cp = require('child_process'); const plist = require('plist'); if (fs.existsSync("./work")) fs.rmSync("./work", { recursive: true }); fs.mkdirSync("./work"); fs.writeFileSync("./work/package.json", "{}"); console.log("# Downloading Electron for macOS ARM64"); cp.execSync("npm install electron@latest --platform=darwin --arch=arm64", { cwd: "./work", stdio: "inherit" }); fs.renameSync("./work/node_modules/electron/dist", "./work/electron-darwin-arm64"); fs.rmSync("./work/node_modules", { recursive: true }); console.log("# Downloading Electron for macOS x64"); cp.execSync("npm install electron@latest --platform=darwin --arch=x64", { cwd: "./work", stdio: "inherit" }); fs.renameSync("./work/node_modules/electron/dist", "./work/electron-darwin-x64"); fs.rmSync("./work/node_modules", { recursive: true }); let version = fs.readFileSync("./work/electron-darwin-arm64/version").toString().trim(); console.log("# Electron version: " + version); console.log("# Preparing Electron"); fs.mkdirSync("./work/root"); fs.mkdirSync("./work/root/arm"); fs.mkdirSync("./work/root/x64"); fs.renameSync("./work/electron-darwin-x64/Electron.app", "./work/root/x64/AtomicRuntime.framework"); fs.renameSync("./work/electron-darwin-arm64/Electron.app", "./work/root/arm/AtomicRuntime.framework"); fs.renameSync("./work/root/x64/AtomicRuntime.framework/Contents/MacOS/Electron", "./work/root/x64/AtomicRuntime.framework/Contents/MacOS/Atomic"); fs.renameSync("./work/root/arm/AtomicRuntime.framework/Contents/MacOS/Electron", "./work/root/arm/AtomicRuntime.framework/Contents/MacOS/Atomic"); fs.rmSync("./work/root/arm/AtomicRuntime.framework/Contents/Info.plist"); fs.rmSync("./work/root/arm/AtomicRuntime.framework/Contents/PkgInfo"); fs.rmSync("./work/root/x64/AtomicRuntime.framework/Contents/Info.plist"); fs.rmSync("./work/root/x64/AtomicRuntime.framework/Contents/PkgInfo"); console.log("# Preparing SDK"); fs.mkdirSync("./work/root/sdk"); fs.mkdirSync("./work/root/sdk/Atomic"); fs.mkdirSync("./work/root/sdk/Atomic/SDK"); for (let file of fs.readdirSync("../converter/").filter(i => i.startsWith("convert_"))) { fs.copyFileSync("../converter/" + file, "./work/root/sdk/Atomic/SDK/" + file); } console.log("# Preparing standalone launcher"); fs.mkdirSync("./work/root/launcher"); fs.mkdirSync("./work/root/launcher/Atomic"); fs.mkdirSync("./work/root/launcher/Atomic/Launcher"); for (let file of fs.readdirSync("../converter/").filter(i => i.startsWith("launcher-"))) { fs.copyFileSync("../converter/" + file, "./work/root/launcher/Atomic/Launcher/" + file); } console.log("# Generating installer"); let data = plist['parse'](fs.readFileSync("./Atomic-x64.pkgproj").toString()); data["PACKAGES"].filter(i => i["PACKAGE_SETTINGS"]["NAME"] === "Atomic Runtime")[0]["PACKAGE_SETTINGS"]["VERSION"] = version; fs.writeFileSync("./Atomic-x64-work.pkgproj", plist['build'](data) .replaceAll(" ", "\t") .replace(/^\t(?=|<\/dict>)|^\t(?=\t(?=[<\t]))/gm, "") .replaceAll("", "") .replaceAll("", "") ); data = plist['parse'](fs.readFileSync("./Atomic-ARM.pkgproj").toString()); data["PACKAGES"].filter(i => i["PACKAGE_SETTINGS"]["NAME"] === "Atomic Runtime")[0]["PACKAGE_SETTINGS"]["VERSION"] = version; fs.writeFileSync("./Atomic-ARM-work.pkgproj", plist['build'](data) .replaceAll(" ", "\t") .replace(/^\t(?=|<\/dict>)|^\t(?=\t(?=[<\t]))/gm, "") .replaceAll("", "") .replaceAll("", "") ); cp.execSync("packagesbuild ./Atomic-x64-work.pkgproj", { stdio: "inherit" }); cp.execSync("packagesbuild ./Atomic-ARM-work.pkgproj", { stdio: "inherit" }); console.log("# Cleaning up"); fs.renameSync("./build/ARM/Atomic.pkg", "./build/Atomic-Mac-ARM64.pkg"); fs.renameSync("./build/x64/Atomic.pkg", "./build/Atomic-Mac-x64.pkg"); fs.rmdirSync("./build/ARM"); fs.rmdirSync("./build/x64"); fs.rmSync("./work", { recursive: true }); fs.rmSync("./Atomic-ARM-work.pkgproj"); fs.rmSync("./Atomic-x64-work.pkgproj"); console.log("# Publishing to GitLab"); cp.execSync(`curl -v --header "PRIVATE-TOKEN: $(cat ~/.deploy.txt)" --header "Content-Type: multipart/form-data" --upload-file Atomic-Mac-ARM64.pkg https://source.equestria.dev/api/v4/projects/186/packages/generic/atomic/${version}/Atomic-Mac-ARM64.pkg`, { cwd: "./build" }); cp.execSync(`curl -v --header "PRIVATE-TOKEN: $(cat ~/.deploy.txt)" --header "Content-Type: multipart/form-data" --upload-file Atomic-Mac-x64.pkg https://source.equestria.dev/api/v4/projects/186/packages/generic/atomic/${version}/Atomic-Mac-x64.pkg`, { cwd: "./build" });