del-cli is a cross-platform command-line tool for safely deleting files and directories using glob patterns. It provides a safer alternative to rm -rf and rimraf with built-in protection against deleting parent directories, dry-run capabilities, and comprehensive glob pattern support including Windows compatibility.
npm install --global del-cli"type": "module")This is a CLI tool that provides binary commands rather than importable modules. The tool is built on the del npm package for programmatic deletion functionality:
// For programmatic usage, use the underlying del package directly:
const { deleteAsync } = require('del');
// or
import { deleteAsync } from 'del';The tool provides two binary commands:
del-cli <path|glob> ...
del <path|glob> ... # Alias (conflicts with Windows built-in del command)# Delete specific files
del-cli file.txt another-file.js
# Delete using glob patterns
del-cli "*.log" "temp/**/*.tmp"
# Preview deletions without actually deleting
del-cli --dry-run "*.cache"
# Delete with verbose output
del-cli --verbose --force "build/**"
# Exclude specific patterns
del-cli "*.png" "!important.png"del-cli is built around several key components:
meow package for argument parsing and help textdel package for actual file system operationsdel's onProgress callback for verbose outputProvides a complete CLI for deleting files and directories with glob pattern support.
// CLI Command Structure
interface DelCliCommand {
command: 'del-cli' | 'del';
arguments: string[]; // Array of path/glob patterns
flags: {
force?: boolean; // -f, --force
dryRun?: boolean; // -d, --dry-run
verbose?: boolean; // -v, --verbose
};
}
// Exit Codes
interface ExitCodes {
SUCCESS: 0; // Successful operation
INPUT_ERROR: 1; // No paths specified
SYSTEM_ERROR: number; // File system errors
}
// Output Formats
interface OutputBehavior {
verbose: { // When --verbose flag is used
existingFile: string; // Prints absolute file path
nonExistingFile: ''; // No output
};
dryRun: string[]; // Array of files that would be deleted
normal: void; // Silent operation
}Deletes files and directories using glob patterns with cross-platform compatibility and safety features.
// Primary deletion function (CLI interface)
function delCli(
patterns: string[], // Array of glob patterns/file paths (minimum 1 required)
options: {
force?: boolean; // Allow deleting CWD and outside directories
dryRun?: boolean; // Preview mode - list files without deleting
verbose?: boolean; // Show real-time deletion progress
}
): Promise<string[]>; // Returns array of deleted file paths
// Usage examples:
// del-cli "*.png" "!important.png" --dry-run
// del-cli --force --verbose "build/**"Arguments:
patterns (string[], required): One or more file paths or glob patterns to deleteGlob Pattern Support:
*, **, ?!pattern*.png - All PNG files in current directory**/*.log - All log files recursively"*.tmp" "!important.tmp" - All tmp files except important.tmpAllows deletion of the current working directory and files outside the current directory.
interface ForceMode {
flag: '--force' | '-f';
behavior: {
allowCurrentDirectory: boolean; // Can delete current working directory
allowOutsideDirectory: boolean; // Can delete files outside CWD
bypassSafetyChecks: boolean; // Disables built-in protections
};
}
// Usage: del-cli --force <path|glob> ...
// Usage: del-cli -f <path|glob> ...Safety Note: Use with caution as this bypasses built-in safety protections.
Lists what would be deleted without actually performing the deletion.
interface DryRunMode {
flag: '--dry-run' | '-d';
behavior: {
deletesFiles: false; // No actual deletion performed
outputFormat: 'newline-separated'; // One file path per line
returnValue: string[]; // Array of file paths that would be deleted
};
}
// Usage: del-cli --dry-run <path|glob> ...
// Usage: del-cli -d <path|glob> ...Output: Prints the full paths of files that would be deleted, one per line to stdout.
Displays the absolute path of files and directories as they are deleted.
interface VerboseMode {
flag: '--verbose' | '-v';
behavior: {
showProgress: boolean; // Real-time deletion feedback
outputTarget: 'stdout'; // Outputs to standard output
pathFormat: 'absolute'; // Full absolute file paths
timing: 'real-time'; // Shows paths as files are processed
};
outputBehavior: {
existingFile: (path: string) => void; // Prints absolute path
nonExistingFile: () => void; // No output
};
}
// Usage: del-cli --verbose <path|glob> ...
// Usage: del-cli -v <path|glob> ...Output: Shows real-time feedback of deletion operations with absolute file paths to stdout.
--force flag to delete current working directory--force flag to delete files outside current directory--dry-run--verboseinterface InputValidation {
requiredArguments: {
minimum: 1; // At least one path/glob pattern required
errorMessage: 'Specify at least one path';
exitCode: 1;
};
patternValidation: {
handler: 'del-package'; // Handled by underlying del package
globEngine: boolean; // Uses glob pattern matching
crossPlatform: boolean; // Works on Windows, macOS, Linux
};
permissionHandling: {
fileSystemErrors: 'standard'; // Standard Node.js file system errors
displayToUser: boolean; // Error messages shown to user
};
}interface ExitCodes {
SUCCESS: 0; // Deletion completed successfully or dry-run finished
INPUT_ERROR: 1; // No path arguments provided
SYSTEM_ERROR: number; // File system operation errors (from del package)
}
// Error conditions that trigger exit code 1:
// - Command executed with no path/glob arguments
// - Displays "Specify at least one path" to stderrdel command, use del-cli instead# Clean build artifacts
del-cli "dist/**" "*.tsbuildinfo" "coverage/**"
# Clean with safety check
del-cli --dry-run "node_modules/**/.cache/**"# Remove temporary files
del-cli "**/*.tmp" "**/*.log" "**/.DS_Store"
# Clean specific file types
del-cli "**/*.{tmp,log,cache}" "!important.log"# Force delete with verbose output
del-cli --force --verbose "**/.git/**"
# Preview complex patterns
del-cli --dry-run "src/**/*.{js,ts}" "!src/**/*.test.{js,ts}"