Skip to content

Commit 55f96b3

Browse files
authored
Fix some autoreloading bugs (#972)
1 parent eb9b5b1 commit 55f96b3

File tree

6 files changed

+37
-7
lines changed

6 files changed

+37
-7
lines changed

pgml-apps/cargo-pgml-components/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pgml-apps/cargo-pgml-components/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-pgml-components"
3-
version = "0.1.9"
3+
version = "0.1.10"
44
edition = "2021"
55
authors = ["PostgresML <team@postgresml.org>"]
66
license = "MIT"

pgml-apps/cargo-pgml-components/src/frontend/components.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use convert_case::{Case, Casing};
22
use sailfish::TemplateOnce;
3-
use std::fs::{create_dir_all, read_dir};
3+
use std::fs::{create_dir_all, read_dir, read_to_string};
44
use std::path::Path;
55
use std::process::exit;
66

77
use crate::frontend::templates;
8-
use crate::util::{error, info, unwrap_or_exit, write_to_file};
8+
use crate::util::{compare_strings, error, info, unwrap_or_exit, write_to_file};
99

1010
static COMPONENT_DIRECTORY: &'static str = "src/components";
1111
static COMPONENT_MOD: &'static str = "src/components/mod.rs";
@@ -131,7 +131,13 @@ pub fn update_modules() {
131131
}
132132

133133
let modules = unwrap_or_exit!(templates::Mod { modules }.render_once());
134+
let existing_modules = unwrap_or_exit!(read_to_string(COMPONENT_MOD));
134135

135-
unwrap_or_exit!(write_to_file(&Path::new(COMPONENT_MOD), &modules));
136-
info(&format!("written {}", COMPONENT_MOD));
136+
if !unwrap_or_exit!(compare_strings(&modules, &existing_modules)) {
137+
debug!("mod.rs is different");
138+
unwrap_or_exit!(write_to_file(&Path::new(COMPONENT_MOD), &modules));
139+
info(&format!("written {}", COMPONENT_MOD));
140+
}
141+
142+
debug!("mod.rs is the same");
137143
}

pgml-apps/cargo-pgml-components/src/util.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use owo_colors::OwoColorize;
2-
use std::fs::File;
2+
use std::fs::{read_to_string, File};
33
use std::io::{ErrorKind, Write};
44
use std::path::Path;
55
use std::process::Command;
@@ -78,3 +78,16 @@ pub fn write_to_file(path: &Path, content: &str) -> std::io::Result<()> {
7878

7979
Ok(())
8080
}
81+
82+
#[allow(dead_code)]
83+
pub fn compare_files(path1: &Path, path2: &Path) -> std::io::Result<bool> {
84+
let content1 = read_to_string(path1)?;
85+
let content2 = read_to_string(path2)?;
86+
87+
compare_strings(&content1, &content2)
88+
}
89+
90+
pub fn compare_strings(string1: &str, string2: &str) -> std::io::Result<bool> {
91+
// TODO: faster string comparison method needed.
92+
Ok(string1 == string2)
93+
}

pgml-dashboard/static/js/.ignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
main.js
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1+
<% use crate::components::*; %>
2+
13
<h3 class="h3">Playground</h3>
4+
5+
<div class="mb-3">
6+
<%+ GithubIcon::new() %>
7+
</div>
8+
9+
<div class="mb-3">
10+
<%- Navbar::render(None) %>
11+
</div>

0 commit comments

Comments
 (0)
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