summaryrefslogtreecommitdiff
path: root/build.js
blob: 9a3551d6ddaa1cce08474c9f2af108a452d13798 (plain)
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
#!/usr/bin/env node
const fs = require('fs');
const zlib = require('zlib');
const child_process = require("child_process");
const crypto = require("crypto");

console.log("Note: use './build.js launcher' to build the launchers.");

let ignore = [
    "bans.json",
    "verify.json",
    "motd.md",
    "remote.lctsc",
    "local.lctsc",
    "debug",
    "build",
    "server.txt",
    ".DS_Store",
    "Electron.app"
];

function scandir(path) {
    let list = [];
    list.push(path);

    for (let file of fs.readdirSync(path)) {
        if (fs.lstatSync(path + "/" + file).isDirectory()) {
            if (!ignore.includes(file)) {
                list.push(path + "/" + file);
                list.push(...scandir(path + "/" + file));
            }
        } else {
            if (!ignore.includes(file)) list.push(path + "/" + file);
        }
    }

    return list;
}

let list = scandir("./client");
let pack = [];

function processFile(item) {
    if (item.endsWith("main.js")) {
        let data = fs.readFileSync(item).toString();
        data = data.replace(/\/\/ --- >START< @BUILDNUMBER@ >START< --- \/\/\n((.|\n)*)\n\/\/ --- >FINAL< @BUILDNUMBER@ >FINAL< --- \/\/\n\n/gm, "// --- >START< @BUILDNUMBER@ >START< --- //\nconst buildNumber = \"" + new Date().toISOString().split("T")[0] + "\";\n// --- >FINAL< @BUILDNUMBER@ >FINAL< --- //\n\n");
        return Buffer.from(data);
    } else {
        return fs.readFileSync(item);
    }
}

for (let item of list) {
    if (fs.lstatSync(item).isDirectory()) {
        pack.push({
            type: "directory",
            name: item,
            content: null
        });
    } else {
        pack.push({
            type: "file",
            name: item,
            content: zlib.brotliCompressSync(processFile(item)).toString("base64"),
            hash: crypto.createHash("sha256").update(processFile(item)).digest("base64")
        });
    }
}

fs.writeFileSync("build/client.lctpk", zlib.brotliCompressSync(JSON.stringify(pack)));

child_process.execSync("scp build/client.lctpk bridlewood:/opt/localchat/update/client.stable.lctpk", { stdio: "inherit" });
child_process.execSync("scp build/client.lctpk bridlewood:/opt/localchat/update/client.beta.lctpk", { stdio: "inherit" });
child_process.execSync("scp build/client.lctpk bridlewood:/opt/localchat/update/client.lctpk", { stdio: "inherit" });

if (process.argv[2] === "launcher") {
    child_process.execSync("npx electron-packager . Chatroom --ignore build --ignore scripts --overwrite --icon icon.icns --platform=darwin --arch=arm64 --out=../../build/client", { cwd: "./launcher/client", stdio: "inherit" })
    child_process.execSync("npx electron-packager . Chatroom --ignore build --ignore scripts --overwrite --icon icon.icns --platform=win32 --arch=x64 --out=../../build/client", { cwd: "./launcher/client", stdio: "inherit" })
    child_process.execSync("npx electron-packager . Chatroom --ignore build --ignore scripts --overwrite --icon icon.png --platform=linux --arch=x64 --out=../../build/client", { cwd: "./launcher/client", stdio: "inherit" })
}