-
Notifications
You must be signed in to change notification settings - Fork 0
/
bun.config.js
81 lines (72 loc) · 2.02 KB
/
bun.config.js
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
81
import { build } from "bun";
import * as path from "path";
import * as fs from "fs";
import pkg from "./module.json";
import archiver from "archiver";
import ModFS from "modfs";
import { stringify } from "ini";
function archiveFolder(sourceDir, outputFilePath) {
if (!fs.existsSync("dist")) {
fs.mkdirSync("dist", { recursive: true });
}
// Create a file to stream archive data to.
const output = fs.createWriteStream(outputFilePath);
const archive = archiver("zip", {
zlib: { level: 9 }, // Sets the compression level.
});
// Listen for all archive data to be written.
output.on("close", () => {
console.log(`${archive.pointer()} total bytes`);
console.log(
"Archiver has been finalized and the output file descriptor has closed."
);
});
// Good practice to catch warnings (e.g. stat failures) explicitly.
archive.on("warning", (err) => {
if (err.code !== "ENOENT") {
throw err;
}
console.warn(err);
});
// Good practice to catch this error explicitly.
archive.on("error", (err) => {
throw err;
});
// Pipe archive data to the file.
archive.pipe(output);
// Append files from sourceDir.
archive.directory(sourceDir, false);
// Finalize the archive (i.e. we are done appending files but streams have to finish yet).
archive.finalize();
}
const modfs = new ModFS(pkg.metadata);
build({
entrypoints: [path.resolve(__dirname, pkg.build.modconf)],
naming: "[dir]/[name].jsx",
outdir: path.resolve(
__dirname,
"magisk/system/usr/share/mmrl/config",
pkg.metadata.id
),
target: "browser",
format: "esm",
external: [
"react",
"@mmrl/*",
"@mui/*",
"default-composer",
"modfs",
"flatlist-react",
],
minify: true,
}).then((res) => {
console.log(res);
const prop = stringify(modfs.formatEntries());
fs.writeFileSync(
path.resolve(__dirname, "magisk/module.prop"),
prop,
"utf-8"
);
const output = `dist/${modfs.format(pkg.dist.moduleFileName)}`;
archiveFolder(path.resolve(__dirname, "magisk"), output);
});