kondo

repository·master·Indexed 25 days ago

https://github.com/tbillington/kondo

A tool for reclaiming disk space by cleaning up heavy dependency and build directories (such as node_modules, target, and build) across various project types. Version 0.9.0 provides both a CLI and a GUI, supporting a wide range of ecosystems including Rust (Cargo), JavaScript/TypeScript (Node, Turborepo), Python, Java/JVM (Maven, Gradle, SBT), C++ (CMake), and others like Unity, Unreal, and .NET.

Tokens
2.3K
Snippets
1
Records
17
Agent score
81%

What's inside kondo

  1. Install the Kondo CLI

    master

    Kondo can be installed via various package managers depending on your operating system, or built from source using Rust.

    Warning: Kondo performs rm -rf operations with a prompt. Use at your own discretion and ensure you have backups of your projects.

  2. Build Kondo for development

    master

    To build the project from source, use cargo build and cargo run.

    • For the CLI, run these commands from the repository root.
    • For the GUI, navigate into the kondo-ui directory before running the commands.

    Output binaries are located in target/debug/ or target/release/ following standard Cargo defaults.

  3. Use the Kondo CLI

    master

    The Kondo CLI cleans dependency and build directories (like node_modules, target, build) from supported project types.

    By default, running kondo without arguments operates on the current directory. You can specify one or more paths to scan, and use the --older flag to filter projects based on their last modified date.

  4. How the project list and selection works

    master

    The Kondo UI manages projects through a specific lifecycle:

    1. Discovery: Users select directories via the select_directory handler, which spawns a background thread to scan for projects using kondo_lib::scan.
    2. Project List: Projects are stored in a ProjectList resource. Each project is wrapped in a ProjectListEntry which tracks its kondo_lib::Project data, its calculated size, and its ProjectListEntryStatus (Uncleaned, Cleaning, or Cleaned).
    3. Selection: Clicking a project entry updates the SelectedProject resource. This triggers a UI update that displays detailed information about the selected project, including its path, type, and a breakdown of directory sizes (artifact vs non-artifact).
    4. Cleaning: When the "Delete Artifacts" button is clicked in the selection view, the project's clean() method is called in an asynchronous task. The status is updated to Cleaning and eventually Cleaned once the task completes.
  5. Supported ProjectTypes in Kondo

    master

    Kondo recognizes a wide variety of project types based on specific marker files (like Cargo.toml or package.json). Supported types include:

    • Rust: Cargo
    • JavaScript/TypeScript: Node (includes special detection for Node (React Native) if ios or android directories are present), Turborepo
    • Python: Python, Jupyter
    • Java/JVM: Maven, Gradle, SBT
    • C++/Build Systems: CMake
    • Mobile/Other: Swift, Cocoapods, Pub (Flutter), Elixir, Zig, Godot4, Unity, Unreal, Dotnet, Terraform, Pixi, Composer.

    Note: Detection logic for some types (like Godot4 vs Dotnet) may depend on the presence of specific sub-files within the directory.

  6. Use the Kondo CLI to clean project directories

    master

    Kondo is a tool that recursively scans directories to find and clean build artifacts from various project types (e.g., Cargo, Node, Maven, Python, etc.).

    Basic Usage

    Run kondo in a directory to scan the current directory and its subdirectories for projects to clean.

    Common Commands

    • Dry Run: List directories that would be cleaned without actually deleting anything. kondo --dry-run or kondo -n
    • Clean All: Clean all found projects automatically without prompting for confirmation. kondo --all or kondo -a
    • Quiet Mode: Suppress output. Use -q for minimal output or -qq to prevent all output (note: -q requires --all).
    • Filter by Age: Only look at projects that haven't been modified for a certain amount of time. Use the --older flag with a time unit (e.g., 20d for 20 days).

    Supported Project Types

    Kondo supports a wide range of ecosystems including: Cargo, Node, Unity, SBT, Haskell Stack, Maven, Unreal Engine, Jupyter Notebook, Python, CMake, Composer, Pub, Elixir, Swift, Gradle, and .NET.

  7. Configure scanning behavior with ScanOptions

    master

    When performing scans or calculating directory sizes, use the ScanOptions struct to define traversal constraints:

    • follow_symlinks: A boolean determining whether to follow symbolic links.
    • same_file_system: A boolean determining whether to stay within the same filesystem during traversal.
  8. Create a custom left-aligned button with `button_left`

    master

    The button_left function is a helper for creating UI buttons that are styled for the Kondo interface. It provides standard padding, alignment, hover effects, and cursor styling (Pointer). It accepts ButtonProps for styling and an overrides bundle for additional properties.

    pub fn button_left<C: bevy::ecs::spawn::SpawnableList<ChildOf> + Send + Sync + 'static, B: Bundle>(
        props: ButtonProps,
        overrides: B,
        children: C,
    ) -> impl Bundle
  9. Represent and manage projects with the Project struct

    master

    The Project struct is the core abstraction for representing a detected software project. It encapsulates the ProjectType (e.g., Cargo, Node, Python, Unity) and the filesystem path to the project root.

    Key capabilities include:

    • Identifying artifact directories: Use .artifact_dirs() to get a list of directories that contain build artifacts (e.g., target for Cargo, node_modules for Node) which can be safely cleaned.
    • Calculating size: Use .size(&options) to get the total size of artifact directories, or .size_dirs(&options) to get a detailed ProjectSize breakdown including artifact vs. non-artifact sizes.
    • Cleaning artifacts: Use .clean() to automatically delete all identified artifact directories for that project type.
    • Metadata: Use .type_name() to get a human-readable string of the project type and .last_modified(&options) to find the most recent modification time within the project tree.
  10. Sort the project list by Name or Size

    master

    You can sort the displayed project list using the SortProjectList command. This command is typically triggered via UI button interactions.

    Available variants:

    • SortProjectList::Name: Sorts projects alphabetically by their file name.
    • SortProjectList::Size: Sorts projects by their total size in descending order.
  11. Get detailed project size breakdown with ProjectSize

    master

    The Project::size_dirs method returns a ProjectSize struct, which provides a granular view of the filesystem usage within a project root.

    ProjectSize contains:

    • artifact_size: Total size of all directories identified as build artifacts.
    • non_artifact_size: Total size of all other files and directories.
    • dirs: A Vec<(String, u64, bool)> where each tuple contains the directory name, its total size, and a boolean indicating if it is an artifact directory.