diff --git a/src/main.rs b/src/main.rs index c6319b3..0159bd4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +pub mod publish; pub mod watcher; use std::{path::PathBuf, sync::mpsc}; @@ -10,8 +11,8 @@ use tracing_subscriber::EnvFilter; #[derive(Debug, Parser)] #[command(name = "lumina", version, about)] struct Cli { - #[arg(short = 'f', long)] - file: Option, + #[arg(short = 'p', long)] + path: Option, #[arg(short = 'v', long)] verbose: bool, } @@ -39,14 +40,14 @@ fn main() -> Result<()> { .with_timer(timer) .init(); - if let Some(file) = args.file { + if let Some(path) = args.path { let (tx, rx) = mpsc::channel::>(); // Automatically select the best implementation for your platform. let mut watcher = notify::recommended_watcher(tx)?; - watcher.watch(&file, RecursiveMode::Recursive)?; + watcher.watch(&path, RecursiveMode::Recursive)?; for res in rx { match res { - Ok(event) => match watcher::watch(event) { + Ok(event) => match watcher::watch(event, &path) { Ok(()) => (), Err(e) => error!("internal error: {:?}", e), }, diff --git a/src/emacs/mod.rs b/src/publish/mod.rs similarity index 100% rename from src/emacs/mod.rs rename to src/publish/mod.rs diff --git a/src/emacs/publish.rs b/src/publish/publish.rs similarity index 71% rename from src/emacs/publish.rs rename to src/publish/publish.rs index 568a9cf..4f99271 100644 --- a/src/emacs/publish.rs +++ b/src/publish/publish.rs @@ -1,3 +1,5 @@ +use std::io::Error as IOError; +use std::path::{Path, PathBuf}; pub struct Project { name: String, base_directory: PathBuf, @@ -22,3 +24,14 @@ pub enum Action { Attach, Copy, } + +#[derive(Debug)] +pub enum Error { + ParseError(PathBuf), + InternalError, + IO(IOError), +} + +pub fn build_site(path: impl AsRef) -> Result<(), Error> { + todo!() +} diff --git a/src/watcher/mod.rs b/src/watcher/mod.rs index 3226166..63a3cf0 100644 --- a/src/watcher/mod.rs +++ b/src/watcher/mod.rs @@ -1,9 +1,9 @@ -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use notify::{Event, EventKind, Result}; use tracing::debug; -pub fn watch(event: Event) -> Result<()> { +pub fn watch(event: Event, path: impl AsRef) -> Result<()> { if event .paths .clone() @@ -11,7 +11,8 @@ pub fn watch(event: Event) -> Result<()> { .filter(|e| { if let Some(base_name) = e.file_name() { let name = base_name.to_os_string().into_string().unwrap_or("".into()); - !name.starts_with(".#") + // Let's filter out emacs changes and lockfiles + !(name.starts_with(".#") | name.ends_with("~")) } else { false } @@ -22,6 +23,7 @@ pub fn watch(event: Event) -> Result<()> { { match event.kind { EventKind::Create(_) | EventKind::Modify(_) | EventKind::Remove(_) => { + // rebuild function debug!(?event); for path in event.paths { if !path.exists() {