Add script to clean materialized plugin files

Adds eng/clean-materialized-plugins.mjs which removes agents/, commands/,
and skills/ subdirectories from plugin folders. These are generated by CI
via eng/materialize-plugins.mjs during publish and should not be tracked on
the staged branch.

Runnable via: npm run plugin:clean

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Aaron Powell
2026-02-24 10:33:17 +11:00
parent 05116b2492
commit 941aced1f3
2 changed files with 63 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
#!/usr/bin/env node
import fs from "fs";
import path from "path";
import { ROOT_FOLDER } from "./constants.mjs";
const PLUGINS_DIR = path.join(ROOT_FOLDER, "plugins");
const MATERIALIZED_DIRS = ["agents", "commands", "skills"];
function cleanPlugin(pluginPath) {
let removed = 0;
for (const subdir of MATERIALIZED_DIRS) {
const target = path.join(pluginPath, subdir);
if (fs.existsSync(target) && fs.statSync(target).isDirectory()) {
const count = countFiles(target);
fs.rmSync(target, { recursive: true, force: true });
removed += count;
console.log(` Removed ${path.basename(pluginPath)}/${subdir}/ (${count} files)`);
}
}
return removed;
}
function countFiles(dir) {
let count = 0;
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
if (entry.isDirectory()) {
count += countFiles(path.join(dir, entry.name));
} else {
count++;
}
}
return count;
}
function main() {
console.log("Cleaning materialized files from plugins...\n");
if (!fs.existsSync(PLUGINS_DIR)) {
console.error(`Error: plugins directory not found at ${PLUGINS_DIR}`);
process.exit(1);
}
const pluginDirs = fs.readdirSync(PLUGINS_DIR, { withFileTypes: true })
.filter(entry => entry.isDirectory())
.map(entry => entry.name)
.sort();
let total = 0;
for (const dirName of pluginDirs) {
total += cleanPlugin(path.join(PLUGINS_DIR, dirName));
}
console.log();
if (total === 0) {
console.log("✅ No materialized files found. Plugins are already clean.");
} else {
console.log(`✅ Removed ${total} materialized file(s) from plugins.`);
}
}
main();