Spaces:
Runtime error
Runtime error
File size: 2,177 Bytes
cd8bd0a | 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 | import fs from "fs";
import os from "os";
import path from "path";
import { execSync } from "child_process";
const args = process.argv.slice(2);
const fullUninstall = args.includes("--full");
const uninstallAlreadyInProgress =
process.env.OMNIROUTE_SKIP_UNINSTALL_HOOK === "1" ||
process.env.npm_lifecycle_event === "uninstall";
console.log("π OmniRoute Uninstaller");
console.log("ββββββββββββββββββββββββββββββ");
// 1. Stop PM2 process if it exists
try {
console.log("Stopping and removing background PM2 processes...");
execSync("pm2 delete omniroute 2>/dev/null", { stdio: "ignore" });
} catch {
// It's perfectly fine if pm2 is not installed or the process doesn't exist.
}
// 2. Local AppData / Config Folder cleanup (Only on Full Uninstall)
const dataDir = process.env.DATA_DIR || path.join(os.homedir(), ".omniroute");
if (fullUninstall) {
console.log(`π§Ή Full Uninstall selected. Erasing database and files at: ${dataDir}`);
try {
if (fs.existsSync(dataDir)) {
fs.rmSync(dataDir, { recursive: true, force: true });
console.log("β
Data directory removed.");
} else {
console.log("βΉοΈ Data directory did not exist. Skipping.");
}
} catch (error) {
console.warn("β οΈ Failed to remove data directory:", error.message);
}
} else {
console.log(`πΎ Keeping data files at: ${dataDir} intact.`);
}
// 3. NPM uninstall
if (uninstallAlreadyInProgress) {
console.log("βΉοΈ npm uninstall is already in progress. Skipping nested uninstall command.");
} else {
console.log("ποΈ Removing npm package...");
try {
execSync("npm uninstall -g omniroute", {
stdio: "inherit",
env: {
...process.env,
OMNIROUTE_SKIP_UNINSTALL_HOOK: "1",
},
});
console.log("\nβ
OmniRoute has been successfully uninstalled from your system.");
if (!fullUninstall) {
console.log(`βΉοΈ Your configurations and databases were preserved in ${dataDir}.`);
}
} catch (error) {
console.warn(
"β οΈ Failed to remove npm package. You might need to run this command with 'sudo'."
);
}
}
|