forked from Cutieguwu/raven
Compare commits
3 Commits
60ec65dc94
...
27f784e1f0
| Author | SHA1 | Date | |
|---|---|---|---|
| 27f784e1f0 | |||
|
|
aa851f7616 | ||
|
|
dafc6ea885 |
16
Cargo.toml
16
Cargo.toml
@@ -2,23 +2,27 @@
|
||||
name = "raven"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
authors = ["Olivia Brooks", "Adrian Long"]
|
||||
repository = "https://gitea.cutieguwu.ca/Cutieguwu/raven"
|
||||
license = "MIT"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
bytesize = "2.3"
|
||||
ron = "0.12"
|
||||
sha256 = "1.6.0"
|
||||
sha256 = "1.6"
|
||||
subprocess = "0.2"
|
||||
toml = "0.9"
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0"
|
||||
features =["derive"]
|
||||
|
||||
[dependencies.clap]
|
||||
version = "4.5"
|
||||
features = ["derive"]
|
||||
features = ["cargo", "derive"]
|
||||
|
||||
[dependencies.semver]
|
||||
version = "1.0"
|
||||
features = ["serde"]
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0"
|
||||
features =["derive"]
|
||||
|
||||
@@ -5,6 +5,8 @@ use clap::{ArgAction, Parser, Subcommand};
|
||||
pub static CONFIG: LazyLock<Args> = LazyLock::new(|| Args::parse());
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(author, version)]
|
||||
#[command(help_template = "{author-section}\n{usage-heading} {usage}\n\n{all-args}")]
|
||||
pub struct Args {
|
||||
#[command(subcommand)]
|
||||
pub command: Command,
|
||||
|
||||
33
src/main.rs
33
src/main.rs
@@ -17,14 +17,6 @@ use nest::{Class, NEST, NestLock};
|
||||
use anyhow::Context;
|
||||
use bytesize::ByteSize;
|
||||
|
||||
const DIR_TARGET: LazyLock<PathBuf> = LazyLock::new(|| PathBuf::from("target/"));
|
||||
const DIR_SRC: LazyLock<PathBuf> = LazyLock::new(|| PathBuf::from("src/"));
|
||||
const DIR_MAIN: LazyLock<PathBuf> = LazyLock::new(|| DIR_SRC.join("main/"));
|
||||
const DIR_TEST: LazyLock<PathBuf> = LazyLock::new(|| DIR_SRC.join("test/"));
|
||||
|
||||
const F_NEST_TOML: LazyLock<PathBuf> = LazyLock::new(|| PathBuf::from("Nest.toml"));
|
||||
const F_NEST_LOCK: LazyLock<PathBuf> = LazyLock::new(|| PathBuf::from("Nest.lock"));
|
||||
|
||||
pub static PROJECT_ROOT: LazyLock<PathBuf> = LazyLock::new(|| {
|
||||
// Start from CWD
|
||||
let cwd = std::env::current_dir().expect("Failed to get current working directory");
|
||||
@@ -44,6 +36,14 @@ pub static PROJECT_ROOT: LazyLock<PathBuf> = LazyLock::new(|| {
|
||||
probe
|
||||
});
|
||||
|
||||
const DIR_TARGET: LazyLock<PathBuf> = LazyLock::new(|| PROJECT_ROOT.join("target/"));
|
||||
const DIR_SRC: LazyLock<PathBuf> = LazyLock::new(|| PROJECT_ROOT.join("src/"));
|
||||
const DIR_MAIN: LazyLock<PathBuf> = LazyLock::new(|| DIR_SRC.join("main/"));
|
||||
const DIR_TEST: LazyLock<PathBuf> = LazyLock::new(|| DIR_SRC.join("test/"));
|
||||
|
||||
const F_NEST_TOML: LazyLock<PathBuf> = LazyLock::new(|| PathBuf::from("Nest.toml"));
|
||||
const F_NEST_LOCK: LazyLock<PathBuf> = LazyLock::new(|| PathBuf::from("Nest.lock"));
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
// Ensure that Nest.toml exists, if the requested command depends upon it.
|
||||
if CONFIG.command.depends_on_nest() && NEST.is_err() {
|
||||
@@ -91,11 +91,7 @@ fn init() -> anyhow::Result<()> {
|
||||
.context("Unable to convert OsStr to str")?
|
||||
.to_owned();
|
||||
|
||||
// Make src, target, tests
|
||||
for dir in [DIR_SRC, DIR_MAIN, DIR_TARGET, DIR_TEST] {
|
||||
std::fs::create_dir_all(dir.clone())?;
|
||||
}
|
||||
|
||||
// ORDER MATTERS. THIS MUST COME FIRST.
|
||||
// Make config file.
|
||||
if let Result::Ok(mut f) = OpenOptions::new()
|
||||
.write(true)
|
||||
@@ -129,6 +125,11 @@ fn init() -> anyhow::Result<()> {
|
||||
)?;
|
||||
}
|
||||
|
||||
// Make src, target, tests
|
||||
for dir in [DIR_SRC, DIR_MAIN, DIR_TARGET, DIR_TEST] {
|
||||
std::fs::create_dir_all(dir.clone())?;
|
||||
}
|
||||
|
||||
// Make src/main/Main.java
|
||||
if let Result::Ok(mut f) = OpenOptions::new().write(true).create_new(is_empty).open(
|
||||
DIR_MAIN
|
||||
@@ -185,7 +186,7 @@ fn new(project_name: String) -> anyhow::Result<()> {
|
||||
}
|
||||
|
||||
fn build() -> anyhow::Result<()> {
|
||||
let mut targets: Vec<PathBuf> = crate::fs::expand_files(DIR_SRC.as_path())?
|
||||
let mut targets: Vec<PathBuf> = crate::fs::expand_files(PROJECT_ROOT.clone().join(DIR_SRC.as_path()))?
|
||||
.into_iter()
|
||||
.filter(|f| {
|
||||
f.extension()
|
||||
@@ -254,7 +255,7 @@ fn test(assertions: bool) -> anyhow::Result<(Option<String>, Option<String>)> {
|
||||
.compile(DIR_TEST.as_path())?;
|
||||
|
||||
// Change cwd to avoid Java pathing issues.
|
||||
crate::env::set_cwd(PROJECT_ROOT.join(DIR_TARGET.as_path()))?;
|
||||
crate::env::set_cwd(DIR_TARGET.as_path())?;
|
||||
|
||||
java::JVMBuilder::new()
|
||||
.assertions(assertions)
|
||||
@@ -267,5 +268,5 @@ fn test(assertions: bool) -> anyhow::Result<(Option<String>, Option<String>)> {
|
||||
|
||||
fn clean() {
|
||||
let _ = std::fs::remove_file(PROJECT_ROOT.join(F_NEST_LOCK.as_path()));
|
||||
let _ = std::fs::remove_dir_all(PROJECT_ROOT.join(DIR_TARGET.as_path()));
|
||||
let _ = std::fs::remove_dir_all(DIR_TARGET.join("/*").as_path());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user