Skip to content

Fix some autoreloading bugs #972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pgml-apps/cargo-pgml-components/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pgml-apps/cargo-pgml-components/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-pgml-components"
version = "0.1.9"
version = "0.1.10"
edition = "2021"
authors = ["PostgresML <team@postgresml.org>"]
license = "MIT"
Expand Down
14 changes: 10 additions & 4 deletions pgml-apps/cargo-pgml-components/src/frontend/components.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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;

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";
Expand Down Expand Up @@ -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 !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));
}

debug!("mod.rs is the same");
}
15 changes: 14 additions & 1 deletion pgml-apps/cargo-pgml-components/src/util.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<bool> {
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<bool> {
// TODO: faster string comparison method needed.
Ok(string1 == string2)
}
1 change: 1 addition & 0 deletions pgml-dashboard/static/js/.ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main.js
10 changes: 10 additions & 0 deletions pgml-dashboard/templates/content/playground.html
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
<% use crate::components::*; %>

<h3 class="h3">Playground</h3>

<div class="mb-3">
<%+ GithubIcon::new() %>
</div>

<div class="mb-3">
<%- Navbar::render(None) %>
</div>