-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostinstall.mjs
More file actions
79 lines (65 loc) · 2.41 KB
/
postinstall.mjs
File metadata and controls
79 lines (65 loc) · 2.41 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
import { cpSync, mkdirSync, existsSync, readdirSync, readFileSync, writeFileSync } from 'fs';
import { join, dirname, relative } from 'path';
import { homedir } from 'os';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const src = join(__dirname, 'claude');
const dest = join(homedir(), '.claude');
// Copy skill and command files
try {
if (!existsSync(dest)) {
mkdirSync(dest, { recursive: true });
}
// Recursively copy claude/ to ~/.claude/
cpSync(src, dest, { recursive: true });
const files = readdirSync(src, { recursive: true, withFileTypes: true })
.filter(e => e.isFile())
.map(e => relative(src, join(e.parentPath, e.name)));
console.log(`\x1b[32m✓\x1b[0m Installed Claude files to ~/.claude/`);
for (const file of files) {
console.log(` - ${file}`);
}
} catch (err) {
console.log(`\x1b[33m⚠\x1b[0m Could not install Claude files: ${err.message}`);
}
// Add permissions to settings.json
const settingsPath = join(dest, 'settings.json');
try {
let settings = { permissions: { allow: [], deny: [] } };
if (existsSync(settingsPath)) {
settings = JSON.parse(readFileSync(settingsPath, 'utf-8'));
}
// Ensure structure exists
settings.permissions = settings.permissions || {};
settings.permissions.allow = settings.permissions.allow || [];
// Build list of permissions to add
const permissions = ['Bash(linear:*)'];
// Add Skill permissions for each skill in the skills directory
const skillsDir = join(src, 'skills');
if (existsSync(skillsDir)) {
const skills = readdirSync(skillsDir, { withFileTypes: true })
.filter(e => e.isDirectory())
.map(e => e.name);
for (const skill of skills) {
permissions.push(`Skill(${skill})`);
permissions.push(`Skill(${skill}:*)`);
}
}
// Add permissions if not already present
const added = [];
for (const permission of permissions) {
if (!settings.permissions.allow.includes(permission)) {
settings.permissions.allow.push(permission);
added.push(permission);
}
}
if (added.length > 0) {
writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n');
console.log(`\x1b[32m✓\x1b[0m Added permissions to ~/.claude/settings.json:`);
for (const permission of added) {
console.log(` - ${permission}`);
}
}
} catch (err) {
console.log(`\x1b[33m⚠\x1b[0m Could not update settings: ${err.message}`);
}