forked from SuperCuber/dotter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch.rs
74 lines (65 loc) · 2.03 KB
/
watch.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use anyhow::{Context, Result};
use watchexec::sources::fs::Watcher;
use watchexec::{Config, Watchexec};
use watchexec_filterer_tagged::{Filter, Matcher, Op, Pattern, TaggedFilterer};
use super::display_error;
use crate::args::Options;
use crate::deploy;
pub(crate) async fn watch(opt: Options) -> Result<()> {
let config = Config::default();
config.file_watcher(Watcher::Native);
config.pathset(["."]);
let filter = TaggedFilterer::new(".".into(), std::env::current_dir()?)
.await
.unwrap();
filter
.add_filters(&[
Filter {
in_path: None,
on: Matcher::Path,
op: Op::NotGlob,
pat: Pattern::Glob(format!("{}/", opt.cache_directory.display())),
negate: false,
},
Filter {
in_path: None,
on: Matcher::Path,
op: Op::NotGlob,
pat: Pattern::Glob(opt.cache_file.to_string_lossy().into()),
negate: false,
},
Filter {
in_path: None,
on: Matcher::Path,
op: Op::NotGlob,
pat: Pattern::Glob(".git/".into()),
negate: false,
},
Filter {
in_path: None,
on: Matcher::Path,
op: Op::NotEqual,
pat: Pattern::Exact("DOTTER_SYMLINK_TEST".into()),
negate: false,
},
])
.await?;
config.filterer(filter);
config.on_action(move |mut action| {
if action.signals().next().is_some() {
action.quit();
return action;
}
println!("[Dotter] Deploying...");
if let Err(e) = deploy::deploy(&opt) {
display_error(e);
}
action
});
config.on_error(move |e| {
log::error!("Watcher error: {e:#?}");
});
let we = Watchexec::with_config(config)?;
we.main().await.context("run watchexec main loop")??;
Ok(())
}