forked from lavender-legacy/lavender.software
66 lines
1.4 KiB
Rust
66 lines
1.4 KiB
Rust
use siru::prelude::*;
|
|
use std::{convert::TryInto, path::PathBuf, sync::Arc, time::Duration};
|
|
|
|
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
|
|
|
mod assets;
|
|
mod main_page;
|
|
|
|
pub struct BuildContext {
|
|
source_dir: PathBuf,
|
|
output_dir: PathBuf,
|
|
write_pipeline: WritePipeline,
|
|
}
|
|
|
|
impl SiruFS for BuildContext {
|
|
fn get_source_dir(&self) -> &PathBuf {
|
|
&self.source_dir
|
|
}
|
|
|
|
fn get_output_dir(&self) -> &PathBuf {
|
|
&self.output_dir
|
|
}
|
|
|
|
fn get_write_pipeline(&self) -> &WritePipeline {
|
|
&self.write_pipeline
|
|
}
|
|
}
|
|
|
|
fn build() {
|
|
let ctx = BuildContext {
|
|
source_dir: "src".try_into().unwrap(),
|
|
output_dir: "dist".try_into().unwrap(),
|
|
write_pipeline: WritePipeline::new(),
|
|
};
|
|
|
|
let ctx = Arc::new(ctx);
|
|
|
|
[main_page::main_page, assets::copy_assets]
|
|
.iter()
|
|
.map(|f| {
|
|
let ctx = Arc::clone(&ctx);
|
|
std::thread::spawn(move || f(&ctx).unwrap())
|
|
})
|
|
.for_each(|t| t.join().unwrap());
|
|
}
|
|
|
|
fn main() {
|
|
println!("Watching...\n");
|
|
|
|
use notify::*;
|
|
|
|
let (tx, rx) = std::sync::mpsc::channel();
|
|
|
|
let mut watcher = watcher(tx, Duration::from_millis(100)).unwrap();
|
|
build();
|
|
|
|
watcher.watch("./src", RecursiveMode::Recursive).unwrap();
|
|
|
|
loop {
|
|
match rx.recv() {
|
|
Ok(_) => build(),
|
|
Err(_) => break,
|
|
}
|
|
}
|
|
}
|