disk-tools
v1.0.0
Published
Modular disk management tools
Readme
Disk Tools
A modular command-line tool for disk management operations including cleaning temporary directories, encrypted archiving, and remote synchronization.
Features
- 🧹 Clean: Remove temporary directories (node_modules, target, .next, cache, etc.)
- 🔒 Archive: Compress and encrypt directories with AES-256-GCM encryption
- 🔄 Sync: Synchronize directories to remote locations using rsync
Installation
pnpm installUsage
Development Mode
pnpm dev <command> [options]Production Mode
# Build the project
pnpm build
# Run built version
pnpm start <command> [options]Commands
🧹 Clean
Remove temporary directories from a path recursively.
Supported directory types:
node_modules- Node.js dependenciestarget- Rust build output.next- Next.js build cachedist,build- Build output directories.cache,cache- Cache directories.turbo- Turbo cache.nuxt,.output- Nuxt.js build files.svelte-kit- SvelteKit build files.vercel,.netlify- Deployment cache
Examples:
# Clean specific directory
pnpm dev clean /path/to/directory
# Dry run (preview without deleting)
pnpm dev clean /path/to/directory --dry-run
# Clean only specific directory names
pnpm dev clean /path/to/directory --custom node_modules target .nextOptions:
-d, --dry-run- Preview what would be deleted without actually deleting-c, --custom <dirs...>- Specify custom directory names to clean
🔒 Archive
Compress and encrypt directories for secure transfer using AES-256-GCM encryption.
Examples:
# Create encrypted archive
pnpm dev archive create /path/to/directory -o backup.zip.enc -p mypassword
# Extract encrypted archive
pnpm dev archive extract backup.zip.enc -o /path/to/extract -p mypassword
# Use default output path
pnpm dev archive create ./my-project -p securepass123Create Options:
-o, --output <path>- Output archive path (default:archive.zip.enc)-p, --password <password>- Encryption password (required)
Extract Options:
-o, --output <path>- Output directory path (default:./extracted)-p, --password <password>- Decryption password (required)
Security Notes:
- Uses AES-256-GCM authenticated encryption
- Generates random salt and IV for each archive
- Password is derived using scrypt key derivation
- Incorrect password will be detected during extraction
🔄 Sync
Synchronize directory to remote location using rsync.
Examples:
# Sync to remote server
pnpm dev sync /path/to/local [email protected]:/path/to/remote
# Sync with delete (mirror)
pnpm dev sync ./my-project user@server:/backup/my-project --delete
# Dry run to preview changes
pnpm dev sync ./data user@server:/data --dry-run
# Sync with exclusions
pnpm dev sync ./project user@server:/project -e node_modules -e "*.log" -e .git
# Verbose output
pnpm dev sync ./files user@server:/files --verboseOptions:
-d, --delete- Delete files in destination that don't exist in source--dry-run- Preview what would be transferred without actually syncing-e, --exclude <patterns...>- Exclude patterns (e.g., "*.log" "node_modules")-v, --verbose- Show detailed output
Requirements:
rsyncmust be installed on your system- SSH access to remote server (if syncing remotely)
Project Structure
disk-tools/
├── src/
│ ├── commands/ # Command modules
│ │ ├── clean.ts # Clean command implementation
│ │ ├── archive.ts # Archive command implementation
│ │ └── sync.ts # Sync command implementation
│ ├── utils/ # Shared utilities
│ │ └── logger.ts # Logging and UI utilities
│ └── index.ts # CLI entry point
├── package.json
├── tsconfig.json
└── README.mdArchitecture
This tool is designed with modularity in mind:
- Modular Commands: Each command is implemented as a separate module
- Easy Extension: Add new commands by creating a new file in
src/commands/ - Commander.js: Uses Commander.js for robust CLI argument parsing
- TypeScript: Full type safety and modern JavaScript features
Adding New Commands
To add a new command:
- Create a new file in
src/commands/your-command.ts - Implement your command logic
- Export a
registerYourCommand(program: Command)function - Register it in
src/index.ts
Example:
import { Command } from 'commander';
import { logger } from '../utils/logger.js';
export function registerYourCommand(program: Command): void {
program
.command('your-command')
.description('Your command description')
.argument('<path>', 'Path argument')
.option('-o, --option', 'Option description')
.action(async (path: string, options: any) => {
logger.info('Executing your command...');
// Your implementation here
});
}License
MIT
