From 60d98d09a98d6371d99aa47dc2f35dae63b6189d Mon Sep 17 00:00:00 2001 From: Lev Kokotov Date: Thu, 31 Aug 2023 16:08:01 -0700 Subject: [PATCH 1/4] Ignore some --- pgml-dashboard/src/components/.ignore | 1 + pgml-dashboard/static/js/.ignore | 1 + pgml-dashboard/templates/content/playground.html | 10 ++++++++++ 3 files changed, 12 insertions(+) create mode 100644 pgml-dashboard/src/components/.ignore create mode 100644 pgml-dashboard/static/js/.ignore diff --git a/pgml-dashboard/src/components/.ignore b/pgml-dashboard/src/components/.ignore new file mode 100644 index 000000000..73abffdd5 --- /dev/null +++ b/pgml-dashboard/src/components/.ignore @@ -0,0 +1 @@ +mod.rs diff --git a/pgml-dashboard/static/js/.ignore b/pgml-dashboard/static/js/.ignore new file mode 100644 index 000000000..a9b203a6e --- /dev/null +++ b/pgml-dashboard/static/js/.ignore @@ -0,0 +1 @@ +main.js diff --git a/pgml-dashboard/templates/content/playground.html b/pgml-dashboard/templates/content/playground.html index 792f7621d..1d03bb214 100644 --- a/pgml-dashboard/templates/content/playground.html +++ b/pgml-dashboard/templates/content/playground.html @@ -1 +1,11 @@ +<% use crate::components::*; %> +

Playground

+ +
+ <%+ GithubIcon::new() %> +
+ +
+ <%- Navbar::render(None) %> +
From 2e6896d9752779c349dd864e4e27de0529b9a0c6 Mon Sep 17 00:00:00 2001 From: Lev Kokotov Date: Thu, 31 Aug 2023 16:23:36 -0700 Subject: [PATCH 2/4] Start fixing autoreload bug --- pgml-apps/cargo-pgml-components/Cargo.lock | 2 +- .../cargo-pgml-components/src/frontend/components.rs | 12 +++++++++--- .../cargo-pgml-components/src/frontend/javascript.rs | 11 +++++++++-- pgml-dashboard/src/components/.ignore | 1 - 4 files changed, 19 insertions(+), 7 deletions(-) delete mode 100644 pgml-dashboard/src/components/.ignore diff --git a/pgml-apps/cargo-pgml-components/Cargo.lock b/pgml-apps/cargo-pgml-components/Cargo.lock index c02281263..ecc6af6f1 100644 --- a/pgml-apps/cargo-pgml-components/Cargo.lock +++ b/pgml-apps/cargo-pgml-components/Cargo.lock @@ -79,7 +79,7 @@ checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" [[package]] name = "cargo-pgml-components" -version = "0.1.8" +version = "0.1.9" dependencies = [ "anyhow", "clap", diff --git a/pgml-apps/cargo-pgml-components/src/frontend/components.rs b/pgml-apps/cargo-pgml-components/src/frontend/components.rs index d1833b281..5d13e445b 100644 --- a/pgml-apps/cargo-pgml-components/src/frontend/components.rs +++ b/pgml-apps/cargo-pgml-components/src/frontend/components.rs @@ -1,6 +1,6 @@ use convert_case::{Case, Casing}; use sailfish::TemplateOnce; -use std::fs::{create_dir_all, read_dir}; +use std::fs::{create_dir_all, read_dir, read_to_string}; use std::path::Path; use std::process::exit; @@ -131,7 +131,13 @@ pub fn update_modules() { } let modules = unwrap_or_exit!(templates::Mod { modules }.render_once()); + let existing_modules = unwrap_or_exit!(read_to_string(COMPONENT_MOD)); - unwrap_or_exit!(write_to_file(&Path::new(COMPONENT_MOD), &modules)); - info(&format!("written {}", COMPONENT_MOD)); + if modules != existing_modules { + debug!("mod.rs is different"); + unwrap_or_exit!(write_to_file(&Path::new(COMPONENT_MOD), &modules)); + info(&format!("written {}", COMPONENT_MOD)); + } + + debug!("mod.rs is the same"); } diff --git a/pgml-apps/cargo-pgml-components/src/frontend/javascript.rs b/pgml-apps/cargo-pgml-components/src/frontend/javascript.rs index 0c9bde514..609828ab2 100644 --- a/pgml-apps/cargo-pgml-components/src/frontend/javascript.rs +++ b/pgml-apps/cargo-pgml-components/src/frontend/javascript.rs @@ -13,6 +13,7 @@ use crate::util::{info, unwrap_or_exit, warn}; /// The name of the JS file that imports all other JS files /// created in the modules. static MODULES_FILE: &'static str = "static/js/modules.js"; +static MODULES_FILE_TMP: &'static str = "/tmp/pgml-components-modules.js"; /// The JS bundle. static JS_FILE: &'static str = "static/js/bundle.js"; @@ -52,7 +53,7 @@ fn assemble_modules() { !path.contains("main.js") && !path.contains("bundle.js") && !path.contains("modules.js") }); - let mut modules = unwrap_or_exit!(File::create(MODULES_FILE)); + let mut modules = unwrap_or_exit!(File::create(MODULES_FILE_TMP)); unwrap_or_exit!(writeln!(&mut modules, "// Build with --bin components")); unwrap_or_exit!(writeln!( @@ -92,7 +93,13 @@ fn assemble_modules() { )); } - info(&format!("written {}", MODULES_FILE)); + let new_modules = unwrap_or_exit!(read_to_string(MODULES_FILE_TMP)); + let old_modules = unwrap_or_exit!(read_to_string(MODULES_FILE)); + + if new_modules != old_modules { + unwrap_or_exit!(copy(MODULES_FILE_TMP, MODULES_FILE)); + info(&format!("written {}", MODULES_FILE)); + } } pub fn bundle() { diff --git a/pgml-dashboard/src/components/.ignore b/pgml-dashboard/src/components/.ignore deleted file mode 100644 index 73abffdd5..000000000 --- a/pgml-dashboard/src/components/.ignore +++ /dev/null @@ -1 +0,0 @@ -mod.rs From 61e40cf0263623640661abe98e69eafcf76c04f4 Mon Sep 17 00:00:00 2001 From: Lev Kokotov Date: Thu, 31 Aug 2023 17:28:24 -0700 Subject: [PATCH 3/4] ok --- .../src/frontend/components.rs | 4 ++-- .../src/frontend/javascript.rs | 11 ++--------- pgml-apps/cargo-pgml-components/src/util.rs | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/pgml-apps/cargo-pgml-components/src/frontend/components.rs b/pgml-apps/cargo-pgml-components/src/frontend/components.rs index 5d13e445b..2dbb0a705 100644 --- a/pgml-apps/cargo-pgml-components/src/frontend/components.rs +++ b/pgml-apps/cargo-pgml-components/src/frontend/components.rs @@ -5,7 +5,7 @@ use std::path::Path; use std::process::exit; use crate::frontend::templates; -use crate::util::{error, info, unwrap_or_exit, write_to_file}; +use crate::util::{compare_strings, error, info, unwrap_or_exit, write_to_file}; static COMPONENT_DIRECTORY: &'static str = "src/components"; static COMPONENT_MOD: &'static str = "src/components/mod.rs"; @@ -133,7 +133,7 @@ pub fn update_modules() { let modules = unwrap_or_exit!(templates::Mod { modules }.render_once()); let existing_modules = unwrap_or_exit!(read_to_string(COMPONENT_MOD)); - if modules != existing_modules { + if !unwrap_or_exit!(compare_strings(&modules, &existing_modules)) { debug!("mod.rs is different"); unwrap_or_exit!(write_to_file(&Path::new(COMPONENT_MOD), &modules)); info(&format!("written {}", COMPONENT_MOD)); diff --git a/pgml-apps/cargo-pgml-components/src/frontend/javascript.rs b/pgml-apps/cargo-pgml-components/src/frontend/javascript.rs index 609828ab2..0c9bde514 100644 --- a/pgml-apps/cargo-pgml-components/src/frontend/javascript.rs +++ b/pgml-apps/cargo-pgml-components/src/frontend/javascript.rs @@ -13,7 +13,6 @@ use crate::util::{info, unwrap_or_exit, warn}; /// The name of the JS file that imports all other JS files /// created in the modules. static MODULES_FILE: &'static str = "static/js/modules.js"; -static MODULES_FILE_TMP: &'static str = "/tmp/pgml-components-modules.js"; /// The JS bundle. static JS_FILE: &'static str = "static/js/bundle.js"; @@ -53,7 +52,7 @@ fn assemble_modules() { !path.contains("main.js") && !path.contains("bundle.js") && !path.contains("modules.js") }); - let mut modules = unwrap_or_exit!(File::create(MODULES_FILE_TMP)); + let mut modules = unwrap_or_exit!(File::create(MODULES_FILE)); unwrap_or_exit!(writeln!(&mut modules, "// Build with --bin components")); unwrap_or_exit!(writeln!( @@ -93,13 +92,7 @@ fn assemble_modules() { )); } - let new_modules = unwrap_or_exit!(read_to_string(MODULES_FILE_TMP)); - let old_modules = unwrap_or_exit!(read_to_string(MODULES_FILE)); - - if new_modules != old_modules { - unwrap_or_exit!(copy(MODULES_FILE_TMP, MODULES_FILE)); - info(&format!("written {}", MODULES_FILE)); - } + info(&format!("written {}", MODULES_FILE)); } pub fn bundle() { diff --git a/pgml-apps/cargo-pgml-components/src/util.rs b/pgml-apps/cargo-pgml-components/src/util.rs index ec3d4aa3d..d500aa78d 100644 --- a/pgml-apps/cargo-pgml-components/src/util.rs +++ b/pgml-apps/cargo-pgml-components/src/util.rs @@ -1,5 +1,5 @@ use owo_colors::OwoColorize; -use std::fs::File; +use std::fs::{read_to_string, File}; use std::io::{ErrorKind, Write}; use std::path::Path; use std::process::Command; @@ -78,3 +78,16 @@ pub fn write_to_file(path: &Path, content: &str) -> std::io::Result<()> { Ok(()) } + +#[allow(dead_code)] +pub fn compare_files(path1: &Path, path2: &Path) -> std::io::Result { + let content1 = read_to_string(path1)?; + let content2 = read_to_string(path2)?; + + compare_strings(&content1, &content2) +} + +pub fn compare_strings(string1: &str, string2: &str) -> std::io::Result { + // TODO: faster string comparison method needed. + Ok(string1 == string2) +} From b10bc5f968a11cf3e6f123928bf1684e95317ebc Mon Sep 17 00:00:00 2001 From: Lev Kokotov Date: Thu, 31 Aug 2023 17:28:51 -0700 Subject: [PATCH 4/4] v bump --- pgml-apps/cargo-pgml-components/Cargo.lock | 2 +- pgml-apps/cargo-pgml-components/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pgml-apps/cargo-pgml-components/Cargo.lock b/pgml-apps/cargo-pgml-components/Cargo.lock index ecc6af6f1..518bdd2e6 100644 --- a/pgml-apps/cargo-pgml-components/Cargo.lock +++ b/pgml-apps/cargo-pgml-components/Cargo.lock @@ -79,7 +79,7 @@ checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" [[package]] name = "cargo-pgml-components" -version = "0.1.9" +version = "0.1.10" dependencies = [ "anyhow", "clap", diff --git a/pgml-apps/cargo-pgml-components/Cargo.toml b/pgml-apps/cargo-pgml-components/Cargo.toml index be13f563c..2b6bd6c32 100644 --- a/pgml-apps/cargo-pgml-components/Cargo.toml +++ b/pgml-apps/cargo-pgml-components/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cargo-pgml-components" -version = "0.1.9" +version = "0.1.10" edition = "2021" authors = ["PostgresML "] license = "MIT" 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