diff --git a/packages/cargo-pgml-components/Cargo.lock b/packages/cargo-pgml-components/Cargo.lock index 92f4118dc..afa0f3ea0 100644 --- a/packages/cargo-pgml-components/Cargo.lock +++ b/packages/cargo-pgml-components/Cargo.lock @@ -126,7 +126,7 @@ dependencies = [ [[package]] name = "cargo-pgml-components" -version = "0.1.20" +version = "0.1.21" dependencies = [ "anyhow", "assert_cmd", @@ -138,6 +138,9 @@ dependencies = [ "glob", "log", "md5", + "notify", + "notify-debouncer-full", + "once_cell", "owo-colors", "predicates", "regex", @@ -218,6 +221,25 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" +dependencies = [ + "cfg-if", +] + [[package]] name = "difflib" version = "0.4.0" @@ -282,6 +304,15 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" +[[package]] +name = "file-id" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6584280525fb2059cba3db2c04abf947a1a29a45ddae89f3870f8281704fafc9" +dependencies = [ + "windows-sys", +] + [[package]] name = "file-lock" version = "2.1.10" @@ -300,7 +331,7 @@ checksum = "d4029edd3e734da6fe05b6cd7bd2960760a616bd2ddd0d59a0124746d6272af0" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.3.5", "windows-sys", ] @@ -319,6 +350,15 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "fsevent-sys" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" +dependencies = [ + "libc", +] + [[package]] name = "glob" version = "0.3.1" @@ -409,6 +449,26 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "inotify" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" +dependencies = [ + "bitflags 1.3.2", + "inotify-sys", + "libc", +] + +[[package]] +name = "inotify-sys" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" +dependencies = [ + "libc", +] + [[package]] name = "is-terminal" version = "0.4.9" @@ -441,6 +501,26 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9028f49264629065d057f340a86acb84867925865f73bbf8d47b4d149a7e88b8" +[[package]] +name = "kqueue" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c" +dependencies = [ + "kqueue-sys", + "libc", +] + +[[package]] +name = "kqueue-sys" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b" +dependencies = [ + "bitflags 1.3.2", + "libc", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -449,9 +529,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.147" +version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" [[package]] name = "linux-raw-sys" @@ -459,6 +539,16 @@ version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.20" @@ -477,12 +567,57 @@ version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f478948fd84d9f8e86967bf432640e46adfb5a4bd4f14ef7e864ab38220534ae" +[[package]] +name = "mio" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys", +] + [[package]] name = "normalize-line-endings" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" +[[package]] +name = "notify" +version = "6.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d" +dependencies = [ + "bitflags 2.4.0", + "crossbeam-channel", + "filetime", + "fsevent-sys", + "inotify", + "kqueue", + "libc", + "log", + "mio", + "walkdir", + "windows-sys", +] + +[[package]] +name = "notify-debouncer-full" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f5dab59c348b9b50cf7f261960a20e389feb2713636399cd9082cd4b536154" +dependencies = [ + "crossbeam-channel", + "file-id", + "log", + "notify", + "parking_lot", + "walkdir", +] + [[package]] name = "num-traits" version = "0.2.16" @@ -504,6 +639,29 @@ version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.4.1", + "smallvec", + "windows-targets", +] + [[package]] name = "predicates" version = "3.0.3" @@ -562,6 +720,15 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "regex" version = "1.9.4" @@ -657,6 +824,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "serde" version = "1.0.188" @@ -697,6 +870,12 @@ dependencies = [ "serde", ] +[[package]] +name = "smallvec" +version = "1.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" + [[package]] name = "strsim" version = "0.10.0" @@ -722,7 +901,7 @@ checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ "cfg-if", "fastrand", - "redox_syscall", + "redox_syscall 0.3.5", "rustix", "windows-sys", ] @@ -829,6 +1008,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "winapi" version = "0.3.9" diff --git a/packages/cargo-pgml-components/Cargo.toml b/packages/cargo-pgml-components/Cargo.toml index 55fff6533..d4ba1c61b 100644 --- a/packages/cargo-pgml-components/Cargo.toml +++ b/packages/cargo-pgml-components/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cargo-pgml-components" -version = "0.1.20" +version = "0.1.21" edition = "2021" authors = ["PostgresML "] license = "MIT" @@ -23,6 +23,9 @@ toml = "0.7" serde = { version = "1", features = ["derive"] } file-lock = "2" serde_json = "1" +notify = "6" +notify-debouncer-full = "0.3" +once_cell = "1" [dev-dependencies] assert_cmd = "2" diff --git a/packages/cargo-pgml-components/src/frontend/tools.rs b/packages/cargo-pgml-components/src/frontend/tools.rs index 0017fdb1a..732770e26 100644 --- a/packages/cargo-pgml-components/src/frontend/tools.rs +++ b/packages/cargo-pgml-components/src/frontend/tools.rs @@ -1,10 +1,14 @@ //! Tools required by us to build stuff. -use crate::util::{debug1, error, execute_command, info, unwrap_or_exit, warn}; +use crate::util::{debug1, error, execute_command, info, print, unwrap_or_exit, warn}; use std::fs::File; use std::io::Write; use std::path::Path; use std::process::{exit, Command}; +use std::time::Duration; + +// use notify::{Watcher, RecursiveMode, event::{EventKind, AccessKind}}; +use notify_debouncer_full::{new_debouncer, notify::*, DebounceEventResult}; /// Required tools. static TOOLS: &[&str] = &["sass", "rollup"]; @@ -126,3 +130,58 @@ pub fn debug() { println!("{}: {}", tool, output.trim()); } } + +pub fn watch() { + let mut debouncer = unwrap_or_exit!(new_debouncer( + Duration::from_secs(1), + None, + |result: DebounceEventResult| { + match result { + Ok(events) => { + let mut detected = true; + for event in &events { + for path in &event.event.paths { + let path = path.display().to_string(); + if path.ends_with("modules.scss") + || path.contains("style.") + || path.ends_with(".pgml-bundle") + || path.ends_with("modules.js") + || path.contains("bundle.") + { + detected = false; + } + } + } + + if detected { + print("changes detected, rebuilding..."); + rebuild(); + info("done"); + } + } + + Err(e) => { + debug!("debouncer error: {:?}", e); + } + } + } + )); + + unwrap_or_exit!(debouncer + .watcher() + .watch(Path::new("src"), RecursiveMode::Recursive)); + unwrap_or_exit!(debouncer + .watcher() + .watch(Path::new("static"), RecursiveMode::Recursive)); + + info("watching for changes"); + + // sleep forever + std::thread::sleep(std::time::Duration::MAX); +} + +fn rebuild() { + unwrap_or_exit!(execute_command( + Command::new("cargo").arg("pgml-components").arg("bundle") + )); +} diff --git a/packages/cargo-pgml-components/src/main.rs b/packages/cargo-pgml-components/src/main.rs index 0e978fc45..4c7c33aea 100644 --- a/packages/cargo-pgml-components/src/main.rs +++ b/packages/cargo-pgml-components/src/main.rs @@ -75,6 +75,9 @@ enum Commands { /// Setup local dev. #[command(subcommand)] LocalDev(LocalDevCommands), + + /// Watch for local changes, + Watch, } #[derive(Subcommand, Debug)] @@ -113,6 +116,9 @@ fn main() { LocalDevCommands::Check {} => local_dev::setup(), LocalDevCommands::InstallPgvector {} => local_dev::install_pgvector(), }, + Commands::Watch => { + frontend::tools::watch(); + } } } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy