40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { existsSync } from "node:fs";
|
|
import { spawnSync } from "node:child_process";
|
|
import path from "node:path";
|
|
|
|
const root = path.resolve(import.meta.dir, "..");
|
|
const args = process.argv.slice(2);
|
|
|
|
function value(flag: string): string | undefined {
|
|
const index = args.indexOf(flag);
|
|
return index >= 0 ? args[index + 1] : undefined;
|
|
}
|
|
|
|
function run(command: string, commandArgs: string[]): void {
|
|
const result = spawnSync(command, commandArgs, {
|
|
cwd: root,
|
|
stdio: "inherit",
|
|
});
|
|
if (result.error) throw result.error;
|
|
if (result.status !== 0)
|
|
throw new Error(`${command} ${commandArgs.join(" ")} failed`);
|
|
}
|
|
|
|
const serial = value("--serial");
|
|
if (!serial)
|
|
throw new Error("Specify the Xiaomi target with --serial <adb-serial>");
|
|
if (!args.includes("--confirm-reinstall"))
|
|
throw new Error("Refusing to replace an app without --confirm-reinstall");
|
|
|
|
run("bun", ["run", "patch:moannotes"]);
|
|
const apk =
|
|
value("--apk") ?? path.join(root, "outputs", "MoanNote_patched-signed.apk");
|
|
if (!existsSync(apk)) {
|
|
throw new Error(
|
|
`Signed APK is missing at ${path.join("outputs", "MoanNote_patched-signed.apk")}`,
|
|
);
|
|
}
|
|
run("adb", ["-s", serial, "install", "--no-incremental", "-r", apk]);
|
|
console.log(
|
|
`[ok] Reinstalled ${path.basename(apk)} without uninstalling MoanNotes data.`,
|
|
);
|