Skip to content

Commit

Permalink
feat: rocks check
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed Dec 29, 2024
1 parent 93fba30 commit 07e1fa9
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
38 changes: 38 additions & 0 deletions rocks-bin/src/check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use eyre::{OptionExt, Result};
use rocks_lib::{
build::BuildBehaviour,
config::Config,
lockfile::PinnedState::Pinned,
manifest::Manifest,
operations::{self, install},
progress::MultiProgress,
project::Project,
};

pub async fn check(config: Config) -> Result<()> {
let project = Project::current()?.ok_or_eyre("Not in a project!")?;

let src_dir = project.src_dir().ok_or_eyre(
"No source directory found! Expected a `src/` or `lua/` directory at the project root.",
)?;

let manifest = Manifest::from_config(config.server(), &config).await?;

install(
vec![(BuildBehaviour::NoForce, "luacheck".parse()?)],
Pinned,
&manifest,
&config,
MultiProgress::new_arc(),
)
.await?;

operations::run(
"luacheck",
vec![src_dir.to_str().unwrap().to_string()],
config,
)
.await?;

Ok(())
}
3 changes: 3 additions & 0 deletions rocks-bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use update::Update;
use upload::Upload;

pub mod build;
pub mod check;
pub mod debug;
pub mod download;
pub mod fetch;
Expand Down Expand Up @@ -110,6 +111,8 @@ pub enum Commands {
Add,
/// Build/compile a rock.
Build(Build),
/// Runs `luacheck` in the current project.
Check,
/// [UNIMPLEMENTED] Query information about Rocks's configuration.
Config,
/// Various debugging utilities.
Expand Down
4 changes: 4 additions & 0 deletions rocks-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{path::PathBuf, time::Duration};
use clap::{Parser, Subcommand};
use rocks::{
build::{self, Build},
check,
debug::Debug,
download::{self, Download},
fetch, format,
Expand Down Expand Up @@ -95,6 +96,8 @@ pub enum Commands {
Add,
/// Build/compile a rock.
Build(Build),
/// Runs `luacheck` in the current project.
Check,
/// [UNIMPLEMENTED] Query information about Rocks's configuration.
Config,
/// Various debugging utilities.
Expand Down Expand Up @@ -211,6 +214,7 @@ async fn main() {
Commands::Pin(pin_data) => pin::set_pinned_state(pin_data, config, Pinned).unwrap(),
Commands::Unpin(pin_data) => pin::set_pinned_state(pin_data, config, Unpinned).unwrap(),
Commands::Upload(upload_data) => upload::upload(upload_data, config).await.unwrap(),
Commands::Check => check::check(config).await.unwrap(),
Commands::Add => unimplemented!(),
Commands::Config => unimplemented!(),
Commands::Doc => unimplemented!(),
Expand Down
14 changes: 14 additions & 0 deletions rocks-lib/src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ impl Project {
pub fn tree(&self, lua_version: LuaVersion) -> io::Result<Tree> {
Tree::new(self.root.clone(), lua_version)
}

pub fn src_dir(&self) -> Option<PathBuf> {
let root = self.root();

// Prioritise the `lua/` directory, in case the project
// is mixed with a different language which also has a `src/` directory.
if root.join("lua").exists() {
Some(root.join("lua"))
} else if root.join("src").exists() {
Some(root.join("src"))
} else {
None
}
}
}

// TODO: Add plenty of tests

0 comments on commit 07e1fa9

Please sign in to comment.