### Init Command Examples (CLI) Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt Shows how to use the 'init' command in Purgo CLI to interactively generate configuration files. It allows specifying the path for the configuration file and demonstrates an example interactive session and its output. ```bash # Create config in current directory purgo-cli init # Create config in specific directory purgo-cli init --path ./packages/frontend # Example interactive session output: # ✨ Let's create your purgo-cli configuration! # # ✔ Select directories/files to clean: › node_modules, dist, build, coverage # ✔ Directories/files to ignore (comma-separated): › **/important-data/** # ✔ Pre-clean hook command: › npm run backup # ✔ Post-clean hook command: › bun install # ✔ Config file format: › .purgo-clirc.json # # ✓ Configuration saved to /path/to/.purgo-clirc.json # ✨ All set! Run 'purgo-cli clean' to start cleaning. ``` -------------------------------- ### Install Purgo CLI Globally Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md Installs the Purgo CLI globally on your system, making it accessible from any directory. This is the recommended installation method for general use. It can be installed using either Bun or npm. ```bash bun install -g purgo-cli # or npm install -g purgo-cli ``` -------------------------------- ### Install Dependencies with Bun Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md Installs all the project's dependencies as defined in the package.json file using the Bun package manager. This is required before running or building the project. ```bash bun install ``` -------------------------------- ### Download Example Purgo CLI Configuration (Bash) Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md These commands demonstrate how to download specific example configuration files for Purgo CLI using `curl`. This allows users to quickly set up Purgo for different project types without manual configuration. ```bash # Download an example directly curl -o .purgorc.json https://raw.githubusercontent.com/andrebessoa/purgo-cli/main/examples/basic-config.json # Or for Next.js curl -o .purgorc.json https://raw.githubusercontent.com/andrebpessoa/purgo-cli/main/examples/nextjs-config.json ``` -------------------------------- ### Purgo CLI Command Examples Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt Examples of using the Purgo CLI for different scenarios. These commands demonstrate dry runs for safety and force mode for non-interactive cleanup with reinstallation. Input: Command-line arguments. Output: Varies based on the command and project state. ```bash # Dry run for safety in CI purgo-cli clean --dry-run --config ./ci-config.json ``` ```bash # Force mode without prompts purgo-cli clean --force --quiet --reinstall ``` -------------------------------- ### Purgo CLI Configuration Extension Example Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md An example of extending Purgo CLI configurations, where a configuration file inherits settings from a base configuration file and then overrides or adds specific targets and ignore patterns. This promotes reusable configurations. ```json { "extends": "./examples/shared-config.json", "targets": ["custom-target"], "ignore": ["**/data/**"] } ``` -------------------------------- ### Basic Purgo CLI Configuration Example Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md A JSON configuration file example for Purgo CLI, specifying directories to target for removal ('targets') and files/directories to ignore ('ignore'), along with pre- and post-cleanup commands ('hooks'). This configuration is typically placed in `.purgorc.json`. ```json { "targets": ["node_modules", "dist", "build", "coverage"], "ignore": ["**/important-data/**"], "hooks": { "preClean": "echo 'Starting cleanup...'", "postClean": "echo 'Cleanup completed!'" } } ``` -------------------------------- ### Next.js Project Cleanup with Purgo CLI (Bash) Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md This example shows how to set up and run Purgo CLI for a Next.js project. It involves downloading the Next.js-specific configuration and then executing the clean command with the --reinstall flag. ```bash curl -o .purgorc.json https://raw.githubusercontent.com/andrebpessoa/purgo-cli/main/examples/nextjs-config.json purgo-cli clean --reinstall ``` -------------------------------- ### Install Purgo CLI Locally Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md Installs the Purgo CLI as a development dependency for a specific project. This is useful for project-specific tooling or when you want to ensure a consistent version across a team. It can be installed using either Bun or npm. ```bash bun install purgo-cli --save-dev # or npm install purgo-cli --save-dev ``` -------------------------------- ### Run Tests with Bun Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md This command executes the test suite for the project using the Bun runtime. Ensure all dependencies are installed before running. ```bash bun test ``` -------------------------------- ### Manage Configuration Cache (TypeScript) Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt This TypeScript example demonstrates how to interact with the in-memory configuration cache provided by 'purgo-cli'. It shows how to get cached configurations, manually set cache entries, invalidate specific entries, clear the entire cache, retrieve cache statistics, and trigger cleanup of expired entries. The cache is automatically used by `loadConfig` but can be managed directly. ```typescript import { configCache } from 'purgo-cli'; // Cache is used automatically by loadConfig // Manual cache operations: // Get cached config (returns null if not found or expired) const cached = configCache.get('/path/to/project', '/global/config.json'); if (cached) { console.log('Using cached config:', cached.config); } // Manually set cache entry configCache.set( '/path/to/project', { config: { targets: ['node_modules'] }, filepath: '.purgorc.json' }, '/global/config.json' ); // Invalidate specific cache entry configCache.invalidate('/path/to/project'); // Clear all cached configurations configCache.clear(); // Get cache statistics const stats = configCache.stats(); console.log(stats); // Output: { size: 3, entries: 3 } // Cleanup expired entries (TTL: 5 minutes) configCache.cleanup(); ``` -------------------------------- ### CI/CD Integration with Purgo CLI (Bash) Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md This example illustrates how to integrate Purgo CLI into a CI/CD pipeline. It shows downloading the CI/CD configuration and then performing a dry run to preview deletions, followed by the actual clean execution. ```bash # In your CI pipeline curl -o .purgorc.json https://raw.githubusercontent.com/andrebpessoa/purgo-cli/main/examples/ci-cd-config.json bunx purgo-cli clean --dry-run # Preview bunx purgo-cli clean # Execute ``` -------------------------------- ### Monorepo Cleanup with Purgo CLI (Bash) Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md This example demonstrates how to clean up a monorepo using Purgo CLI. It involves downloading the monorepo-specific configuration, which uses recursive glob patterns, and then executing the clean command with --reinstall. ```bash curl -o .purgorc.json https://raw.githubusercontent.com/andrebpessoa/purgo-cli/main/examples/monorepo-config.json purgo-cli clean --reinstall ``` -------------------------------- ### Clean Command Examples (CLI) Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt Demonstrates various ways to use the 'clean' command in Purgo CLI to remove build artifacts and dependencies. Supports options for dry runs, dependency reinstallation, specifying paths, overriding targets, using custom configurations, force mode, verbosity, and quiet operation. ```bash # Basic cleanup with confirmation purgo-cli clean # Dry run to preview what will be deleted purgo-cli clean --dry-run # Clean and reinstall dependencies (auto-detects npm/yarn/pnpm/bun) purgo-cli clean --reinstall # Clean specific directory purgo-cli clean --path ./packages/my-app # Override targets from CLI purgo-cli clean --targets "node_modules,dist,.next,coverage" # Use custom global config purgo-cli clean --config ~/.purgo-global.json # Force mode for CI/CD (skip confirmation) purgo-cli clean --force # Verbose output with retry details purgo-cli clean --verbose # Quiet mode (minimal output) purgo-cli clean --quiet # Combined example: clean Next.js app with reinstall purgo-cli clean --path ./my-nextjs-app --reinstall --targets "node_modules,.next,out" ``` -------------------------------- ### Run Purgo CLI for One-time Usage Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md Executes the Purgo CLI command without a global or local installation, useful for quick, one-off cleaning tasks. This command can be run using either Bun or npx. ```bash bunx purgo-cli clean # or npx purgo-cli clean ``` -------------------------------- ### GitHub Actions Workflow for Cleanup Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt This GitHub Actions workflow automates the cleanup of build artifacts using the Purgo CLI. It checks out the repository, downloads a CI configuration, installs the Purgo CLI globally, and then executes cleanup commands. Dependencies: actions/checkout@v3, npm, curl. ```yaml name: Cleanup Build Artifacts on: [push] jobs: cleanup: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Download CI config run: curl -o .purgorc.json https://raw.githubusercontent.com/andreb Pessoa/purgo-cli/main/examples/ci-cd-config.json - name: Install Purgo CLI run: npm install -g purgo-cli - name: Clean artifacts run: purgo-cli clean --force --quiet - name: Reinstall and build run: purgo-cli clean --reinstall --force ``` -------------------------------- ### Clean and Reinstall Dependencies with Purgo CLI Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md Cleans the project and then automatically reinstalls dependencies. This is useful for ensuring a clean slate and up-to-date dependencies. It combines cleanup with a fresh dependency installation. ```bash purgo-cli clean --reinstall ``` -------------------------------- ### Initialize and Use CleanUI for Terminal Output (TypeScript) Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt This TypeScript example shows how to initialize and use the `CleanUI` class from the 'purgo-cli' library to manage terminal user interface elements. It covers starting/stopping spinners, displaying search progress, showing found targets with their sizes, using a progress bar for deletions, displaying a summary of the cleanup operation, and handling retry messages. ```typescript import { CleanUI, type CleanSummary, type TargetWithSize } from 'purgo-cli'; // Initialize with verbosity level const ui = new CleanUI('normal'); // 'verbose' | 'normal' | 'quiet' // Show search progress ui.startSearching(); ui.updateSearching('Calculating target sizes...'); ui.stopSpinner(); // Display targets before deletion const targets: TargetWithSize[] = [ { path: 'node_modules', size: 524288000 }, { path: 'dist', size: 10485760 }, { path: '.next', size: 52428800 } ]; ui.showTargets(targets); // Output: 🔍 Targets found: // - node_modules (500 MB) // - dist (10 MB) // - .next (50 MB) // Total space to be freed: 560 MB // Progress bar for large operations ui.startProgress(100, 'Deleting'); for (let i = 0; i < 100; i++) { ui.updateProgress({ current: i + 1, total: 100, itemName: `file-${i}.txt` }); // Output: [████████████ ] 60% (60/100) - file-59.txt } ui.stopProgress(true, 'Cleanup completed successfully!'); // Show summary with statistics const summary: CleanSummary = { deletedCount: 3, totalSize: 587202560, errorCount: 0, errors: [], elapsedTime: 12.5, speed: 46976204.8 }; ui.showSummary(summary); // Output: ╭──────────────────────────────────╮ // │ ✨ Cleanup Summary ✨ │ // │ │ // │ Items removed: 3 │ // │ Space freed: 560 MB │ // │ Errors: 0 │ // │ Time elapsed: 12.50s │ // │ Speed: 44.8 MB/s │ // ╰──────────────────────────────────╯ // Handle errors gracefully ui.showRetrying('node_modules', 2, 3); // Output: ⟳ Retrying node_modules (attempt 2/3)... ``` -------------------------------- ### Troubleshooting Purgo CLI Command Not Found (Bash) Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md This bash command provides solutions for the 'Command not found' error when trying to use Purgo CLI. It suggests installing the CLI globally or using package runners like `npx` or `bunx`. ```bash # Install globally bun install -g purgo-cli # or use npx/bunx bunx purgo-cli clean ``` -------------------------------- ### Purgo CLI Clean Command with Explicit Targets (Bash) Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md This bash command demonstrates how to use the `purgo-cli clean` command with explicit targets, including lock files, which are not cleaned by default. This provides fine-grained control over what gets removed. ```bash purgo-cli clean --targets "node_modules,dist,package-lock.json" ``` -------------------------------- ### Clone Purgo CLI Repository Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md Downloads the Purgo CLI project files from GitHub to your local machine. This is the first step for development or contributing. ```bash git clone https://github.com/andrebpessoa/purgo-cli.git cd purgo-cli ``` -------------------------------- ### Build Purgo CLI Project Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md Compiles or bundles the project's source code into an executable format using Bun. This is typically done before deployment or local testing. ```bash bun run build ``` -------------------------------- ### Run Purgo CLI Locally Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md Executes the Purgo CLI from the local build using the 'bun run cli' command, often followed by arguments like '--help' to see available options. ```bash bun run cli --help ``` -------------------------------- ### Global Purgo CLI Configuration Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md Demonstrates how to specify a global configuration file for Purgo CLI, allowing for system-wide default settings. This can be done by placing a config file in a standard location or by providing a custom path via the command line. ```bash purgo-cli clean --config /path/to/global-config.json ``` -------------------------------- ### Next.js Project Cleanup with Purgo CLI (Bash) Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt This bash script demonstrates a full cleanup workflow for a Next.js project using Purgo CLI. It includes downloading a project-specific configuration file, running the `clean` command with the `--reinstall` flag to clean targets and reinstall dependencies, and shows the expected output including hook execution. ```bash # Download Next.js config curl -o .purgorc.json https://raw.githubusercontent.com/andrebessoa/purgo-cli/main/examples/nextjs-config.json # Clean with reinstall purgo-cli clean --reinstall # Expected output: # Running preClean hook: echo '🧹 Cleaning Next.js project...' # 🧹 Cleaning Next.js project... # ✓ preClean hook completed # 🔍 Targets found: # - node_modules (450 MB) # - .next (120 MB) # - out (30 MB) # Total space to be freed: 600 MB # ✓ Cleanup completed successfully! # Running postClean hook: bun install && bun run build ``` -------------------------------- ### Load Configuration Programmatically (TypeScript) Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt Demonstrates how to use the `loadConfig` function from the 'purgo-cli' library in TypeScript to load and merge project configurations. It explains the merging priority and caching mechanism. ```typescript import { loadConfig } from 'purgo-cli'; // Load configuration for a project const { config, filepath } = await loadConfig({ projectRoot: '/path/to/project', globalConfigPath: '/home/user/.config/purgo-cli/config.json' }); console.log('Loaded config:', config); // Output: { targets: ['node_modules', 'dist'], ignore: ['**/keep/**'], hooks: {...} } // Configuration merging priority (last wins): // 1. Global config (if exists) // 2. Workspace config (.purgorc, purgo-cli.config.js, etc.) // 3. package.json "purgo-cli" field // With caching - subsequent calls return cached config within 5 minutes const cached = await loadConfig({ projectRoot: '/path/to/project' }); // Returns same config instantly without filesystem reads ``` -------------------------------- ### Purgo CLI Configuration File Formats Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt Illustrates the different formats and locations supported for Purgo CLI configuration files, including JSON, JavaScript, and the package.json field. ```json // .purgorc.json { "targets": ["node_modules", "dist", "build"], "ignore": ["**/important-data/**", "**/keep/**"], "extends": "./base-config.json", "hooks": { "preClean": "npm run backup", "postClean": "npm install && npm run build" } } ``` ```javascript // purgo-cli.config.js export default { targets: ['node_modules', 'dist', '.next'], ignore: ['**/.git', '**/data/**'], hooks: { preClean: 'echo "Starting cleanup"', postClean: 'bun install' } }; ``` ```json // package.json { "name": "my-app", "purgo-cli": { "targets": ["node_modules", "dist"], "ignore": ["**/keep/**"] } } ``` ```json // ~/.config/purgo-cli/config.json (global config) { "ignore": ["**/.git", "**/.env"], "hooks": { "preClean": "echo 'Global pre-clean hook'" } } ``` -------------------------------- ### Programmatic Project Cleanup with Purgo CLI Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt Shows how to use the `cleanProject` function from the 'purgo-cli' library programmatically. Covers basic cleanup, advanced options with detailed configurations, dry runs for safety checks, and silent cleanup for automation. ```typescript import { cleanProject, type CleanOptions } from 'purgo-cli'; // Basic cleanup await cleanProject({ rootDir: process.cwd(), dryRun: false, reinstall: false }); ``` ```typescript // Advanced cleanup with all options const options: CleanOptions = { rootDir: '/path/to/project', targets: ['node_modules', 'dist', '.next', 'coverage'], dryRun: false, reinstall: true, configPath: '/home/user/.purgo-global.json', force: true, verbosity: 'verbose' }; try { await cleanProject(options); console.log('Cleanup completed successfully'); } catch (error) { console.error('Cleanup failed:', error); process.exit(1); } ``` ```typescript // Dry run for CI safety check await cleanProject({ rootDir: process.cwd(), dryRun: true, verbosity: 'normal' }); // Lists files that would be deleted without removing them ``` ```typescript // Silent cleanup for automation await cleanProject({ rootDir: '/app', force: true, verbosity: 'quiet', reinstall: true }); ``` -------------------------------- ### JSON Configuration Inheritance and Extension Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt Demonstrates how to define and extend JSON configurations for Purgo CLI. It shows single file extension, multiple file extension, and how to override properties like 'targets'. ```json // shared-config.json (team base config) { "targets": ["node_modules", "dist"], "ignore": ["**/.git", "**/.env"] } ``` ```json // developer-config.json (extends base) { "extends": "./shared-config.json", "targets": ["node_modules", "dist", "coverage"], "hooks": { "postClean": "bun install" } } ``` ```json // Multiple inheritance (merges in order) { "extends": ["./base.json", "./overrides.json"], "targets": ["node_modules"] } ``` -------------------------------- ### Programmatic Purgo CLI Usage (TypeScript) Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md This TypeScript code snippet shows how to use the `cleanProject` function from the 'purgo-cli' library programmatically. It demonstrates importing the function and calling it with various options like root directory, dry run, reinstall, targets, and config path. ```typescript import { cleanProject } from 'purgo-cli'; await cleanProject({ rootDir: process.cwd(), dryRun: false, reinstall: true, targets: ['node_modules', 'dist'], configPath: './purgo.config.json' }); ``` -------------------------------- ### Troubleshooting Purgo CLI Permission Errors (Bash) Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md This bash command shows a potential solution for 'Permission denied' errors when using Purgo CLI. It suggests using `sudo`, but also notes that checking file permissions is a more recommended approach. ```bash # Try with sudo (not recommended) or check file permissions sudo purgo-cli clean ``` -------------------------------- ### Clean Current Project with Purgo CLI Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md Performs a standard cleanup of the current project, removing common build artifacts and dependencies based on default configurations or project settings. This is the most basic usage command. ```bash purgo-cli clean ``` -------------------------------- ### Execute Project Cleanup with Hooks (TypeScript) Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt This TypeScript code snippet demonstrates how to programmatically trigger the `cleanProject` function from Purgo CLI. It shows how hooks defined in a configuration file are automatically executed in sequence: `preClean`, the actual cleanup, and `postClean`. ```typescript // Hooks run automatically during cleanProject await cleanProject({ rootDir: process.cwd(), configPath: './purgo.config.json' }); // Executes: preClean → cleanup → postClean ``` -------------------------------- ### Monorepo Cleanup Configuration (JSON) Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt This JSON configuration is designed for monorepo projects, specifying multiple common build and artifact directories to be cleaned across various packages. It includes `targets`, `ignore` patterns to prevent unwanted deletions, and a `postClean` hook to ensure dependencies are reinstalled. ```json { "targets": [ "**/node_modules", "**/dist", "**/build", "**/.turbo", "**/.next" ], "ignore": [ "**/node_modules/**/node_modules", "**/.git", "**/important-data/**" ], "hooks": { "postClean": "bun install --frozen-lockfile" } } ``` -------------------------------- ### Define Hooks in Configuration (JSON) Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt This JSON configuration defines targets for cleaning and specifies commands to run before ('preClean') and after ('postClean') the cleaning process. It's used for automating workflows during project cleanup. ```json { "targets": ["node_modules", "dist"], "hooks": { "preClean": "git stash && npm run backup-data", "postClean": "bun install && bun run typecheck && bun run build" } } ``` -------------------------------- ### Purgo CLI Hooks Configuration (JSON) Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md This JSON object defines pre- and post-cleanup hooks for Purgo CLI. These allow users to execute custom commands before ('preClean') and after ('postClean') the main cleanup process. ```json { "hooks": { "preClean": "npm run backup-data", "postClean": "npm run setup && npm run build" } } ``` -------------------------------- ### Initialize Git Feature Branch Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md Creates a new Git branch for developing a specific feature. It's a standard practice for managing code changes and facilitating pull requests. ```bash git checkout -b feature/amazing-feature ``` -------------------------------- ### Preview Deletions with Purgo CLI Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md Executes the Purgo CLI in dry-run mode, showing which files and directories would be deleted without actually performing any removal. This is a safety feature to review the intended cleanup actions. ```bash purgo-cli clean --dry-run ``` -------------------------------- ### Monorepo Cleanup Commands (Bash) Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt These bash commands demonstrate how to use Purgo CLI for cleaning monorepos. The first command cleans the entire monorepo from the root, while the second allows for cleaning a specific package within the monorepo by specifying a path and targets. ```bash # Clean entire monorepo from root purgo-cli clean --reinstall # Clean specific package purgo-cli clean --path ./packages/frontend --targets "node_modules,dist" ``` -------------------------------- ### Detect Package Manager Utility Function Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt Demonstrates the `detectPackageManager` function from 'purgo-cli', which automatically detects the package manager (bun, pnpm, yarn, npm) by looking for lock files. It prioritizes lock files in a specific order and defaults to 'npm' if none are found. ```typescript import { detectPackageManager } from 'purgo-cli'; // Detect from project root const pm = detectPackageManager('/path/to/project'); console.log(pm); // 'bun' | 'pnpm' | 'yarn' | 'npm' // Priority: bun.lockb > bun.lock > pnpm-lock.yaml > yarn.lock > package-lock.json // Returns 'npm' as default if no lock files found // Use in automation scripts const packageManager = detectPackageManager(process.cwd()); console.log(`Installing dependencies with ${packageManager}`); if (packageManager === 'bun') { // Bun detected - use bun install } else if (packageManager === 'pnpm') { // pnpm detected - use pnpm install } ``` -------------------------------- ### Commit Changes with Git Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md Stages and commits the current changes to the Git repository with a descriptive message. This is a crucial step before pushing to a remote branch. ```bash git commit -m 'Add amazing feature' ``` -------------------------------- ### Execute Hook Function for Shell Commands Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt Details the `executeHook` function from 'purgo-cli', which runs shell commands as hooks (e.g., 'preClean', 'postClean') with cross-platform support. It handles command execution, error handling, skipping undefined hooks, and uses the appropriate shell (cmd on Windows, sh on Unix). ```typescript import { executeHook } from 'purgo-cli'; // Execute pre-clean hook await executeHook( 'npm run backup && echo "Backup complete"', 'preClean', process.cwd() ); // Output: Running preClean hook: npm run backup && echo "Backup complete" // ✓ preClean hook completed ``` ```typescript // Execute post-clean hook with error handling try { await executeHook( 'bun install && bun run build', 'postClean', '/path/to/project' ); } catch (error) { console.error('Hook failed:', error); // Output: ✗ postClean hook failed: Command failed } ``` ```typescript // Skip if hook is undefined await executeHook(undefined, 'preClean', process.cwd()); // No-op - returns immediately ``` ```typescript // Cross-platform shell execution (cmd on Windows, sh on Unix) await executeHook('ls -la', 'custom', '/tmp'); // Runs with appropriate shell based on platform ``` -------------------------------- ### executeHook Function Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt Executes shell commands as hooks before or after cleanup operations, with cross-platform support. ```APIDOC ## executeHook Function ### Description Runs shell commands before or after cleanup with cross-platform support. ### Method `executeHook(command: string | undefined, hookName: string, projectDir: string): Promise` ### Parameters #### Path Parameters - **command** (string | undefined) - Optional - The shell command to execute. If undefined, the function does nothing. - **hookName** (string) - Required - The name of the hook (e.g., 'preClean', 'postClean'). Used for logging. - **projectDir** (string) - Required - The directory in which to execute the command. ### Request Example ```typescript import { executeHook } from 'purgo-cli'; // Execute pre-clean hook await executeHook( 'npm run backup && echo "Backup complete"', 'preClean', process.cwd() ); // Execute post-clean hook with error handling try { await executeHook( 'bun install && bun run build', 'postClean', '/path/to/project' ); } catch (error) { console.error('Hook failed:', error); } ``` ### Response #### Success Response (200) - **Promise** - Resolves when the hook command completes successfully. #### Response Example ```json // No explicit JSON response, logs output based on command execution ``` ### Error Handling - Rejects the promise if the executed command fails. ``` -------------------------------- ### cleanProject Function Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt The main function for programmatic project cleanup. It offers extensive control over cleanup operations through various options. ```APIDOC ## cleanProject Function ### Description Main function for programmatic cleanup operations with full control over options. ### Method `cleanProject(options: CleanOptions)` ### Parameters #### Request Body - **rootDir** (string) - Required - The root directory of the project to clean. - **targets** (string[]) - Optional - An array of file/directory patterns to target for deletion. - **dryRun** (boolean) - Optional - If true, lists files that would be deleted without actually removing them. Defaults to `false`. - **reinstall** (boolean) - Optional - If true, re-installs project dependencies after cleanup. Defaults to `false`. - **configPath** (string) - Optional - Path to a custom configuration file. - **force** (boolean) - Optional - Forces cleanup even if certain checks fail. Defaults to `false`. - **verbosity** (string) - Optional - Controls the level of output. Options: 'verbose', 'normal', 'quiet'. Defaults to 'normal'. ### Request Example ```typescript import { cleanProject, type CleanOptions } from 'purgo-cli'; const options: CleanOptions = { rootDir: '/path/to/project', targets: ['node_modules', 'dist', '.next', 'coverage'], dryRun: false, reinstall: true, configPath: '/home/user/.purgo-global.json', force: true, verbosity: 'verbose' }; try { await cleanProject(options); console.log('Cleanup completed successfully'); } catch (error) { console.error('Cleanup failed:', error); process.exit(1); } ``` ### Response #### Success Response (200) - **void** - The function completes without returning a specific value upon success. #### Response Example ```json // No explicit JSON response, logs output based on verbosity level ``` ### Error Handling - Throws an error if the cleanup process fails. ``` -------------------------------- ### Clean Specific Path with Purgo CLI Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md Cleans a specific directory within the project, rather than the entire project root. This allows for targeted cleanup operations on sub-packages or specific build outputs. The path is provided as an argument. ```bash purgo-cli clean --path ./packages/my-app ``` -------------------------------- ### Clean Custom Targets with Purgo CLI Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md Cleans specific targets defined as a comma-separated string, overriding default or configured targets. This provides flexibility to clean custom directories or files based on project needs. ```bash purgo-cli clean --targets "node_modules,dist,.next,coverage" ``` -------------------------------- ### Push Git Branch Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md Uploads local commits from a feature branch to the remote repository. This makes the changes available for review and merging. ```bash git push origin feature/amazing-feature ``` -------------------------------- ### Enable Debug Mode for Purgo CLI Source: https://github.com/andrebpessoa/purgo-cli/blob/main/README.md Activates verbose logging for the Purgo CLI by setting the DEBUG environment variable. This is useful for troubleshooting issues. ```bash DEBUG=purgo-cli:* purgo-cli clean ``` -------------------------------- ### detectPackageManager Function Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt Auto-detects the package manager used in a project based on lock files. ```APIDOC ## detectPackageManager Function ### Description Auto-detects package manager from lock files with priority ordering. ### Method `detectPackageManager(projectDir: string): 'bun' | 'pnpm' | 'yarn' | 'npm'` ### Parameters #### Path Parameters - **projectDir** (string) - Required - The root directory of the project to check. ### Request Example ```typescript import { detectPackageManager } from 'purgo-cli'; const pm = detectPackageManager('/path/to/project'); console.log(pm); // 'bun' | 'pnpm' | 'yarn' | 'npm' // Priority: bun.lockb > bun.lock > pnpm-lock.yaml > yarn.lock > package-lock.json // Returns 'npm' as default if no lock files found ``` ### Response #### Success Response (200) - **string** - The detected package manager ('bun', 'pnpm', 'yarn', or 'npm'). #### Response Example ```json "bun" ``` ``` -------------------------------- ### Convert to Bytes Utility Function Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt Explains the `toBytes` function from 'purgo-cli', used for converting various numeric types and objects with size properties into byte values. It handles numbers, BigInt, objects with 'size', 'bytes', or 'raw' properties, and invalid inputs by returning 0. ```typescript import { toBytes } from 'purgo-cli'; // Convert numbers console.log(toBytes(1024)); // 1024 console.log(toBytes(Number.POSITIVE_INFINITY)); // 0 // Convert BigInt console.log(toBytes(BigInt(2048))); // 2048 // Convert objects with size properties console.log(toBytes({ size: 4096 })); // 4096 console.log(toBytes({ bytes: 8192 })); // 8192 console.log(toBytes({ raw: 16384 })); // 16384 // Handle invalid values console.log(toBytes(null)); // 0 console.log(toBytes(undefined)); // 0 console.log(toBytes('invalid')); // 0 ``` -------------------------------- ### toBytes Function Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt Converts various numeric types and objects with size properties into byte values. ```APIDOC ## toBytes Function ### Description Converts various numeric types to byte values for size calculations. ### Method `toBytes(value: number | bigint | { size?: number; bytes?: number; raw?: number } | null | undefined): number` ### Parameters #### Request Body - **value** (number | bigint | object | null | undefined) - Required - The value to convert to bytes. Can be a number, BigInt, an object with size properties, null, or undefined. ### Request Example ```typescript import { toBytes } from 'purgo-cli'; console.log(toBytes(1024)); // 1024 console.log(toBytes({ size: 4096 })); // 4096 console.log(toBytes(BigInt(2048))); // 2048 console.log(toBytes(null)); // 0 ``` ### Response #### Success Response (200) - **number** - The value converted to bytes. Returns 0 for invalid inputs. #### Response Example ```json 1024 ``` ``` -------------------------------- ### Deduplicate Paths Utility Function Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt Illustrates the use of the `deduplicatePaths` function from 'purgo-cli' to remove nested paths from an array, preventing redundant cleanup operations. It handles both Windows and Unix path formats. ```typescript import { deduplicatePaths } from 'purgo-cli'; // Remove nested paths const paths = [ 'node_modules', 'node_modules/package-a', 'node_modules/package-b/node_modules', 'dist', 'src/dist', 'packages/app/node_modules' ]; const deduplicated = deduplicatePaths(paths); console.log(deduplicated); // Output: ['node_modules', 'dist', 'src/dist', 'packages/app/node_modules'] ``` ```typescript // Handles Windows and Unix paths const mixedPaths = [ 'app\node_modules', 'app/node_modules/lodash', 'app\dist' ]; const result = deduplicatePaths(mixedPaths); // Output: ['app/node_modules', 'app/dist'] ``` -------------------------------- ### deduplicatePaths Function Source: https://context7.com/andrebpessoa/purgo-cli/llms.txt Removes nested paths from an array to prevent redundant deletion operations. ```APIDOC ## deduplicatePaths Function ### Description Removes nested paths to avoid redundant delete operations. ### Method `deduplicatePaths(paths: string[]): string[]` ### Parameters #### Request Body - **paths** (string[]) - Required - An array of file/directory paths. ### Request Example ```typescript import { deduplicatePaths } from 'purgo-cli'; const paths = [ 'node_modules', 'node_modules/package-a', 'node_modules/package-b/node_modules', 'dist', 'src/dist', 'packages/app/node_modules' ]; const deduplicated = deduplicatePaths(paths); console.log(deduplicated); // Output: ['node_modules', 'dist', 'src/dist', 'packages/app/node_modules'] ``` ### Response #### Success Response (200) - **string[]** - An array of deduplicated paths. #### Response Example ```json [ "node_modules", "dist", "src/dist", "packages/app/node_modules" ] ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.