virtualcode 1.4.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 +13 -45
  2. package/package.json +1 -1
package/install.js CHANGED
@@ -1,11 +1,8 @@
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
7
  function findConfig(start, name) {
11
8
  const candidates = [
@@ -20,53 +17,24 @@ function findConfig(start, name) {
20
17
  return null
21
18
  }
22
19
 
23
- function setup() {
24
- const configPath = findConfig(process.cwd(), "opencode.jsonc") || findConfig(process.cwd(), "opencode.json") || join(XDG_CONFIG, "opencode.jsonc")
25
-
20
+ function addToConfig(filename) {
21
+ const path = findConfig(process.cwd(), filename) || join(XDG_CONFIG, filename)
26
22
  let config = { plugin: [] }
27
- if (existsSync(configPath)) {
23
+ if (existsSync(path)) {
28
24
  try {
29
- config = JSON.parse(readFileSync(configPath, "utf-8"))
25
+ config = JSON.parse(readFileSync(path, "utf-8"))
30
26
  } catch {
31
27
  config = { plugin: [] }
32
28
  }
33
29
  }
34
-
35
30
  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
- }
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: [] }
50
- }
51
- }
52
-
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
- }
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)
70
36
  }
71
37
 
72
- 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.4.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",