virtualcode 1.3.0 → 1.5.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.
Files changed (2) hide show
  1. package/install.js +17 -37
  2. package/package.json +1 -1
package/install.js CHANGED
@@ -1,60 +1,40 @@
1
- import { existsSync, readFileSync, writeFileSync, mkdirSync, copyFileSync } from "node:fs"
1
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs"
2
2
  import { join, dirname } from "node:path"
3
3
  import { homedir } from "node:os"
4
- import { fileURLToPath } from "node:url"
5
4
 
6
- const __dirname = dirname(fileURLToPath(import.meta.url))
7
5
  const XDG_CONFIG = join(homedir(), ".config", "opencode")
8
- const PLUGINS_DIR = join(XDG_CONFIG, "plugins")
9
6
 
10
- function findConfig(start) {
7
+ function findConfig(start, name) {
11
8
  const candidates = [
12
- join(start, ".opencode", "opencode.jsonc"),
13
- join(start, ".opencode", "opencode.json"),
14
- join(start, "opencode.jsonc"),
15
- join(start, "opencode.json"),
9
+ join(start, ".opencode", name),
10
+ join(start, name),
16
11
  ]
17
12
  for (const p of candidates) {
18
13
  if (existsSync(p)) return p
19
14
  }
20
15
  const parent = dirname(start)
21
- if (parent !== start) return findConfig(parent)
16
+ if (parent !== start) return findConfig(parent, name)
22
17
  return null
23
18
  }
24
19
 
25
- function setup() {
26
- const configPath = findConfig(process.cwd()) || join(XDG_CONFIG, "opencode.jsonc")
27
-
20
+ function addToConfig(filename) {
21
+ const path = findConfig(process.cwd(), filename) || join(XDG_CONFIG, filename)
28
22
  let config = { plugin: [] }
29
- if (existsSync(configPath)) {
23
+ if (existsSync(path)) {
30
24
  try {
31
- config = JSON.parse(readFileSync(configPath, "utf-8"))
25
+ config = JSON.parse(readFileSync(path, "utf-8"))
32
26
  } catch {
33
27
  config = { plugin: [] }
34
28
  }
35
29
  }
36
-
37
30
  if (!Array.isArray(config.plugin)) config.plugin = []
38
-
39
- const oldTui = "virtualcode/tui"
40
- if (config.plugin.includes(oldTui)) {
41
- config.plugin = config.plugin.filter((p) => p !== oldTui)
42
- }
43
-
44
- if (!config.plugin.includes("virtualcode")) {
45
- config.plugin.unshift("virtualcode")
46
- }
47
- mkdirSync(dirname(configPath), { recursive: true })
48
- writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n")
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
- }
31
+ if (config.plugin.includes("virtualcode")) return
32
+ config.plugin.unshift("virtualcode")
33
+ mkdirSync(dirname(path), { recursive: true })
34
+ writeFileSync(path, JSON.stringify(config, null, 2) + "\n")
35
+ console.log("[virtualcode] Added to " + path)
58
36
  }
59
37
 
60
- setup()
38
+ addToConfig("opencode.jsonc")
39
+ addToConfig("opencode.json")
40
+ addToConfig("tui.json")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "virtualcode",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "OpenCode plugin that bridges your terminal sessions with Telegram",
5
5
  "type": "module",
6
6
  "license": "MIT",