Skip to content

Commit 61e40cf

Browse files
committed
ok
1 parent 2e6896d commit 61e40cf

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ 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";
@@ -133,7 +133,7 @@ pub fn update_modules() {
133133
let modules = unwrap_or_exit!(templates::Mod { modules }.render_once());
134134
let existing_modules = unwrap_or_exit!(read_to_string(COMPONENT_MOD));
135135

136-
if modules != existing_modules {
136+
if !unwrap_or_exit!(compare_strings(&modules, &existing_modules)) {
137137
debug!("mod.rs is different");
138138
unwrap_or_exit!(write_to_file(&Path::new(COMPONENT_MOD), &modules));
139139
info(&format!("written {}", COMPONENT_MOD));

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use crate::util::{info, unwrap_or_exit, warn};
1313
/// The name of the JS file that imports all other JS files
1414
/// created in the modules.
1515
static MODULES_FILE: &'static str = "static/js/modules.js";
16-
static MODULES_FILE_TMP: &'static str = "/tmp/pgml-components-modules.js";
1716

1817
/// The JS bundle.
1918
static JS_FILE: &'static str = "static/js/bundle.js";
@@ -53,7 +52,7 @@ fn assemble_modules() {
5352
!path.contains("main.js") && !path.contains("bundle.js") && !path.contains("modules.js")
5453
});
5554

56-
let mut modules = unwrap_or_exit!(File::create(MODULES_FILE_TMP));
55+
let mut modules = unwrap_or_exit!(File::create(MODULES_FILE));
5756

5857
unwrap_or_exit!(writeln!(&mut modules, "// Build with --bin components"));
5958
unwrap_or_exit!(writeln!(
@@ -93,13 +92,7 @@ fn assemble_modules() {
9392
));
9493
}
9594

96-
let new_modules = unwrap_or_exit!(read_to_string(MODULES_FILE_TMP));
97-
let old_modules = unwrap_or_exit!(read_to_string(MODULES_FILE));
98-
99-
if new_modules != old_modules {
100-
unwrap_or_exit!(copy(MODULES_FILE_TMP, MODULES_FILE));
101-
info(&format!("written {}", MODULES_FILE));
102-
}
95+
info(&format!("written {}", MODULES_FILE));
10396
}
10497

10598
pub fn bundle() {

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+
}

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