@involvex/bun-sweep 0.0.0-stage → 0.0.1
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/.prettierignore +41 -0
- package/AGENTS.md +93 -0
- package/README.md +118 -2
- package/package.json +34 -5
- package/src/index.ts +128 -0
- package/tsconfig.json +32 -0
package/.prettierignore
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# AI Agent Directories
|
|
2
|
+
.agent
|
|
3
|
+
.agents
|
|
4
|
+
.kilo
|
|
5
|
+
.claude
|
|
6
|
+
.gemini
|
|
7
|
+
.kilocode
|
|
8
|
+
.opencode
|
|
9
|
+
|
|
10
|
+
# Build & Dependency Directories
|
|
11
|
+
node_modules
|
|
12
|
+
dist
|
|
13
|
+
build
|
|
14
|
+
coverage
|
|
15
|
+
.next
|
|
16
|
+
.nuxt
|
|
17
|
+
.cache
|
|
18
|
+
|
|
19
|
+
# Version Control & Config
|
|
20
|
+
.git
|
|
21
|
+
.vscode
|
|
22
|
+
.idea
|
|
23
|
+
|
|
24
|
+
# Lock Files
|
|
25
|
+
package-lock.json
|
|
26
|
+
yarn.lock
|
|
27
|
+
pnpm-lock.yaml
|
|
28
|
+
bun.lockb
|
|
29
|
+
|
|
30
|
+
# Minified & Generated Files
|
|
31
|
+
*.min.js
|
|
32
|
+
*.min.css
|
|
33
|
+
*.min.js.map
|
|
34
|
+
*.min.css.map
|
|
35
|
+
|
|
36
|
+
# System Files
|
|
37
|
+
.DS_Store
|
|
38
|
+
Thumbs.db
|
|
39
|
+
*.log
|
|
40
|
+
*.tgz
|
|
41
|
+
*.tar.gz
|
package/AGENTS.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
## Project Overview
|
|
4
|
+
|
|
5
|
+
**bun-sweep** is a CLI tool for cleaning project directories. It provides commands to remove common build output directories and node_modules recursively.
|
|
6
|
+
|
|
7
|
+
## Useful Commands
|
|
8
|
+
|
|
9
|
+
### Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bun install
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Development
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bun run dev # Run the CLI in development mode
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Building
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
bun run build # Build the CLI to dist/ directory
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Type Checking
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
bun run typecheck # Run TypeScript type checking with bun check
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Linting & Formatting
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
bun run lint # Run linter on src/
|
|
37
|
+
bun run format # Format code with prettier
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### CLI Usage
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
bun run index.ts # Run directly
|
|
44
|
+
|
|
45
|
+
bun-sweep # If installed globally
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
bun-sweep clean # Remove dist, build, out, coverage, .cache
|
|
50
|
+
bun-sweep clean:node_modules # Remove node_modules in current directory
|
|
51
|
+
bun-sweep clean:node_modules --path <dir> -r # Remove specific directory recursively
|
|
52
|
+
bun-sweep --help # Show available commands
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Technologies
|
|
56
|
+
|
|
57
|
+
- **Runtime**: [Bun](https://bun.com) v1.4.4+ (fast all-in-one JavaScript runtime)
|
|
58
|
+
- **Language**: TypeScript (ESNext, strict mode)
|
|
59
|
+
- **CLI Dependencies**:
|
|
60
|
+
- @involvex/del-cli - For recursive deletion
|
|
61
|
+
- has-flag - For parsing CLI flags
|
|
62
|
+
- **Build Target**: Bun (native)
|
|
63
|
+
- **Code Quality**:
|
|
64
|
+
- Prettier with @involvex/prettier-config
|
|
65
|
+
- ESLint with TypeScript plugin (type-aware linting enabled)
|
|
66
|
+
- **Module System**: ES Modules ("type": "module")
|
|
67
|
+
|
|
68
|
+
## Best Practices
|
|
69
|
+
|
|
70
|
+
- **Type Safety**: Uses strict TypeScript configuration with additional checks (
|
|
71
|
+
oUncheckedIndexedAccess,
|
|
72
|
+
oImplicitOverride, etc.)
|
|
73
|
+
- **Error Handling**: Validates paths exist before attempting deletion operations
|
|
74
|
+
- **CLI Design**: Uses flag parsing for flexible command options
|
|
75
|
+
- **Cross-platform**: Works on Windows, macOS, and Linux via Bun
|
|
76
|
+
- **Clean Output**: Provides informative console messages for user feedback
|
|
77
|
+
|
|
78
|
+
## Guidelines
|
|
79
|
+
|
|
80
|
+
- **Code Style**: Follow the Prettier configuration from @involvex/prettier-config - imports are sorted
|
|
81
|
+
- **Linting Rules**:
|
|
82
|
+
- qeqeq with smart mode enforced
|
|
83
|
+
-
|
|
84
|
+
|
|
85
|
+
o-unused-vars is an error
|
|
86
|
+
|
|
87
|
+
- @typescript-eslint/no-explicit-any is an error
|
|
88
|
+
- Type-aware linting is enabled
|
|
89
|
+
- **Build Process**: The prebuild script runs format, lint with auto-fix, and typecheck before building
|
|
90
|
+
- **File Structure**: Keep source code in src/, built output in dist/
|
|
91
|
+
- **Adding Commands**: New commands should be added to the commands object in src/index.ts with async functions
|
|
92
|
+
- **Dependencies**: Use Bun as the package manager (see global instructions) - prefer bun add/bun remove
|
|
93
|
+
- **Type Checking**: Use bun check (built-in Rust checker) as specified in global instructions
|
package/README.md
CHANGED
|
@@ -1,3 +1,119 @@
|
|
|
1
|
-
#
|
|
1
|
+
# bun-sweep
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A CLI tool for cleaning project directories. Removes `node_modules` and build output folders recursively, inspired by [cargo-sweep](https://github.com/holmgr/cargo-sweep).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun install
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
bun-sweep [options] [path]
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Options
|
|
18
|
+
|
|
19
|
+
| Flag | Alias | Description |
|
|
20
|
+
| ------------------- | ----- | -------------------------------------------------------------- |
|
|
21
|
+
| `-r`, `--recursive` | | Recursively clean `node_modules` in subdirectories |
|
|
22
|
+
| `--dry-run` | | Preview what would be deleted without deleting |
|
|
23
|
+
| `--build-outputs` | | Clear `dist`, `out`, `dist-electron` instead of `node_modules` |
|
|
24
|
+
| `--version`, `-v` | | Show version number |
|
|
25
|
+
| `--help`, `-h` | | Show help message |
|
|
26
|
+
|
|
27
|
+
### Arguments
|
|
28
|
+
|
|
29
|
+
| Argument | Description |
|
|
30
|
+
| -------- | ---------------------------------------------------------- |
|
|
31
|
+
| `path` | Directory to clean (defaults to current working directory) |
|
|
32
|
+
|
|
33
|
+
### Examples
|
|
34
|
+
|
|
35
|
+
Clean `node_modules` in the current directory:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
bun-sweep
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Preview what would be deleted (dry-run):
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
bun-sweep --dry-run
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Clean `node_modules` in a specific directory:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
bun-sweep D:\repos\my-project
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Recursively clean `node_modules` in all subdirectories:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
bun-sweep -r D:\repos\
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Clean build output folders (`dist`, `out`, `dist-electron`):
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
bun-sweep --build-outputs
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Show help:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
bun-sweep --help
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Development
|
|
72
|
+
|
|
73
|
+
### Install dependencies
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
bun install
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Run in development mode
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
bun run dev
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Build
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
bun run build
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Type check
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
bun run typecheck
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Lint
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
bun run lint
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Format
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
bun run format
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Technologies
|
|
110
|
+
|
|
111
|
+
- **Runtime**: [Bun](https://bun.com) v1.4.4+
|
|
112
|
+
- **Language**: TypeScript (ESNext, strict mode)
|
|
113
|
+
- **CLI Dependencies**:
|
|
114
|
+
- [`@involvex/del-cli`](https://www.npmjs.com/package/@involvex/del-cli) - For recursive deletion
|
|
115
|
+
- [`has-flag`](https://www.npmjs.com/package/has-flag) - For parsing CLI flags
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@involvex/bun-sweep",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"author": "involvex",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/involvex/bun-sweep.git"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"bun-sweep": "src/index.ts"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"module": "src/index.ts",
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "bun build src/index.ts --outdir dist --target bun",
|
|
16
|
+
"dev": "bun src/index.ts",
|
|
17
|
+
"typecheck": "bun check",
|
|
18
|
+
"prebuild": "bun run format && bun run lint --fix && bun run typecheck",
|
|
19
|
+
"lint": "bun lint src",
|
|
20
|
+
"format": "bun fmt",
|
|
21
|
+
"prepublishOnly": "bun run build"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@involvex/del-cli": "^7.0.1",
|
|
25
|
+
"has-flag": "^5.0.1"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@involvex/prettier-config": "^0.0.6",
|
|
29
|
+
"@types/bun": "latest"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"typescript": "^7"
|
|
33
|
+
},
|
|
34
|
+
"prettier": "@involvex/prettier-config"
|
|
35
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import {existsSync, readdirSync} from 'fs'
|
|
3
|
+
import {isAbsolute, join} from 'path'
|
|
4
|
+
|
|
5
|
+
import {$} from 'bun'
|
|
6
|
+
import hasflag from 'has-flag'
|
|
7
|
+
|
|
8
|
+
import pkg from '../package.json' with {type: 'json'}
|
|
9
|
+
|
|
10
|
+
const args = process.argv.slice(2)
|
|
11
|
+
|
|
12
|
+
// Parse flags
|
|
13
|
+
const help =
|
|
14
|
+
hasflag('help') || hasflag('h') || hasflag('-h') || hasflag('--help')
|
|
15
|
+
const dryRun = hasflag('--dry-run')
|
|
16
|
+
const recursive = hasflag('--recursive') || hasflag('-r')
|
|
17
|
+
const buildOutputs = hasflag('--build-outputs')
|
|
18
|
+
const version = hasflag('--version') || hasflag('-v')
|
|
19
|
+
const repo = pkg.repository?.url || ''
|
|
20
|
+
if (version) {
|
|
21
|
+
console.log('Repository: ', repo)
|
|
22
|
+
console.log('@involvex/bun-sweep version: ', pkg.version)
|
|
23
|
+
process.exit(0)
|
|
24
|
+
}
|
|
25
|
+
// Positional path argument (first non-flag argument)
|
|
26
|
+
const pathArg = args.find(a => !a.startsWith('-'))
|
|
27
|
+
|
|
28
|
+
const targetDir = pathArg
|
|
29
|
+
? isAbsolute(pathArg)
|
|
30
|
+
? pathArg
|
|
31
|
+
: join(process.cwd(), pathArg)
|
|
32
|
+
: process.cwd()
|
|
33
|
+
|
|
34
|
+
const actionLabel = dryRun ? 'Would clean' : 'Cleaning'
|
|
35
|
+
|
|
36
|
+
const deletePaths = async (paths: string[], label: string) => {
|
|
37
|
+
if (dryRun) {
|
|
38
|
+
console.log(`${label}: ${paths.join(', ')}`)
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
console.log(`${label}: ${paths.join(', ')}`)
|
|
42
|
+
await $`del-cli ${paths}`
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const cleanBuildOutputs = async (dir: string) => {
|
|
46
|
+
const folders = ['dist', 'out', 'dist-electron']
|
|
47
|
+
const existing: string[] = []
|
|
48
|
+
for (const folder of folders) {
|
|
49
|
+
const fullPath = join(dir, folder)
|
|
50
|
+
if (existsSync(fullPath)) {
|
|
51
|
+
existing.push(fullPath)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (existing.length === 0) {
|
|
55
|
+
console.log(`No build output folders found in ${dir}`)
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
await deletePaths(existing, `${actionLabel} build outputs in ${dir}`)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const cleanNodeModules = async (dir: string) => {
|
|
62
|
+
const nodeModules = join(dir, 'node_modules')
|
|
63
|
+
if (existsSync(nodeModules)) {
|
|
64
|
+
await deletePaths([nodeModules], `${actionLabel} node_modules in ${dir}`)
|
|
65
|
+
} else {
|
|
66
|
+
console.log(`No node_modules found in ${dir}`)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const processDir = async (dir: string) => {
|
|
71
|
+
if (buildOutputs) {
|
|
72
|
+
await cleanBuildOutputs(dir)
|
|
73
|
+
} else {
|
|
74
|
+
await cleanNodeModules(dir)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (recursive) {
|
|
78
|
+
try {
|
|
79
|
+
const entries = readdirSync(dir, {withFileTypes: true})
|
|
80
|
+
for (const entry of entries) {
|
|
81
|
+
if (entry.isDirectory() && entry.name !== 'node_modules') {
|
|
82
|
+
await processDir(join(dir, entry.name))
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
} catch (e) {
|
|
86
|
+
console.error(`Failed to read directory ${dir}: ${String(e)}`)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (help) {
|
|
92
|
+
console.log('Usage: bun-sweep [options] [path]')
|
|
93
|
+
console.log('')
|
|
94
|
+
console.log('Options:')
|
|
95
|
+
console.log(
|
|
96
|
+
' -r, --recursive Recursively clean node_modules in subdirectories',
|
|
97
|
+
)
|
|
98
|
+
console.log(
|
|
99
|
+
' --dry-run Preview what would be deleted without deleting',
|
|
100
|
+
)
|
|
101
|
+
console.log(
|
|
102
|
+
' --build-outputs Clear dist, out, dist-electron instead of node_modules',
|
|
103
|
+
)
|
|
104
|
+
console.log(' --help, -h Show this help message')
|
|
105
|
+
console.log('')
|
|
106
|
+
console.log('Examples:')
|
|
107
|
+
console.log(
|
|
108
|
+
' bun-sweep Clean node_modules in current directory',
|
|
109
|
+
)
|
|
110
|
+
console.log(' bun-sweep --dry-run Preview node_modules cleanup')
|
|
111
|
+
console.log(
|
|
112
|
+
' bun-sweep D:/repos/ Clean node_modules in specific directory',
|
|
113
|
+
)
|
|
114
|
+
console.log(
|
|
115
|
+
' bun-sweep -r D:/repos/ Recursively clean node_modules in all subdirs',
|
|
116
|
+
)
|
|
117
|
+
console.log(
|
|
118
|
+
' bun-sweep --build-outputs Clean dist, out, dist-electron folders',
|
|
119
|
+
)
|
|
120
|
+
process.exit(0)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (!existsSync(targetDir)) {
|
|
124
|
+
console.log(`Path not found: ${targetDir}`)
|
|
125
|
+
process.exit(1)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
await processDir(targetDir)
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Environment setup & latest features
|
|
4
|
+
"lib": ["ESNext"],
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"module": "Preserve",
|
|
7
|
+
"moduleDetection": "force",
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
"types": ["bun"],
|
|
11
|
+
|
|
12
|
+
// Bundler mode
|
|
13
|
+
"moduleResolution": "bundler",
|
|
14
|
+
"allowImportingTsExtensions": true,
|
|
15
|
+
"verbatimModuleSyntax": true,
|
|
16
|
+
"noEmit": true,
|
|
17
|
+
"rewriteRelativeImportExtensions": true,
|
|
18
|
+
// Best practices
|
|
19
|
+
"strict": true,
|
|
20
|
+
"skipLibCheck": true,
|
|
21
|
+
"noFallthroughCasesInSwitch": true,
|
|
22
|
+
"noUncheckedIndexedAccess": true,
|
|
23
|
+
"noImplicitOverride": true,
|
|
24
|
+
"noUncheckedSideEffectImports": true,
|
|
25
|
+
"allowArbitraryExtensions": true,
|
|
26
|
+
|
|
27
|
+
// Some stricter flags (disabled by default)
|
|
28
|
+
"noUnusedLocals": false,
|
|
29
|
+
"noUnusedParameters": false,
|
|
30
|
+
"noPropertyAccessFromIndexSignature": false
|
|
31
|
+
}
|
|
32
|
+
}
|