virtualcode 1.0.1 → 1.0.2
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 +17 -11
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs"
|
|
2
2
|
import { join, dirname } from "node:path"
|
|
3
|
+
import { homedir } from "node:os"
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
const XDG_CONFIG = join(homedir(), ".config", "opencode")
|
|
6
|
+
|
|
7
|
+
function findConfig(start) {
|
|
8
|
+
const candidates = [
|
|
9
|
+
join(start, ".opencode", "opencode.jsonc"),
|
|
10
|
+
join(start, ".opencode", "opencode.json"),
|
|
11
|
+
join(start, "opencode.jsonc"),
|
|
12
|
+
join(start, "opencode.json"),
|
|
13
|
+
]
|
|
14
|
+
for (const p of candidates) {
|
|
15
|
+
if (existsSync(p)) return p
|
|
12
16
|
}
|
|
17
|
+
|
|
18
|
+
const parent = dirname(start)
|
|
19
|
+
if (parent !== start) return findConfig(parent)
|
|
13
20
|
return null
|
|
14
21
|
}
|
|
15
22
|
|
|
16
23
|
function setup() {
|
|
17
|
-
const
|
|
18
|
-
const configPath = findOpencodeConfig(cwd) || join(cwd, ".opencode", "opencode.json")
|
|
24
|
+
const configPath = findConfig(process.cwd()) || join(XDG_CONFIG, "opencode.jsonc")
|
|
19
25
|
|
|
20
26
|
let config = { plugins: [] }
|
|
21
27
|
if (existsSync(configPath)) {
|
|
@@ -33,7 +39,7 @@ function setup() {
|
|
|
33
39
|
|
|
34
40
|
mkdirSync(dirname(configPath), { recursive: true })
|
|
35
41
|
writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n")
|
|
36
|
-
console.log("[virtualcode] Added to
|
|
42
|
+
console.log("[virtualcode] Added to " + configPath)
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
setup()
|