virtualcode 1.0.1 → 1.0.3

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.
Files changed (2) hide show
  1. package/install.js +22 -16
  2. package/package.json +1 -1
package/install.js CHANGED
@@ -1,39 +1,45 @@
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
- function findOpencodeConfig(start) {
5
- let dir = start
6
- for (let i = 0; i < 10; i++) {
7
- const candidate = join(dir, ".opencode", "opencode.json")
8
- if (existsSync(candidate)) return candidate
9
- const parent = dirname(dir)
10
- if (parent === dir) break
11
- dir = parent
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 cwd = process.cwd()
18
- const configPath = findOpencodeConfig(cwd) || join(cwd, ".opencode", "opencode.json")
24
+ const configPath = findConfig(process.cwd()) || join(XDG_CONFIG, "opencode.jsonc")
19
25
 
20
- let config = { plugins: [] }
26
+ let config = { plugin: [] }
21
27
  if (existsSync(configPath)) {
22
28
  try {
23
29
  config = JSON.parse(readFileSync(configPath, "utf-8"))
24
30
  } catch {
25
- config = { plugins: [] }
31
+ config = { plugin: [] }
26
32
  }
27
33
  }
28
34
 
29
- if (!Array.isArray(config.plugins)) config.plugins = []
30
- if (config.plugins.includes("virtualcode")) return
35
+ if (!Array.isArray(config.plugin)) config.plugin = []
36
+ if (config.plugin.includes("virtualcode")) return
31
37
 
32
- config.plugins.push("virtualcode")
38
+ config.plugin.push("virtualcode")
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 .opencode/opencode.json")
42
+ console.log("[virtualcode] Added to " + configPath)
37
43
  }
38
44
 
39
45
  setup()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "virtualcode",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "OpenCode plugin that bridges your terminal sessions with Telegram",
5
5
  "type": "module",
6
6
  "license": "MIT",