Skip to content

Commit

Permalink
fixup project list update, selected impl
Browse files Browse the repository at this point in the history
  • Loading branch information
tbillington committed Aug 30, 2024
1 parent 495dbc2 commit 6f0514d
Show file tree
Hide file tree
Showing 7 changed files with 620 additions and 333 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = ["kondo", "kondo-lib", "path-trie"]
resolver = "2"
default-members = ["kondo"]

[workspace.dependencies]
path-trie = { path = "./path-trie" }
Expand All @@ -11,9 +12,9 @@ kondo-lib = { path = "./kondo-lib" }

[profile.distribution]
inherits = "release"
# strip = true
strip = true
lto = true
codegen-units = 1
panic = 'abort'
# debug = 0
debug = true
# debug = true
149 changes: 149 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
To Release

- Tag commit
- Build Kondo-ui for win/linux/mac
- Push Tag
- Add kondo-ui to release artifacts
- Post to reddit, users.rust-lang.org?

# Kondo 🧹

Cleans `node_modules`, `target`, `build`, etc from your projects.

Excellent if

- 💾 You want to back up your code but don't want to include GBs of dependencies
- 🧑‍🎨 You try out lots of projects but hate how much space they occupy
- ⚡️ You like keeping your disks lean and zippy

<br />

<p align="center">
<strong>14 Supported Project Types</strong>
</p>
<p align="center">
<a href="https://doc.rust-lang.org/cargo/">Cargo</a>
- <a href="https://nodejs.org/">Node</a>
- <a href="https://unity.com/">Unity</a>
- <a href="https://www.scala-sbt.org/">Scala SBT</a>
- <a href="https://docs.haskellstack.org/">Haskell Stack</a>
- <a href="https://maven.apache.org/">Maven</a>
- <a href="https://www.unrealengine.com/">Unreal Engine</a>
- <a href="https://www.python.org/">Python</a>
</p>
<p align="center">
<a href="https://jupyter.org/">Jupyter Notebook</a>
- <a href="https://cmake.org">CMake</a>
- <a href="https://getcomposer.org/">Composer</a>
- <a href="https://dart.dev/">Pub</a>
- <a href="https://elixir-lang.org/">Elixir</a>
- <a href="https://swift.org/">Swift</a>
</p>
<p align="center">
Pull requests are welcome, it's <a href="https://github.com/tbillington/kondo/pull/76/files">easy to extend</a>!
</p>

<img width="972" alt="kondo cli cleaning projects" src="https://user-images.githubusercontent.com/2771466/222950622-475bc6cc-7b91-47c2-86b2-5948bee4fe8e.png">

<img width="1112" alt="kondo gui displaying projects" src="https://user-images.githubusercontent.com/2771466/222950846-964162a1-80c9-4cdf-a9a8-d818ba4cb34a.png">

<details>
<summary>CLI Video</summary>

[kondo-cli.webm](https://user-images.githubusercontent.com/2771466/222949617-0ed621bc-ac4e-495a-9165-036a3a597d34.webm)

</details>

<details>
<summary>GUI Video</summary>

[kondo-ui.webm](https://user-images.githubusercontent.com/2771466/222951044-13484711-6107-45d4-aaa3-3140bbbba898.webm)

</details>

## Installation

### Command Line

**Homebrew**

```sh
brew install kondo
```

**Source**

Requires [rust](https://www.rust-lang.org/tools/install).

```sh
git clone https://github.com/tbillington/kondo.git
cargo install --path kondo/kondo
```

**Others**

Binaries available on the [releases page](https://github.com/tbillington/kondo/releases).

<a href="https://repology.org/project/kondo/versions">
<img src="https://repology.org/badge/vertical-allrepos/kondo.svg" alt="Packaging status">
</a>

### Graphic User Interface

**Source**

Requires [rust](https://www.rust-lang.org/tools/install). You may need [platform specific dependencies on linux](https://github.com/xi-editor/druid#platform-notes).

```sh
git clone https://github.com/tbillington/kondo.git
cargo install --path kondo/kondo-ui
```

Binaries available on the [releases page](https://github.com/tbillington/kondo/releases).

<a href="https://repology.org/project/rust:kondo-ui/versions">
<img src="https://repology.org/badge/vertical-allrepos/rust:kondo-ui.svg" alt="Packaging status">
</a>

## Usage

### Command Line Interface

Running `kondo` without a directory specified will run in the current directory.

```sh
kondo
```

Supplying a path will tell `kondo` where to start. Multiple paths are supported.

```sh
kondo code/my_project code/my_project_2
```

Passing a time will filter projects to those that haven't been modified for at least the specified period. See `kondo --help` for the full list of options.

```sh
kondo --older 3M # only projects with last modified greater than 3 months
kondo -o3M # shorthand
```

More options such as quiet mode, folowing symlinks, and filesystem restriction are viewable with `kondo --help`.

## Building/Development

To build the cli `kondo` you can run `cargo build` and `cargo run` from the projects root directory.

To build the gui `kondo-ui` you must first navigate into the `kondo-ui` directory, then you can run `cargo build` and `cargo run`.

The output binaries will be located in `target/debug/` or `target/release/` per [Cargo](https://doc.rust-lang.org/cargo/index.html) defaults.

## Similar Projects

- [The Tin Summer](https://github.com/vmchale/tin-summer)
- [Detox](https://github.com/whitfin/detox)
- [Sweep](https://github.com/woubuc/sweep)
- [npkill](https://github.com/voidcosmos/npkill)
- [Cargo Cleanall](https://github.com/LeSnake04/cargo-cleanall)
- [Cargo Sweep](https://github.com/holmgr/cargo-sweep)
- [Cargo Wipe](https://github.com/mihai-dinculescu/cargo-wipe)
43 changes: 43 additions & 0 deletions kondo/src/component.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use ratatui::{
crossterm::event::{Event, KeyEvent, MouseEvent},
prelude::*,
};

pub(crate) enum Action {
Quit,
Consumed,
Noop,
Push(Box<dyn Component>),
}

pub(crate) trait Component {
fn init(&mut self) -> Result<(), ()> {
Ok(())
}

fn handle_events(&mut self, event: Option<Event>) -> Action {
match event {
// Some(Event::Quit) => Action::Quit,
// Some(Event::Tick) => Action::Tick,
Some(Event::Key(key_event)) => self.handle_key_events(key_event),
Some(Event::Mouse(mouse_event)) => self.handle_mouse_events(mouse_event),
// Some(Event::Resize(x, y)) => Action::Resize(x, y),
Some(_) => Action::Noop,
None => Action::Noop,
}
}

fn handle_key_events(&mut self, key: KeyEvent) -> Action {
Action::Noop
}

fn handle_mouse_events(&mut self, mouse: MouseEvent) -> Action {
Action::Noop
}

fn update(&mut self, action: Action) -> Action {
Action::Noop
}

fn render(&mut self, area: Rect, buf: &mut Buffer);
}
74 changes: 74 additions & 0 deletions kondo/src/discovery.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use std::path::PathBuf;

use kondo_lib::{crossbeam::Receiver, Project as _};

use crate::{pretty_size2, print_elapsed, TableEntry};

pub(crate) fn discover(dirs: Vec<PathBuf>) -> Receiver<TableEntry> {
let rx = kondo_lib::run_local(dirs.into_iter(), None);
let (ttx, rrx) = kondo_lib::crossbeam::unbounded();
std::thread::spawn(move || {
let mut get_id = {
let mut next_id = 0;
move || {
let id = next_id;
next_id += 1;
id
}
};

while let Ok((path, proj)) = rx.recv() {
let name = proj
.name(&path)
.unwrap_or_else(|| {
path.file_name()
.unwrap_or_default()
.to_string_lossy()
.into_owned()
})
.into_boxed_str();

let focus = proj
.project_focus(&path)
.map(|focus| focus.into_boxed_str());

let artifact_bytes = proj.artifact_size(&path);

// if artifact_bytes == 0 {
// continue;
// }

let artifact_bytes_fmt = pretty_size2(artifact_bytes);

let mut last_modified_secs = None;
if let Ok(lm) = proj.last_modified(&path) {
if let Ok(elapsed) = lm.elapsed() {
let secs = elapsed.as_secs();
last_modified_secs = Some((secs, print_elapsed(secs)));
}
}

let path_str = path.to_string_lossy().into_owned().into_boxed_str();

let path_chars = path_str.chars().count() as u16;

let entry = TableEntry {
id: get_id(),
proj,
name,
focus,
path,
path_str,
path_chars,
artifact_bytes,
artifact_bytes_fmt,
last_modified_secs,
};

if ttx.send(entry).is_err() {
break;
}
}
});
rrx
}
Loading

0 comments on commit 6f0514d

Please sign in to comment.