repo-clean 1.0.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/LICENSE +21 -0
- package/README.md +64 -0
- package/bin/repo-clean.js +172 -0
- package/package.json +25 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Arben Kryemadhi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# repo-clean
|
|
2
|
+
|
|
3
|
+
Clean common build outputs and cache folders from a repository.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
repo-clean [--dry-run] [--node-modules] [--pm-cache] [--logs] [--editor] [--tmp]
|
|
9
|
+
repo-clean --all [--keep-nm] [--dry-run]
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
### Default behavior (no flags)
|
|
13
|
+
|
|
14
|
+
Removes:
|
|
15
|
+
|
|
16
|
+
- `dist`
|
|
17
|
+
- `build`
|
|
18
|
+
- `coverage`
|
|
19
|
+
- `.next`
|
|
20
|
+
- `.turbo`
|
|
21
|
+
- `.vite`
|
|
22
|
+
- `.parcel-cache`
|
|
23
|
+
- `.cache`
|
|
24
|
+
|
|
25
|
+
### Flags
|
|
26
|
+
|
|
27
|
+
- `--dry-run` Print what would be removed without deleting anything.
|
|
28
|
+
- `--node-modules` Also remove `node_modules`.
|
|
29
|
+
- `--pm-cache` Also remove package manager caches/stores:
|
|
30
|
+
- `.yarn/cache`
|
|
31
|
+
- `.yarn/unplugged`
|
|
32
|
+
- `.yarn/install-state.gz`
|
|
33
|
+
- `.pnp.cjs`
|
|
34
|
+
- `.pnp.loader.mjs`
|
|
35
|
+
- `.pnpm-store`
|
|
36
|
+
- `--logs` Also remove common root log files:
|
|
37
|
+
- `npm-debug.log*`
|
|
38
|
+
- `yarn-error.log*`
|
|
39
|
+
- `pnpm-debug.log*`
|
|
40
|
+
- `lerna-debug.log*`
|
|
41
|
+
- `--editor` Also remove editor folders (`.vscode`, `.idea`).
|
|
42
|
+
- `--tmp` Also remove `tmp` and `temp`.
|
|
43
|
+
- `--all` Include all optional cleanup categories above.
|
|
44
|
+
- `--keep-nm` With `--all`, keep `node_modules`.
|
|
45
|
+
|
|
46
|
+
## Examples
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# Dry-run default cleanup
|
|
50
|
+
npx repo-clean --dry-run
|
|
51
|
+
|
|
52
|
+
# Remove default targets + node_modules
|
|
53
|
+
npx repo-clean --node-modules
|
|
54
|
+
|
|
55
|
+
# Full cleanup except node_modules
|
|
56
|
+
npx repo-clean --all --keep-nm
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Install
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npm i -g repo-clean
|
|
63
|
+
repo-clean --help
|
|
64
|
+
```
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* repo-clean: remove common repo build outputs and caches */
|
|
3
|
+
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const path = require("node:path");
|
|
6
|
+
|
|
7
|
+
const argv = process.argv.slice(2);
|
|
8
|
+
const args = new Set(argv);
|
|
9
|
+
|
|
10
|
+
const dryRun = args.has("--dry-run");
|
|
11
|
+
const help = args.has("--help") || args.has("-h");
|
|
12
|
+
|
|
13
|
+
const flagAll = args.has("--all");
|
|
14
|
+
const keepNm = args.has("--keep-nm");
|
|
15
|
+
|
|
16
|
+
const flagNodeModules = args.has("--node-modules");
|
|
17
|
+
const flagPmCache = args.has("--pm-cache");
|
|
18
|
+
const flagLogs = args.has("--logs");
|
|
19
|
+
const flagEditor = args.has("--editor");
|
|
20
|
+
const flagTmp = args.has("--tmp");
|
|
21
|
+
|
|
22
|
+
if (help) {
|
|
23
|
+
console.log(`repo-clean
|
|
24
|
+
|
|
25
|
+
Usage:
|
|
26
|
+
repo-clean [--dry-run] [--node-modules] [--pm-cache] [--logs] [--editor] [--tmp]
|
|
27
|
+
repo-clean --all [--keep-nm] [--dry-run]
|
|
28
|
+
|
|
29
|
+
Defaults (no flags):
|
|
30
|
+
Removes build outputs + framework caches:
|
|
31
|
+
dist, build, coverage, .next, .turbo, .vite, .parcel-cache, .cache
|
|
32
|
+
|
|
33
|
+
Flags:
|
|
34
|
+
--dry-run Print what would be removed
|
|
35
|
+
--node-modules Also remove node_modules
|
|
36
|
+
--pm-cache Also remove package manager caches/stores (Yarn/Pnpm artifacts)
|
|
37
|
+
--logs Also remove common debug log files in the repo root
|
|
38
|
+
--editor Also remove editor/IDE folders (.vscode, .idea)
|
|
39
|
+
--tmp Also remove tmp/temp folders
|
|
40
|
+
--all Default + all flags above
|
|
41
|
+
--keep-nm With --all, keep node_modules (do not remove it)
|
|
42
|
+
`);
|
|
43
|
+
process.exit(0);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const cwd = process.cwd();
|
|
47
|
+
|
|
48
|
+
const defaultTargets = [
|
|
49
|
+
"dist",
|
|
50
|
+
"build",
|
|
51
|
+
"coverage",
|
|
52
|
+
".next",
|
|
53
|
+
".turbo",
|
|
54
|
+
".vite",
|
|
55
|
+
".parcel-cache",
|
|
56
|
+
".cache",
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
const editorTargets = [".vscode", ".idea"];
|
|
60
|
+
const tmpTargets = ["tmp", "temp"];
|
|
61
|
+
|
|
62
|
+
// Mix of directories + files that can exist in a repo for Yarn/Pnpm setups.
|
|
63
|
+
// (No globs; exact known paths only.)
|
|
64
|
+
const pmCacheTargets = [
|
|
65
|
+
".yarn/cache",
|
|
66
|
+
".yarn/unplugged",
|
|
67
|
+
".yarn/install-state.gz",
|
|
68
|
+
".pnp.cjs",
|
|
69
|
+
".pnp.loader.mjs",
|
|
70
|
+
".pnpm-store",
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
// Log file prefixes to delete in repo root (covers e.g. npm-debug.log.123)
|
|
74
|
+
const logPrefixes = [
|
|
75
|
+
"npm-debug.log",
|
|
76
|
+
"yarn-error.log",
|
|
77
|
+
"pnpm-debug.log",
|
|
78
|
+
"lerna-debug.log",
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
function exists(p) {
|
|
82
|
+
try {
|
|
83
|
+
fs.accessSync(p);
|
|
84
|
+
return true;
|
|
85
|
+
} catch {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function removePath(absPath) {
|
|
91
|
+
if (!exists(absPath)) return false;
|
|
92
|
+
|
|
93
|
+
if (dryRun) {
|
|
94
|
+
console.log(`[dry-run] would remove: ${absPath}`);
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
fs.rmSync(absPath, {
|
|
99
|
+
recursive: true,
|
|
100
|
+
force: true,
|
|
101
|
+
maxRetries: 2,
|
|
102
|
+
retryDelay: 50,
|
|
103
|
+
});
|
|
104
|
+
console.log(`removed: ${absPath}`);
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function gatherRootLogs() {
|
|
109
|
+
const found = [];
|
|
110
|
+
let entries;
|
|
111
|
+
try {
|
|
112
|
+
entries = fs.readdirSync(cwd, { withFileTypes: true });
|
|
113
|
+
} catch {
|
|
114
|
+
return found;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
for (const ent of entries) {
|
|
118
|
+
if (!ent.isFile()) continue;
|
|
119
|
+
const name = ent.name;
|
|
120
|
+
if (logPrefixes.some((p) => name === p || name.startsWith(p))) {
|
|
121
|
+
found.push(name);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return found;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Determine what to remove
|
|
128
|
+
const targets = new Set(defaultTargets);
|
|
129
|
+
|
|
130
|
+
const includePmCache = flagAll || flagPmCache;
|
|
131
|
+
const includeLogs = flagAll || flagLogs;
|
|
132
|
+
const includeEditor = flagAll || flagEditor;
|
|
133
|
+
const includeTmp = flagAll || flagTmp;
|
|
134
|
+
|
|
135
|
+
// node_modules inclusion logic:
|
|
136
|
+
// - default: off
|
|
137
|
+
// - --node-modules: on
|
|
138
|
+
// - --all: on, unless --keep-nm is also present
|
|
139
|
+
const includeNodeModules = (flagAll || flagNodeModules) && !(flagAll && keepNm);
|
|
140
|
+
|
|
141
|
+
if (includePmCache) for (const t of pmCacheTargets) targets.add(t);
|
|
142
|
+
if (includeEditor) for (const t of editorTargets) targets.add(t);
|
|
143
|
+
if (includeTmp) for (const t of tmpTargets) targets.add(t);
|
|
144
|
+
if (includeNodeModules) targets.add("node_modules");
|
|
145
|
+
|
|
146
|
+
// Remove fixed targets
|
|
147
|
+
let removedCount = 0;
|
|
148
|
+
|
|
149
|
+
for (const rel of Array.from(targets).sort()) {
|
|
150
|
+
const abs = path.join(cwd, rel);
|
|
151
|
+
if (removePath(abs)) removedCount += 1;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Remove root log files (if enabled)
|
|
155
|
+
if (includeLogs) {
|
|
156
|
+
const logs = gatherRootLogs();
|
|
157
|
+
for (const name of logs.sort()) {
|
|
158
|
+
const abs = path.join(cwd, name);
|
|
159
|
+
if (removePath(abs)) removedCount += 1;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const nmNote =
|
|
164
|
+
flagAll && keepNm
|
|
165
|
+
? " (kept node_modules)"
|
|
166
|
+
: includeNodeModules
|
|
167
|
+
? " (includes node_modules)"
|
|
168
|
+
: "";
|
|
169
|
+
const mode = dryRun ? "done (dry-run)" : "done";
|
|
170
|
+
console.log(
|
|
171
|
+
`${mode}. ${dryRun ? "would remove" : "removed"} ${removedCount} item(s).${nmNote}`,
|
|
172
|
+
);
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "repo-clean",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Clean common build and cache folders from a repository.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"bin": {
|
|
7
|
+
"repo-clean": "bin/repo-clean.js"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/arbenkryemadhi/repo-clean.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [],
|
|
14
|
+
"author": "Arben Kryemadhi",
|
|
15
|
+
"type": "commonjs",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/arbenkryemadhi/repo-clean/issues"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/arbenkryemadhi/repo-clean#readme",
|
|
20
|
+
"files": [
|
|
21
|
+
"bin",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
]
|
|
25
|
+
}
|