virtualcode 1.2.2 → 1.3.0
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.
- package/install.js +19 -11
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs"
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, copyFileSync } from "node:fs"
|
|
2
2
|
import { join, dirname } from "node:path"
|
|
3
3
|
import { homedir } from "node:os"
|
|
4
|
+
import { fileURLToPath } from "node:url"
|
|
4
5
|
|
|
6
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
5
7
|
const XDG_CONFIG = join(homedir(), ".config", "opencode")
|
|
8
|
+
const PLUGINS_DIR = join(XDG_CONFIG, "plugins")
|
|
6
9
|
|
|
7
10
|
function findConfig(start) {
|
|
8
11
|
const candidates = [
|
|
@@ -14,7 +17,6 @@ function findConfig(start) {
|
|
|
14
17
|
for (const p of candidates) {
|
|
15
18
|
if (existsSync(p)) return p
|
|
16
19
|
}
|
|
17
|
-
|
|
18
20
|
const parent = dirname(start)
|
|
19
21
|
if (parent !== start) return findConfig(parent)
|
|
20
22
|
return null
|
|
@@ -34,19 +36,25 @@ function setup() {
|
|
|
34
36
|
|
|
35
37
|
if (!Array.isArray(config.plugin)) config.plugin = []
|
|
36
38
|
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (!config.plugin.includes(entry)) {
|
|
41
|
-
config.plugin.push(entry)
|
|
42
|
-
changed = true
|
|
43
|
-
}
|
|
39
|
+
const oldTui = "virtualcode/tui"
|
|
40
|
+
if (config.plugin.includes(oldTui)) {
|
|
41
|
+
config.plugin = config.plugin.filter((p) => p !== oldTui)
|
|
44
42
|
}
|
|
45
|
-
if (!changed) return
|
|
46
43
|
|
|
44
|
+
if (!config.plugin.includes("virtualcode")) {
|
|
45
|
+
config.plugin.unshift("virtualcode")
|
|
46
|
+
}
|
|
47
47
|
mkdirSync(dirname(configPath), { recursive: true })
|
|
48
48
|
writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n")
|
|
49
|
-
console.log("[virtualcode]
|
|
49
|
+
console.log("[virtualcode] Updated " + configPath)
|
|
50
|
+
|
|
51
|
+
const tuiSrc = join(__dirname, "dist", "tui.js")
|
|
52
|
+
const tuiDest = join(PLUGINS_DIR, "virtualcode-tui.js")
|
|
53
|
+
if (existsSync(tuiSrc)) {
|
|
54
|
+
mkdirSync(PLUGINS_DIR, { recursive: true })
|
|
55
|
+
copyFileSync(tuiSrc, tuiDest)
|
|
56
|
+
console.log("[virtualcode] TUI plugin copied to " + tuiDest)
|
|
57
|
+
}
|
|
50
58
|
}
|
|
51
59
|
|
|
52
60
|
setup()
|