|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +import fs from "fs"; |
| 4 | +import path from "path"; |
| 5 | +import { ROOT_FOLDER } from "./constants.mjs"; |
| 6 | + |
| 7 | +const PLUGINS_DIR = path.join(ROOT_FOLDER, "plugins"); |
| 8 | +const MATERIALIZED_DIRS = ["agents", "commands", "skills"]; |
| 9 | + |
| 10 | +function cleanPlugin(pluginPath) { |
| 11 | + let removed = 0; |
| 12 | + for (const subdir of MATERIALIZED_DIRS) { |
| 13 | + const target = path.join(pluginPath, subdir); |
| 14 | + if (fs.existsSync(target) && fs.statSync(target).isDirectory()) { |
| 15 | + const count = countFiles(target); |
| 16 | + fs.rmSync(target, { recursive: true, force: true }); |
| 17 | + removed += count; |
| 18 | + console.log(` Removed ${path.basename(pluginPath)}/${subdir}/ (${count} files)`); |
| 19 | + } |
| 20 | + } |
| 21 | + return removed; |
| 22 | +} |
| 23 | + |
| 24 | +function countFiles(dir) { |
| 25 | + let count = 0; |
| 26 | + for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { |
| 27 | + if (entry.isDirectory()) { |
| 28 | + count += countFiles(path.join(dir, entry.name)); |
| 29 | + } else { |
| 30 | + count++; |
| 31 | + } |
| 32 | + } |
| 33 | + return count; |
| 34 | +} |
| 35 | + |
| 36 | +function main() { |
| 37 | + console.log("Cleaning materialized files from plugins...\n"); |
| 38 | + |
| 39 | + if (!fs.existsSync(PLUGINS_DIR)) { |
| 40 | + console.error(`Error: plugins directory not found at ${PLUGINS_DIR}`); |
| 41 | + process.exit(1); |
| 42 | + } |
| 43 | + |
| 44 | + const pluginDirs = fs.readdirSync(PLUGINS_DIR, { withFileTypes: true }) |
| 45 | + .filter(entry => entry.isDirectory()) |
| 46 | + .map(entry => entry.name) |
| 47 | + .sort(); |
| 48 | + |
| 49 | + let total = 0; |
| 50 | + for (const dirName of pluginDirs) { |
| 51 | + total += cleanPlugin(path.join(PLUGINS_DIR, dirName)); |
| 52 | + } |
| 53 | + |
| 54 | + console.log(); |
| 55 | + if (total === 0) { |
| 56 | + console.log("✅ No materialized files found. Plugins are already clean."); |
| 57 | + } else { |
| 58 | + console.log(`✅ Removed ${total} materialized file(s) from plugins.`); |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +main(); |
0 commit comments