diff --git a/README.md b/README.md index 3aa098d..42491e4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# rasp +# rsapi This Project contains the following exported libraries: diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100755 index 73d981e..0000000 --- a/src/lib.rs +++ /dev/null @@ -1,58 +0,0 @@ -#![deny(clippy::all)] - -#[macro_use] -extern crate napi_derive; - -use napi::{ - bindgen_prelude::*, - threadsafe_function::{ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode}, -}; - -#[napi(object)] -#[derive(Debug)] -pub struct Options { - pub ignore_patterns: Option>, -} - -#[napi] -pub fn watch(path: String, options: Options, callback: JsFunction) -> Result<()> { - let tsfn: ThreadsafeFunction<(String, Vec)> = callback.create_threadsafe_function( - 0, - |ctx: ThreadSafeCallContext<(String, Vec)>| { - let mut ret = vec![ctx.env.create_string(&*ctx.value.0)?]; - for path in ctx.value.1.iter() { - ret.push(ctx.env.create_string(&*path)?); - } - Ok(ret) - }, - )?; - println!("D: watching {}", path); - println!("D: with opts: {:?}", options); - - watcher::watch( - path, - options.ignore_patterns.iter().flatten().map(|s| s.as_str()), - move |event| { - tsfn.call( - Ok(( - event.kind().to_owned(), - event - .paths() - .into_iter() - .map(|p| p.to_str().unwrap().to_owned()) - .collect(), - )), - ThreadsafeFunctionCallMode::Blocking, - ); - }, - ) - .unwrap(); - - Ok(()) -} - -#[napi] -pub fn close() -> Result<()> { - watcher::close().unwrap(); - Ok(()) -}