Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/cmd/run.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use std::{
process::Command,
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
time::Duration,
path::Path, process::Command, sync::{
Arc, atomic::{AtomicBool, Ordering}
}, time::Duration
};

use crate::config::{self};

/// More in depth errors that could cause a project not to run
#[derive(Debug)]
pub enum OsedaRunError {
BuildError(String),
ServeError(String),
NotOsedaProjectError(String),
}

impl std::error::Error for OsedaRunError {}
Expand All @@ -20,6 +20,7 @@ impl std::fmt::Display for OsedaRunError {
match self {
Self::BuildError(msg) => write!(f, "Oseda Build Error: {}", msg),
Self::ServeError(msg) => write!(f, "Oseda Serve Error: {}", msg),
Self::NotOsedaProjectError(msg) => write!(f, "Current working directory is not an Oseda project: {}", msg)
}
}
}
Expand All @@ -39,8 +40,16 @@ pub fn run() -> Result<(), OsedaRunError> {
run_with_shutdown(Arc::new(AtomicBool::new(false)))
}

pub fn is_cwd_oseda_project() -> bool {
Path::new(config::CONFIG_FILE_NAME).try_exists().is_ok_and(|exists| exists)
}

pub fn run_with_shutdown(shutdown_flag: Arc<AtomicBool>) -> Result<(), OsedaRunError> {
// command run failure and command status are considered different, handled accordingly
if !is_cwd_oseda_project(){
return Err(OsedaRunError::NotOsedaProjectError("oseda-config.json not found".to_string()));
}

match Command::new("npx").arg("vite").arg("build").status() {
Ok(status) => {
if !status.success() {
Expand Down
4 changes: 3 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use crate::license::License;
use crate::tags::DefinedTag;
use crate::{github, license};

pub const CONFIG_FILE_NAME: &str = "oseda-config.json";

pub fn read_config_file<P: AsRef<std::path::Path>>(
path: P,
) -> Result<OsedaConfig, OsedaCheckError> {
Expand Down Expand Up @@ -50,7 +52,7 @@ pub fn read_and_validate_config() -> Result<OsedaConfig, OsedaCheckError> {
OsedaCheckError::DirectoryNameMismatch("Could not get path of working directory".to_owned())
})?;

let config_path = path.join("oseda-config.json");
let config_path = path.join(CONFIG_FILE_NAME);

let conf = read_config_file(config_path)?;

Expand Down
Loading