@sksoftofficial/ocduet 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,86 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { dataDir, opencodeConfigDir, pluginDir } from "../paths.js";
4
+ import { stop } from "./service.js";
5
+
6
+ function unpatchConfig() {
7
+ const dir = opencodeConfigDir();
8
+ for (const name of ["opencode.jsonc", "opencode.json"]) {
9
+ const p = path.join(dir, name);
10
+ if (!fs.existsSync(p)) continue;
11
+ const text = fs.readFileSync(p, "utf8");
12
+ const re = new RegExp(`^\\s*"file://[^"]*ocduet-server\\.js",?\\s*\\n?`, "m");
13
+ if (!re.test(text)) continue;
14
+ let next = text.replace(re, "");
15
+ // clean a dangling ",\n]" left behind when we removed the last entry
16
+ next = next.replace(/,(\s*\]\s*\n?\s*\])/g, "$1");
17
+ fs.writeFileSync(p, next);
18
+ return p;
19
+ }
20
+ return null;
21
+ }
22
+
23
+ function unpatchTuiJson() {
24
+ const p = path.join(opencodeConfigDir(), "tui.json");
25
+ if (!fs.existsSync(p)) return null;
26
+ let cfg;
27
+ try {
28
+ cfg = JSON.parse(fs.readFileSync(p, "utf8"));
29
+ } catch {
30
+ return null;
31
+ }
32
+ if (!cfg || !Array.isArray(cfg.plugin)) return null;
33
+ const before = cfg.plugin.length;
34
+ cfg.plugin = cfg.plugin.filter((e) => {
35
+ if (e === "./plugin/ocduet-sidebar.tsx") return false;
36
+ if (Array.isArray(e) && e[0] === "./plugin/ocduet-sidebar.tsx") return false;
37
+ return true;
38
+ });
39
+ if (cfg.plugin.length === before) return null;
40
+ fs.writeFileSync(p, JSON.stringify(cfg, null, 2) + "\n");
41
+ return p;
42
+ }
43
+
44
+ export async function uninstall(argv = []) {
45
+ const purge = argv.includes("--purge");
46
+ await stop([]);
47
+ const pdir = pluginDir();
48
+ const removed = [];
49
+
50
+ const ddir = dataDir();
51
+ for (const f of ["ocduet-server.js", "ocduet-sidebar.tsx", "ocduet-installation.json"]) {
52
+ const p = path.join(pdir, f);
53
+ if (fs.existsSync(p)) {
54
+ fs.rmSync(p);
55
+ removed.push(p);
56
+ }
57
+ }
58
+ const webDir = path.join(pdir, "ocduet-web");
59
+ if (fs.existsSync(webDir)) {
60
+ fs.rmSync(webDir, { recursive: true });
61
+ removed.push(webDir);
62
+ }
63
+
64
+ const configPatched = unpatchConfig();
65
+ if (configPatched) console.log(`removed plugin entry from: ${configPatched}`);
66
+
67
+ const tuiPatched = unpatchTuiJson();
68
+ if (tuiPatched) console.log(`removed TUI sidebar entry from: ${tuiPatched}`);
69
+
70
+ const qrLib = path.join(ddir, "qrcodegen.js");
71
+ if (fs.existsSync(qrLib)) {
72
+ fs.rmSync(qrLib);
73
+ removed.push(qrLib);
74
+ }
75
+ if (purge && fs.existsSync(ddir)) {
76
+ fs.rmSync(ddir, { recursive: true });
77
+ removed.push(ddir);
78
+ }
79
+
80
+ if (removed.length === 0 && !configPatched && !tuiPatched) {
81
+ console.log("nothing to remove");
82
+ return;
83
+ }
84
+ for (const p of removed) console.log(`removed: ${p}`);
85
+ console.log(purge ? "fully uninstalled (token and state deleted)" : "uninstalled (token kept; use --purge to delete it)");
86
+ }