This repository has been archived by the owner on May 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.mjs
75 lines (66 loc) · 2.32 KB
/
build.mjs
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
// Derived from Vendetta's build script
import swc from "@swc/core";
import { execSync } from "child_process";
import esbuild from "esbuild";
import { argv } from "process";
const flags = argv.slice(2).filter(arg => arg.startsWith("--")).map(arg => arg.slice(2));
const isDev = !flags.includes("release");
const commitHash = execSync("git rev-parse --short HEAD").toString().trim();
console.log(`Building with commit hash ${commitHash}, isDev=${isDev}`);
const buildOutput = "dist/pyoncord.js";
/** @type {import("esbuild").Plugin} */
const swcPlugin = {
name: "swc",
setup(build) {
build.onLoad({ filter: /\.[jt]sx?/ }, async args => {
const result = await swc.transformFile(args.path, {
jsc: {
externalHelpers: true,
},
env: {
targets: "defaults",
include: [
"transform-classes",
"transform-arrow-functions",
],
},
});
return { contents: result.code };
});
}
};
await esbuild.build({
entryPoints: ["entry.js"],
bundle: true,
minify: !isDev,
format: "iife",
target: "esnext",
outfile: buildOutput,
footer: {
js: "//# sourceURL=pyoncord",
},
define: {
__PYONCORD_COMMIT_HASH__: JSON.stringify(commitHash),
__PYONCORD_DEV__: JSON.stringify(isDev),
},
legalComments: "none",
alias: {
"@/*": "./src/*"
},
plugins: [
swcPlugin
]
});
console.log("Build complete!");
if (flags.includes("deploy-root")) {
console.log("Deploying to device with root...");
// Hardcode stuff because I'm lazy :trollface:
const packageName = "com.discord";
// Make sure to configure the loader to load from an invalid URL so it uses the cache
// This is still an issue because the cache is cleared intervally so we need to make our own loader
execSync("adb wait-for-device root");
execSync(`adb shell am force-stop ${packageName}`);
// execSync(`adb push ${buildOutput} sdcard/Documents/pyoncord/pyoncord/cache/pyoncord.js`);
execSync(`adb push ${buildOutput} /data/data/${packageName}/files/pyoncord/cache/pyoncord.js`);
execSync(`adb shell am start ${packageName}/com.discord.main.MainActivity`);
}