Files
OmniRoute/scripts/build/uninstall.mjs
diegosouzapw f3b944a55a refactor(scripts): organize into build/dev/check/docs/i18n/ad-hoc subfolders
Reorganizes the 29 active scripts under scripts/ into purpose-driven
subfolders:

- scripts/build/    (11) — Build, install, publish, runtime env
- scripts/dev/      (13) — Dev servers, test runners, healthchecks
- scripts/check/    (10) — Lint/validation/coverage checks
- scripts/docs/      (2) — Docs index and provider reference generation
- scripts/i18n/     (+3) — Adds Python translation utilities (check/validate/autotranslate)
- scripts/ad-hoc/    (4) — One-shot maintenance utilities

Updates all references in package.json, electron/package.json,
.husky/pre-commit, .github/workflows/ci.yml, Dockerfile, src/,
tests/, scripts/ internal cross-imports, playwright.config.ts,
and English docs (CODEBASE_DOCUMENTATION, ENVIRONMENT, FEATURES,
RELEASE_CHECKLIST, COVERAGE_PLAN, ELECTRON_GUIDE, I18N, GEMINI).

Also patches scripts/build/pack-artifact-policy.ts so the npm pack
allowlist mirrors the new layout.

Validates with:
- npm run lint            (exit 0 — pre-existing minified-bundle errors only)
- npm run typecheck:core  (exit 0)
- npm run check:docs-all  (exit 0)
- unit tests for moved scripts (57 tests pass)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 10:14:25 -03:00

65 lines
2.1 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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'."
);
}
}