mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-03 00:17:47 +00:00
feat(npm): add postuninstall script
- add scripts/postuninstall.js for npm uninstall cleanup - register in package.json scripts.postuninstall - runs ccs --uninstall on npm uninstall -g
This commit is contained in:
@@ -51,6 +51,7 @@
|
|||||||
"preferGlobal": true,
|
"preferGlobal": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"preinstall": "node scripts/preinstall.js",
|
"preinstall": "node scripts/preinstall.js",
|
||||||
|
"postuninstall": "node scripts/postuninstall.js",
|
||||||
"build": "tsc && node scripts/add-shebang.js",
|
"build": "tsc && node scripts/add-shebang.js",
|
||||||
"build:watch": "tsc --watch",
|
"build:watch": "tsc --watch",
|
||||||
"build:server": "tsc && node scripts/add-shebang.js",
|
"build:server": "tsc && node scripts/add-shebang.js",
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
/**
|
||||||
|
* CCS Postuninstall Script
|
||||||
|
*
|
||||||
|
* Cleans up WebSearch hook from ~/.claude/settings.json after npm uninstall.
|
||||||
|
* Self-contained, no external dependencies.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const os = require('os');
|
||||||
|
|
||||||
|
const SETTINGS_PATH = path.join(os.homedir(), '.claude', 'settings.json');
|
||||||
|
|
||||||
|
function cleanupHook() {
|
||||||
|
try {
|
||||||
|
if (!fs.existsSync(SETTINGS_PATH)) {
|
||||||
|
return; // Nothing to clean
|
||||||
|
}
|
||||||
|
|
||||||
|
const content = fs.readFileSync(SETTINGS_PATH, 'utf8');
|
||||||
|
let settings;
|
||||||
|
try {
|
||||||
|
settings = JSON.parse(content);
|
||||||
|
} catch {
|
||||||
|
return; // Malformed JSON, don't touch
|
||||||
|
}
|
||||||
|
|
||||||
|
const hooks = settings.hooks;
|
||||||
|
if (!hooks?.PreToolUse) {
|
||||||
|
return; // No hooks to remove
|
||||||
|
}
|
||||||
|
|
||||||
|
const originalLength = hooks.PreToolUse.length;
|
||||||
|
hooks.PreToolUse = hooks.PreToolUse.filter((h) => {
|
||||||
|
if (h.matcher !== 'WebSearch') return true;
|
||||||
|
const command = h.hooks?.[0]?.command;
|
||||||
|
if (!command) return true;
|
||||||
|
return !command.includes('.ccs/hooks/websearch-transformer');
|
||||||
|
});
|
||||||
|
|
||||||
|
if (hooks.PreToolUse.length === originalLength) {
|
||||||
|
return; // Nothing changed
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up empty structures
|
||||||
|
if (hooks.PreToolUse.length === 0) {
|
||||||
|
delete hooks.PreToolUse;
|
||||||
|
}
|
||||||
|
if (Object.keys(hooks).length === 0) {
|
||||||
|
delete settings.hooks;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync(SETTINGS_PATH, JSON.stringify(settings, null, 2), 'utf8');
|
||||||
|
} catch {
|
||||||
|
// Silent fail - not critical
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanupHook();
|
||||||
Reference in New Issue
Block a user