virtualcode 1.2.2 → 1.4.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 +39 -19
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
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
|
-
function findConfig(start) {
|
|
10
|
+
function findConfig(start, name) {
|
|
8
11
|
const candidates = [
|
|
9
|
-
join(start, ".opencode",
|
|
10
|
-
join(start,
|
|
11
|
-
join(start, "opencode.jsonc"),
|
|
12
|
-
join(start, "opencode.json"),
|
|
12
|
+
join(start, ".opencode", name),
|
|
13
|
+
join(start, name),
|
|
13
14
|
]
|
|
14
15
|
for (const p of candidates) {
|
|
15
16
|
if (existsSync(p)) return p
|
|
16
17
|
}
|
|
17
|
-
|
|
18
18
|
const parent = dirname(start)
|
|
19
|
-
if (parent !== start) return findConfig(parent)
|
|
19
|
+
if (parent !== start) return findConfig(parent, name)
|
|
20
20
|
return null
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
function setup() {
|
|
24
|
-
const configPath = findConfig(process.cwd()) || join(XDG_CONFIG, "opencode.jsonc")
|
|
24
|
+
const configPath = findConfig(process.cwd(), "opencode.jsonc") || findConfig(process.cwd(), "opencode.json") || join(XDG_CONFIG, "opencode.jsonc")
|
|
25
25
|
|
|
26
26
|
let config = { plugin: [] }
|
|
27
27
|
if (existsSync(configPath)) {
|
|
@@ -33,20 +33,40 @@ function setup() {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
if (!Array.isArray(config.plugin)) config.plugin = []
|
|
36
|
+
if (!config.plugin.includes("virtualcode")) {
|
|
37
|
+
config.plugin.unshift("virtualcode")
|
|
38
|
+
mkdirSync(dirname(configPath), { recursive: true })
|
|
39
|
+
writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n")
|
|
40
|
+
console.log("[virtualcode] Added to " + configPath)
|
|
41
|
+
}
|
|
36
42
|
|
|
37
|
-
const
|
|
38
|
-
let
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
const tuiPath = findConfig(process.cwd(), "tui.json") || join(XDG_CONFIG, "tui.json")
|
|
44
|
+
let tuiConfig = { plugin: [] }
|
|
45
|
+
if (existsSync(tuiPath)) {
|
|
46
|
+
try {
|
|
47
|
+
tuiConfig = JSON.parse(readFileSync(tuiPath, "utf-8"))
|
|
48
|
+
} catch {
|
|
49
|
+
tuiConfig = { plugin: [] }
|
|
43
50
|
}
|
|
44
51
|
}
|
|
45
|
-
if (!changed) return
|
|
46
52
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
if (!Array.isArray(tuiConfig.plugin)) tuiConfig.plugin = []
|
|
54
|
+
|
|
55
|
+
const tuiRef = "./plugins/virtualcode-tui.js"
|
|
56
|
+
if (!tuiConfig.plugin.includes(tuiRef)) {
|
|
57
|
+
tuiConfig.plugin.push(tuiRef)
|
|
58
|
+
mkdirSync(dirname(tuiPath), { recursive: true })
|
|
59
|
+
writeFileSync(tuiPath, JSON.stringify(tuiConfig, null, 2) + "\n")
|
|
60
|
+
console.log("[virtualcode] TUI plugin registered in " + tuiPath)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const tuiSrc = join(__dirname, "dist", "tui.js")
|
|
64
|
+
const tuiDest = join(PLUGINS_DIR, "virtualcode-tui.js")
|
|
65
|
+
if (existsSync(tuiSrc)) {
|
|
66
|
+
mkdirSync(PLUGINS_DIR, { recursive: true })
|
|
67
|
+
copyFileSync(tuiSrc, tuiDest)
|
|
68
|
+
console.log("[virtualcode] TUI plugin file copied to " + tuiDest)
|
|
69
|
+
}
|
|
50
70
|
}
|
|
51
71
|
|
|
52
72
|
setup()
|