I think I finished it...

This commit is contained in:
Cutieguwu
2026-02-15 17:39:48 -05:00
parent 0fad1b74bc
commit 79629391c5
33 changed files with 215 additions and 389 deletions

View File

@@ -10,7 +10,6 @@ categories = ["development-tools::build-utils"]
repository.workspace = true
publish.workspace = true
test.workspace = true
[dependencies]
anyhow.workspace = true
@@ -20,5 +19,4 @@ core.workspace = true
fs.workspace = true
io.workspace = true
java.workspace = true
path.workspace = true
toml.workspace = true

View File

@@ -1,19 +0,0 @@
use std::path::PathBuf;
use anyhow::Context;
pub fn in_path<S: AsRef<str>>(binary: S) -> Result<bool, std::env::VarError> {
std::env::var("PATH").and_then(|paths| {
Ok(paths
.split(":")
.map(|p| PathBuf::from(p).join(binary.as_ref()))
.any(|p| p.exists()))
})
}
pub fn get_project_root() -> anyhow::Result<PathBuf> {
nest::locate_nest().context(
"Attempted to find Nest.toml, but it could not be located.\n
It's likely that a call for get_project_root occurred before runtime checks were ran.",
)
}

View File

@@ -1,68 +1,37 @@
mod env;
mod manager;
use std::fs::OpenOptions;
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
use core::prelude::WorkspaceHandler;
use anyhow::anyhow;
use cli::{CLI_ARGS, Command};
use java::{FN_JAVA_VERSION, JAVA_EXT_CLASS, JAVA_EXT_SOURCE};
//use nest::prelude::{Class, F_NEST_LOCK, F_NEST_TOML, Nest, NestLock, Prey, PreyLock};
//use path::{PathHandled, PathHandler};
use anyhow::{Context, anyhow};
use bytesize::ByteSize;
fn main() -> anyhow::Result<()> {
// Ensure that ph is constructed with the assumption that it is at the project root.
let mut ph = match CLI_ARGS.command.clone() {
Command::Init => PathHandler::new(std::env::current_dir()?),
Command::New { name, .. } => PathHandler::new(std::env::current_dir()?.join(name)),
_ => PathHandler::new(crate::env::get_project_root()?),
};
// type_ is yet unused.
if let Command::New { project_name, .. } = &CLI_ARGS.command {
new(project_name.to_owned())?;
}
// Ensure that Nest.toml exists in the way functions need.
// Init does not need one, but it's easier to deal with the minor unnecessary computation
// of running the default contrustor, thand to fight the compiler.
let mut nest = match CLI_ARGS.command {
Command::Build | Command::Run { .. } => Nest::try_from(ph.project_root().join(F_NEST_TOML))
.map_err(|err| {
anyhow!(
"No {} found in project directory: {}.\n{}",
F_NEST_TOML,
ph.project_root().display(),
err.to_string()
)
})?,
_ => Nest::default(),
};
let project_root = std::env::current_dir()?;
match CLI_ARGS.command.clone() {
Command::Init => init(ph)?,
Command::New { name, .. } => {
new(name.to_owned())?;
init(ph)?;
}
Command::Build => {
build(&mut ph, &mut nest)?;
}
let mut wh: WorkspaceHandler = match &CLI_ARGS.command {
Command::New { .. } | Command::Init => WorkspaceHandler::new(project_root),
_ => WorkspaceHandler::load(project_root),
}
.map_err(|err| anyhow!(err))?;
dbg!();
match &CLI_ARGS.command {
Command::New { .. } | Command::Init => wh.init(),
Command::Build => wh.build(),
Command::Run {
entry_point,
assertions,
} => {
build(&mut ph, &mut nest)?;
run(
&mut ph,
entry_point.unwrap_or(nest.workspace.default_package),
assertions.into(),
)?;
}
Command::Test { assertions } => {
test(&mut ph, assertions.into())?;
}
Command::Clean => clean(&mut ph),
} => wh
.build()
.map_err(|err| anyhow!(err))?
.run(entry_point.to_owned(), assertions.into()),
Command::Clean => wh.clean(),
Command::Test { .. } => unimplemented!(),
}
.map_err(|err| anyhow!(err))?;
Ok(())
}
@@ -75,24 +44,3 @@ fn new(project_name: String) -> anyhow::Result<()> {
Ok(())
}
fn run<P: AsRef<Path>>(
ph: &mut PathHandler,
entry_point: P,
assertions: bool,
) -> anyhow::Result<(Option<String>, Option<String>)> {
// JRE pathing will be messed up without this.
std::env::set_current_dir(ph.dir_target())?;
java::runtime::JVMBuilder::new(ph.dir_target())
.assertions(assertions)
.monitor(true)
.build()
.run(entry_point)
.map_err(|err| anyhow!(err))
}
fn clean(ph: &mut PathHandler) {
let _ = std::fs::remove_file(ph.project_root().join(F_NEST_LOCK));
let _ = std::fs::remove_dir_all(ph.dir_target());
}

View File

@@ -1,11 +0,0 @@
use std::collections::HashSet;
use nest::prelude::{Nest, NestLock};
use path::PathHandler;
pub struct ProjectManager {
ph: PathHandler,
nest: Nest,
nest_lock: NestLock,
// HashSet<Crates { prey, prey_lock }>
}