Works but needs modifications
This commit is contained in:
parent
68f1b9e217
commit
52ef41b9aa
30
src/lib.rs
30
src/lib.rs
|
@ -2,13 +2,16 @@
|
|||
extern crate log;
|
||||
|
||||
use std::{io, thread};
|
||||
use std::env::current_dir;
|
||||
use std::process::{Command, ExitStatus};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::fs::{File, create_dir_all};
|
||||
use std::sync::mpsc::channel;
|
||||
use std::time::Duration;
|
||||
|
||||
use notify::{Watcher, RecursiveMode, DebouncedEvent, watcher};
|
||||
use colored::*;
|
||||
|
||||
use notify::{Watcher, RecursiveMode, watcher};
|
||||
|
||||
use notify_rust::Notification;
|
||||
|
||||
|
@ -109,20 +112,35 @@ pub fn builder_arguments_from_string(uri: &str) -> (PathBuf, Vec<String>) {
|
|||
|
||||
/// Watches a directory and builds it when a modification occurs.
|
||||
pub fn watch<P: AsRef<Path>>(p: P) -> Result<(), Error> {
|
||||
let path = PathBuf::from(p.as_ref());
|
||||
let mut path = current_dir()?;
|
||||
path.push(p.as_ref());
|
||||
|
||||
thread::spawn(move || {
|
||||
let (tx, rx) = channel();
|
||||
let mut watcher = watcher(tx, Duration::from_secs(10)).unwrap();
|
||||
let mut watcher = watcher(tx, Duration::from_millis(200)).unwrap();
|
||||
watcher.watch(&path, RecursiveMode::Recursive).unwrap();
|
||||
|
||||
info!("watching {}", path.display());
|
||||
|
||||
loop {
|
||||
match rx.recv() {
|
||||
Ok(DebouncedEvent::NoticeWrite(_)) => {
|
||||
Ok(_) => {
|
||||
let builder = GeneralBuilder::new();
|
||||
builder.build(&path, &vec![]).ok();
|
||||
|
||||
let start_string = format!("---- STARTING BUILD ---- from {}", path.display());
|
||||
println!("{}", start_string.bold().green());
|
||||
|
||||
match builder.build(&path, &vec![]) {
|
||||
Err(_) => {
|
||||
println!("{}", "--------- FAIL ---------".bold().red());
|
||||
},
|
||||
Ok(_) => {
|
||||
println!("{}", "----- SUCCESSFUL -----".bold().green());
|
||||
},
|
||||
};
|
||||
println!();
|
||||
},
|
||||
Err(e) => error!("watch error: {:?}", e),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue