Skip to content

Commit 3d0b777

Browse files
authored
Merge pull request #800 from github/chore/clean-materialized-plugins
Add cross-platform script to clean materialized plugin files
2 parents 05116b2 + 941aced commit 3d0b777

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

eng/clean-materialized-plugins.mjs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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();

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"plugin:create": "node ./eng/create-plugin.mjs",
1616
"skill:validate": "node ./eng/validate-skills.mjs",
1717
"skill:create": "node ./eng/create-skill.mjs",
18+
"plugin:clean": "node ./eng/clean-materialized-plugins.mjs",
1819
"plugin:generate-marketplace": "node ./eng/generate-marketplace.mjs",
1920
"website:data": "node ./eng/generate-website-data.mjs",
2021
"website:dev": "npm run website:data && npm run --prefix website dev",

0 commit comments

Comments
 (0)