forked from OHIF/Viewers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreinstall.js
More file actions
88 lines (75 loc) · 3.03 KB
/
Copy pathpreinstall.js
File metadata and controls
88 lines (75 loc) · 3.03 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
console.log('preinstall.js');
const fs = require('fs');
const path = require('path');
const { exec } = require('child_process');
const log = (err, stdout, stderr) => console.log(stdout);
const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
if (GITHUB_TOKEN) {
const command = `git config --global url."https://${GITHUB_TOKEN}:x-oauth-basic@github.com/".insteadOf ssh://git@github.com/`;
console.log(command);
exec(command, log);
} else {
console.log('No GITHUB_TOKEN found, skipping private repo customization');
}
const agentsPath = path.join(__dirname, 'AGENTS.md');
const claudePath = path.join(__dirname, 'CLAUDE.md');
try {
if (fs.existsSync(agentsPath)) {
try {
fs.unlinkSync(claudePath);
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}
fs.symlinkSync('AGENTS.md', claudePath);
console.log('Linked CLAUDE.md -> AGENTS.md');
}
} catch (err) {
console.log(`Skipped CLAUDE.md symlink: ${err.message}`);
}
// Mirror every skill under .agents/skills/ into .claude/skills/
try {
const agentsSkillsDir = path.join(__dirname, '.agents', 'skills');
const claudeSkillsDir = path.join(__dirname, '.claude', 'skills');
if (!fs.existsSync(agentsSkillsDir)) {
console.log('No .agents/skills directory found, skipping skill symlinks');
} else {
fs.mkdirSync(claudeSkillsDir, { recursive: true });
const agentsDirectoryEntries = fs.readdirSync(agentsSkillsDir, { withFileTypes: true });
for (const agentFolderEntry of agentsDirectoryEntries) {
if (!agentFolderEntry.isDirectory()) {
continue;
}
const claudeSkillLinkPath = path.join(claudeSkillsDir, agentFolderEntry.name);
const expectedSymlinkTarget = path.join('..', '..', '.agents', 'skills', agentFolderEntry.name);
try {
const existingLinkStats = fs.lstatSync(claudeSkillLinkPath, { throwIfNoEntry: false });
if (existingLinkStats) {
if (!existingLinkStats.isSymbolicLink()) {
console.log(
`Skipped skill symlink ${agentFolderEntry.name}: ${claudeSkillLinkPath} exists and is not a symlink`
);
continue;
}
const existingSymlinkTarget = fs.readlinkSync(claudeSkillLinkPath);
if (existingSymlinkTarget === expectedSymlinkTarget) {
continue;
}
// A symlink pointing somewhere else is treated as a developer
// override (.claude/ is gitignored local config). Leave it alone.
console.log(
`Skipped skill symlink ${agentFolderEntry.name}: ${claudeSkillLinkPath} points to ${existingSymlinkTarget}, not ${expectedSymlinkTarget}`
);
continue;
}
fs.symlinkSync(expectedSymlinkTarget, claudeSkillLinkPath, 'dir');
console.log(`Linked .claude/skills/${agentFolderEntry.name} -> ${expectedSymlinkTarget}`);
} catch (err) {
console.log(`Skipped skill symlink ${agentFolderEntry.name}: ${err.message}`);
}
}
}
} catch (err) {
console.log(`Skipped skill symlink setup: ${err.message}`);
}