forked from panta82/opencode-notificator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
executable file
·103 lines (87 loc) · 2.5 KB
/
deploy.js
File metadata and controls
executable file
·103 lines (87 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env node
import { execSync } from 'child_process'
import { readFileSync, rmSync, existsSync, mkdirSync, copyFileSync, readdirSync, statSync } from 'fs'
import { join } from 'path'
import { homedir } from 'os'
const PLUGINS_DIR = {
linux: join(homedir(), '.config', 'opencode', 'plugin'),
darwin: join(homedir(), '.config', 'opencode', 'plugin'),
win32: join(process.env.APPDATA || join(homedir(), 'AppData', 'Roaming'), 'opencode', 'plugin')
}
function getPluginsDir() {
const dir = PLUGINS_DIR[process.platform]
if (!dir) {
console.error(`Unsupported platform: ${process.platform}`)
process.exit(1)
}
return dir
}
function copyRecursive(src, dest) {
const stat = statSync(src)
if (stat.isDirectory()) {
if (!existsSync(dest)) {
mkdirSync(dest, { recursive: true })
}
const files = readdirSync(src)
for (const file of files) {
copyRecursive(join(src, file), join(dest, file))
}
} else {
copyFileSync(src, dest)
}
}
function build() {
console.log('Building plugin...')
try {
execSync('npm run build', { stdio: 'inherit' })
console.log('✓ Build complete')
} catch (error) {
console.error('✗ Build failed')
process.exit(1)
}
}
function install() {
const pluginsDir = getPluginsDir()
console.log(`Installing to ${pluginsDir}...`)
const distDir = 'dist'
if (!existsSync(distDir)) {
console.error('✗ dist/ directory not found. Run build first.')
process.exit(1)
}
const files = readdirSync(distDir)
for (const file of files) {
const srcPath = join(distDir, file)
const destPath = join(pluginsDir, file)
if (existsSync(destPath)) {
const stat = statSync(destPath)
if (stat.isDirectory()) {
console.log(` Removing existing ${file}/`)
rmSync(destPath, { recursive: true, force: true })
} else {
if (file === 'notificator.jsonc') {
console.log(` Preserving existing ${file}`)
continue
}
console.log(` Removing existing ${file}`)
rmSync(destPath, { force: true })
}
}
}
console.log(' Copying files...')
copyRecursive(distDir, pluginsDir)
console.log('✓ Installation complete')
}
function main() {
const args = process.argv.slice(2)
const buildOnly = args.includes('--build-only') || args.includes('-b')
const installOnly = args.includes('--install-only') || args.includes('-i')
if (buildOnly) {
build()
} else if (installOnly) {
install()
} else {
build()
install()
}
}
main()