forked from PurpleAILAB/Vigilo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostinstall.mjs
More file actions
121 lines (100 loc) · 3.3 KB
/
postinstall.mjs
File metadata and controls
121 lines (100 loc) · 3.3 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { createRequire } from "node:module";
import { promises as fs } from "node:fs";
import { join, dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { homedir } from "node:os";
import { getPlatformPackage, getBinaryPath } from "./bin/platform.js";
const require = createRequire(import.meta.url);
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
function getLibcFamily() {
if (process.platform !== "linux") {
return undefined;
}
try {
const detectLibc = require("detect-libc");
return detectLibc.familySync();
} catch {
return null;
}
}
function getOpenCodeConfigDir() {
const home = homedir();
if (process.platform === "win32") {
return join(process.env.APPDATA || join(home, "AppData", "Roaming"), "opencode");
}
return join(process.env.XDG_CONFIG_HOME || join(home, ".config"), "opencode");
}
async function copyDir(src, dest) {
await fs.mkdir(dest, { recursive: true });
const entries = await fs.readdir(src, { withFileTypes: true });
for (const entry of entries) {
const srcPath = join(src, entry.name);
const destPath = join(dest, entry.name);
if (entry.isDirectory()) {
await copyDir(srcPath, destPath);
} else {
await fs.copyFile(srcPath, destPath);
}
}
}
async function installSkills() {
const packageSkillsDir = join(__dirname, "skills");
const targetSkillsDir = join(getOpenCodeConfigDir(), "skills");
try {
const entries = await fs.readdir(packageSkillsDir, { withFileTypes: true });
const skillDirs = entries.filter(e => e.isDirectory() && !e.name.startsWith("."));
if (skillDirs.length === 0) {
return;
}
await fs.mkdir(targetSkillsDir, { recursive: true });
let installed = 0;
let skipped = 0;
for (const skillDir of skillDirs) {
const srcSkillDir = join(packageSkillsDir, skillDir.name);
const destSkillDir = join(targetSkillsDir, skillDir.name);
// Check if skill already exists
try {
await fs.access(destSkillDir);
// Skill exists, skip to avoid overwriting user modifications
skipped++;
continue;
} catch {
// Skill doesn't exist, install it
}
await copyDir(srcSkillDir, destSkillDir);
installed++;
}
if (installed > 0) {
console.log(`✓ vigilo skills installed: ${installed} new`);
}
if (skipped > 0) {
console.log(` ${skipped} skills skipped (already exist)`);
}
} catch (error) {
// Skills directory doesn't exist in package, skip silently
if (error.code !== "ENOENT") {
console.warn(`⚠ vigilo: Failed to install skills: ${error.message}`);
}
}
}
async function installBinary() {
const { platform, arch } = process;
const libcFamily = getLibcFamily();
try {
const pkg = getPlatformPackage({ platform, arch, libcFamily });
const binPath = getBinaryPath(pkg, platform);
require.resolve(binPath);
console.log(`✓ vigilo binary installed for ${platform}-${arch}`);
} catch (error) {
console.warn(`⚠ vigilo: ${error.message}`);
console.warn(` The CLI may not work on this platform.`);
}
}
async function main() {
await Promise.all([
installBinary(),
installSkills(),
]);
}
main().catch(console.error);