@trendai-crem/claude-skills 0.4.0 → 0.5.0
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/cli.js +72 -10
- package/package.json +4 -1
package/cli.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { execFileSync } from 'child_process';
|
|
4
|
-
import { readFileSync, readdirSync } from 'fs';
|
|
4
|
+
import { readFileSync, readdirSync, writeFileSync, mkdirSync, existsSync } from 'fs';
|
|
5
5
|
import { fileURLToPath } from 'url';
|
|
6
6
|
import { dirname, join } from 'path';
|
|
7
|
+
import { homedir } from 'os';
|
|
7
8
|
|
|
8
9
|
const __dir = dirname(fileURLToPath(import.meta.url));
|
|
9
10
|
|
|
@@ -55,13 +56,74 @@ if (externalFailed.length > 0) {
|
|
|
55
56
|
console.warn(`\nWARN: ${externalFailed.length} external source(s) failed — team skills installed successfully.`);
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
// Configure auto-update hook in ~/.claude/settings.json
|
|
60
|
+
setupAutoUpdate();
|
|
61
|
+
|
|
62
|
+
// ─── Auto-update setup ─────────────────────────────────────────────────────
|
|
63
|
+
|
|
64
|
+
function setupAutoUpdate() {
|
|
65
|
+
const { version: installedVersion } = JSON.parse(
|
|
66
|
+
readFileSync(join(__dir, 'package.json'), 'utf8')
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const claudeDir = join(homedir(), '.claude');
|
|
70
|
+
const hooksDir = join(claudeDir, 'hooks');
|
|
71
|
+
const hookScript = join(hooksDir, 'auto-update-claude-skills.sh');
|
|
72
|
+
const stampFile = join(homedir(), '.cache', 'claude-skills-update.json');
|
|
73
|
+
const settingsPath = join(claudeDir, 'settings.json');
|
|
74
|
+
|
|
75
|
+
// Write the auto-update hook script
|
|
76
|
+
mkdirSync(hooksDir, { recursive: true });
|
|
77
|
+
writeFileSync(hookScript, buildHookScript(stampFile, installedVersion), { mode: 0o755 });
|
|
78
|
+
|
|
79
|
+
// Merge SessionStart hook into ~/.claude/settings.json (idempotent)
|
|
80
|
+
let settings = {};
|
|
81
|
+
if (existsSync(settingsPath)) {
|
|
82
|
+
try { settings = JSON.parse(readFileSync(settingsPath, 'utf8')); } catch {}
|
|
66
83
|
}
|
|
67
|
-
|
|
84
|
+
settings.hooks ??= {};
|
|
85
|
+
settings.hooks.SessionStart ??= [];
|
|
86
|
+
settings.hooks.SessionStart = settings.hooks.SessionStart.filter(
|
|
87
|
+
e => !e.hooks?.some(h => h.command?.includes('auto-update-claude-skills'))
|
|
88
|
+
);
|
|
89
|
+
settings.hooks.SessionStart.push({
|
|
90
|
+
hooks: [{ type: 'command', command: hookScript }]
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n');
|
|
94
|
+
console.log('\n✓ Auto-update configured (runs daily at session start)');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function buildHookScript(stampFile, installedVersion) {
|
|
98
|
+
return `#!/usr/bin/env bash
|
|
99
|
+
# Auto-update @trendai-crem/claude-skills at Claude Code session start (max once per 24h).
|
|
100
|
+
set -euo pipefail
|
|
101
|
+
|
|
102
|
+
STAMP="${stampFile}"
|
|
103
|
+
PACKAGE="@trendai-crem/claude-skills"
|
|
104
|
+
MIN_INTERVAL=$((60 * 60 * 24))
|
|
105
|
+
|
|
106
|
+
mkdir -p "$(dirname "$STAMP")"
|
|
107
|
+
|
|
108
|
+
LAST_TS=0
|
|
109
|
+
CURRENT_VER="${installedVersion}"
|
|
110
|
+
if [ -f "$STAMP" ]; then
|
|
111
|
+
LAST_TS=$(python3 -c "import json; print(json.load(open('$STAMP')).get('ts',0))" 2>/dev/null || echo 0)
|
|
112
|
+
CURRENT_VER=$(python3 -c "import json; print(json.load(open('$STAMP')).get('version','${installedVersion}'))" 2>/dev/null || echo "${installedVersion}")
|
|
113
|
+
fi
|
|
114
|
+
|
|
115
|
+
NOW=$(date +%s)
|
|
116
|
+
[ $(( NOW - LAST_TS )) -lt $MIN_INTERVAL ] && exit 0
|
|
117
|
+
|
|
118
|
+
# Update timestamp to prevent parallel runs
|
|
119
|
+
python3 -c "import json; json.dump({'ts': $NOW, 'version': '$CURRENT_VER'}, open('$STAMP','w'))"
|
|
120
|
+
|
|
121
|
+
LATEST=$(npm view "$PACKAGE" version 2>/dev/null || echo "")
|
|
122
|
+
[ -z "$LATEST" ] || [ "$LATEST" = "$CURRENT_VER" ] && exit 0
|
|
123
|
+
|
|
124
|
+
# New version — update in background, don't block session startup
|
|
125
|
+
echo "🔄 Auto-updating claude-skills: $CURRENT_VER → $LATEST"
|
|
126
|
+
npx "${PACKAGE}@${LATEST}" >/dev/null 2>&1 &
|
|
127
|
+
python3 -c "import json; json.dump({'ts': $NOW, 'version': '$LATEST'}, open('$STAMP','w'))"
|
|
128
|
+
`;
|
|
129
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trendai-crem/claude-skills",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Claude Code skills installer for the trendai-crem team",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">=20"
|
|
20
20
|
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"prepare": "git config core.hooksPath .githooks"
|
|
23
|
+
},
|
|
21
24
|
"dependencies": {
|
|
22
25
|
"skills": "1.4.5"
|
|
23
26
|
}
|