@soyjuanpiece/jpcode 1.0.0 → 1.0.1
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/bin/install-plugin.mjs +15 -7
- package/bin/jpcode.mjs +19 -6
- package/package.json +2 -2
package/bin/install-plugin.mjs
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Postinstall: registra el plugin JpCode en el tui.json del usuario para que
|
|
3
3
|
// `opencode` también lo cargue si se invoca directamente. Idempotente.
|
|
4
|
+
// Usa ruta absoluta plana (formato que el loader de opencode reconoce como
|
|
5
|
+
// path-plugin en todos los OS) y limpia entradas rotas de versiones previas.
|
|
4
6
|
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs"
|
|
5
7
|
import path from "node:path"
|
|
6
8
|
import os from "node:os"
|
|
9
|
+
import { fileURLToPath } from "node:url"
|
|
7
10
|
|
|
8
11
|
try {
|
|
9
12
|
const base =
|
|
@@ -13,14 +16,19 @@ try {
|
|
|
13
16
|
if (existsSync(cfgPath)) {
|
|
14
17
|
cfg = JSON.parse(readFileSync(cfgPath, "utf8"))
|
|
15
18
|
}
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
const pkgRoot = path.dirname(path.dirname(fileURLToPath(import.meta.url)))
|
|
20
|
+
const pluginDir = path.join(pkgRoot, "plugin")
|
|
21
|
+
const stale = new Set([
|
|
22
|
+
`file:${pluginDir}`,
|
|
23
|
+
`file:${pluginDir.replace(/\\/g, "/")}`,
|
|
24
|
+
`file://${pluginDir}`,
|
|
25
|
+
`file:///${pluginDir.replace(/\\/g, "/")}`,
|
|
26
|
+
])
|
|
27
|
+
const plugins = (Array.isArray(cfg.plugin) ? cfg.plugin : []).filter(
|
|
28
|
+
(p) => typeof p !== "string" || !stale.has(p),
|
|
20
29
|
)
|
|
21
|
-
|
|
22
|
-
plugins
|
|
23
|
-
const next = { ...cfg, plugin: [...plugins] }
|
|
30
|
+
if (!plugins.includes(pluginDir)) plugins.push(pluginDir)
|
|
31
|
+
const next = { ...cfg, plugin: plugins }
|
|
24
32
|
if (!next.theme) next.theme = "claude"
|
|
25
33
|
mkdirSync(path.dirname(cfgPath), { recursive: true })
|
|
26
34
|
writeFileSync(cfgPath, JSON.stringify(next, null, 2) + "\n")
|
package/bin/jpcode.mjs
CHANGED
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
// JpCode launcher: asegura que el plugin/tema estén registrados y executa el
|
|
3
3
|
// motor opencode (instalado como dependencia de este paquete).
|
|
4
4
|
import { createRequire } from "node:module"
|
|
5
|
-
import { existsSync
|
|
5
|
+
import { existsSync } from "node:fs"
|
|
6
6
|
import { spawnSync } from "node:child_process"
|
|
7
7
|
import path from "node:path"
|
|
8
8
|
import os from "node:os"
|
|
9
|
+
import { fileURLToPath } from "node:url"
|
|
9
10
|
|
|
10
11
|
const require = createRequire(import.meta.url)
|
|
12
|
+
const pkgRoot = path.dirname(path.dirname(fileURLToPath(import.meta.url)))
|
|
13
|
+
const pluginDir = path.join(pkgRoot, "plugin")
|
|
11
14
|
|
|
12
15
|
function packageDir() {
|
|
13
16
|
try {
|
|
@@ -25,18 +28,28 @@ function tuiConfigPath() {
|
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
// Registra el plugin embebido de JpCode en el tui.json del usuario (una vez).
|
|
28
|
-
//
|
|
31
|
+
// Usa ruta absoluta plana: es el formato de path-plugin que opencode reconoce
|
|
32
|
+
// en todos los OS (file:/X o file:C:\ no cumplen el check file:// del loader).
|
|
33
|
+
// Limpia entradas rotas de versiones anteriores y respeta plugins del usuario.
|
|
29
34
|
function ensurePluginRegistered() {
|
|
30
35
|
try {
|
|
36
|
+
const { readFileSync, writeFileSync, mkdirSync } = require("node:fs")
|
|
31
37
|
const cfgPath = tuiConfigPath()
|
|
32
38
|
let cfg = {}
|
|
33
39
|
if (existsSync(cfgPath)) {
|
|
34
40
|
cfg = JSON.parse(readFileSync(cfgPath, "utf8"))
|
|
35
41
|
}
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
const stale = new Set([
|
|
43
|
+
`file:${pluginDir}`,
|
|
44
|
+
`file:${pluginDir.replace(/\\/g, "/")}`,
|
|
45
|
+
`file://${pluginDir}`,
|
|
46
|
+
`file:///${pluginDir.replace(/\\/g, "/")}`,
|
|
47
|
+
])
|
|
48
|
+
const plugins = (Array.isArray(cfg.plugin) ? cfg.plugin : []).filter(
|
|
49
|
+
(p) => typeof p !== "string" || !stale.has(p),
|
|
50
|
+
)
|
|
51
|
+
if (!plugins.includes(pluginDir)) plugins.push(pluginDir)
|
|
52
|
+
const next = { ...cfg, plugin: plugins }
|
|
40
53
|
if (!next.theme) next.theme = "claude"
|
|
41
54
|
mkdirSync(path.dirname(cfgPath), { recursive: true })
|
|
42
55
|
writeFileSync(cfgPath, JSON.stringify(next, null, 2) + "\n")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soyjuanpiece/jpcode",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "JpCode — la CLI de opencode con identidad visual propia: banner JPCODE, tema claude, /cost, /memory y layout adaptativo. Motor opencode real, solo rediseñado por fuera.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,4 +34,4 @@
|
|
|
34
34
|
"type": "git",
|
|
35
35
|
"url": "git+https://github.com/SoyJuanPiece/jpcode.git"
|
|
36
36
|
}
|
|
37
|
-
}
|
|
37
|
+
}
|