Merge pull request #58 from trevyn/fix-notify
Fix `notify` and make CI pass
This commit is contained in:
5 files changed
+332
-375
No files matched your search
Generated
+202
-249
File diff suppressed because it is too large.
Load diff
+1
-1
@@ -25,7 +25,7 @@ toml = "0.5.8"
|
|||||||
fs_extra = "1.2.0"
|
fs_extra = "1.2.0"
|
||||||
cargo_toml = "0.11.4"
|
cargo_toml = "0.11.4"
|
||||||
futures = "0.3.21"
|
futures = "0.3.21"
|
||||||
notify = { version = "5.0.0-pre.13", features = ["serde"] }
|
notify = { version = "5.0.0-pre.16", features = ["serde"] }
|
||||||
html_parser = "0.6.2"
|
html_parser = "0.6.2"
|
||||||
binary-install = "0.0.2"
|
binary-install = "0.0.2"
|
||||||
convert_case = "0.5.0"
|
convert_case = "0.5.0"
|
||||||
|
|||||||
+11
-8
@@ -152,10 +152,7 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
|
|||||||
if config.release == true {
|
if config.release == true {
|
||||||
args.push("-Oz");
|
args.push("-Oz");
|
||||||
}
|
}
|
||||||
binaryen.call(
|
binaryen.call("wasm-opt", args)?;
|
||||||
"wasm-opt",
|
|
||||||
args,
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,11 +174,11 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
|
|||||||
|
|
||||||
let input_path = match sub.get("input") {
|
let input_path = match sub.get("input") {
|
||||||
Some(val) => val.as_str().unwrap(),
|
Some(val) => val.as_str().unwrap(),
|
||||||
None => "./public"
|
None => "./public",
|
||||||
};
|
};
|
||||||
let config_path = match sub.get("config") {
|
let config_path = match sub.get("config") {
|
||||||
Some(val) => val.as_str().unwrap(),
|
Some(val) => val.as_str().unwrap(),
|
||||||
None => "./src/tailwind.config.js"
|
None => "./src/tailwind.config.js",
|
||||||
};
|
};
|
||||||
let mut args = vec![
|
let mut args = vec![
|
||||||
"-i",
|
"-i",
|
||||||
@@ -189,7 +186,7 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
|
|||||||
"-o",
|
"-o",
|
||||||
"dist/tailwind.css",
|
"dist/tailwind.css",
|
||||||
"-c",
|
"-c",
|
||||||
config_path
|
config_path,
|
||||||
];
|
];
|
||||||
|
|
||||||
if config.release == true {
|
if config.release == true {
|
||||||
@@ -459,7 +456,13 @@ pub fn gen_page(config: &DioxusConfig, serve: bool) -> String {
|
|||||||
&style.to_str().unwrap(),
|
&style.to_str().unwrap(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
if config.application.tools.clone().unwrap_or_default().contains_key("tailwindcss") {
|
if config
|
||||||
|
.application
|
||||||
|
.tools
|
||||||
|
.clone()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.contains_key("tailwindcss")
|
||||||
|
{
|
||||||
style_str.push_str("<link rel=\"stylesheet\" href=\"tailwind.css\">\n");
|
style_str.push_str("<link rel=\"stylesheet\" href=\"tailwind.css\">\n");
|
||||||
}
|
}
|
||||||
html = html.replace("{style_include}", &style_str);
|
html = html.replace("{style_include}", &style_str);
|
||||||
|
|||||||
+108
-101
@@ -98,100 +98,104 @@ pub async fn startup_hot_reload(port: u16, config: CrateConfig) -> Result<()> {
|
|||||||
.unwrap_or_else(|| vec![PathBuf::from("src")]);
|
.unwrap_or_else(|| vec![PathBuf::from("src")]);
|
||||||
|
|
||||||
let watcher_config = config.clone();
|
let watcher_config = config.clone();
|
||||||
let mut watcher = RecommendedWatcher::new(move |evt: notify::Result<notify::Event>| {
|
let mut watcher = RecommendedWatcher::new(
|
||||||
let config = watcher_config.clone();
|
move |evt: notify::Result<notify::Event>| {
|
||||||
if chrono::Local::now().timestamp() > last_update_time {
|
let config = watcher_config.clone();
|
||||||
// Give time for the change to take effect before reading the file
|
if chrono::Local::now().timestamp() > last_update_time {
|
||||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
// Give time for the change to take effect before reading the file
|
||||||
if let Ok(evt) = evt {
|
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||||
let mut messages = Vec::new();
|
if let Ok(evt) = evt {
|
||||||
let mut needs_rebuild = false;
|
let mut messages = Vec::new();
|
||||||
for path in evt.paths.clone() {
|
let mut needs_rebuild = false;
|
||||||
let mut file = File::open(path.clone()).unwrap();
|
for path in evt.paths.clone() {
|
||||||
if path.extension().map(|p| p.to_str()).flatten() != Some("rs") {
|
let mut file = File::open(path.clone()).unwrap();
|
||||||
continue;
|
if path.extension().map(|p| p.to_str()).flatten() != Some("rs") {
|
||||||
}
|
continue;
|
||||||
let mut src = String::new();
|
}
|
||||||
file.read_to_string(&mut src).expect("Unable to read file");
|
let mut src = String::new();
|
||||||
// find changes to the rsx in the file
|
file.read_to_string(&mut src).expect("Unable to read file");
|
||||||
if let Ok(syntax) = syn::parse_file(&src) {
|
// find changes to the rsx in the file
|
||||||
let mut last_file_rebuild = last_file_rebuild.lock().unwrap();
|
if let Ok(syntax) = syn::parse_file(&src) {
|
||||||
if let Some(old_str) = last_file_rebuild.map.get(&path) {
|
let mut last_file_rebuild = last_file_rebuild.lock().unwrap();
|
||||||
if let Ok(old) = syn::parse_file(&old_str) {
|
if let Some(old_str) = last_file_rebuild.map.get(&path) {
|
||||||
match find_rsx(&syntax, &old) {
|
if let Ok(old) = syn::parse_file(&old_str) {
|
||||||
DiffResult::CodeChanged => {
|
match find_rsx(&syntax, &old) {
|
||||||
needs_rebuild = true;
|
DiffResult::CodeChanged => {
|
||||||
last_file_rebuild.map.insert(path, src);
|
needs_rebuild = true;
|
||||||
}
|
last_file_rebuild.map.insert(path, src);
|
||||||
DiffResult::RsxChanged(changed) => {
|
}
|
||||||
log::info!("🪁 reloading rsx");
|
DiffResult::RsxChanged(changed) => {
|
||||||
for (old, new) in changed.into_iter() {
|
log::info!("🪁 reloading rsx");
|
||||||
let hr = get_location(
|
for (old, new) in changed.into_iter() {
|
||||||
&crate_dir,
|
let hr = get_location(
|
||||||
&path.to_path_buf(),
|
&crate_dir,
|
||||||
old.to_token_stream(),
|
&path.to_path_buf(),
|
||||||
);
|
old.to_token_stream(),
|
||||||
// get the original source code to preserve whitespace
|
);
|
||||||
let span = new.span();
|
// get the original source code to preserve whitespace
|
||||||
let start = span.start();
|
let span = new.span();
|
||||||
let end = span.end();
|
let start = span.start();
|
||||||
let mut lines: Vec<_> = src
|
let end = span.end();
|
||||||
.lines()
|
let mut lines: Vec<_> = src
|
||||||
.skip(start.line - 1)
|
.lines()
|
||||||
.take(end.line - start.line + 1)
|
.skip(start.line - 1)
|
||||||
.collect();
|
.take(end.line - start.line + 1)
|
||||||
if let Some(first) = lines.first_mut() {
|
.collect();
|
||||||
*first = first.split_at(start.column).1;
|
if let Some(first) = lines.first_mut() {
|
||||||
}
|
*first = first.split_at(start.column).1;
|
||||||
if let Some(last) = lines.last_mut() {
|
|
||||||
// if there is only one line the start index of last line will be the start of the rsx!, not the start of the line
|
|
||||||
if start.line == end.line {
|
|
||||||
*last =
|
|
||||||
last.split_at(end.column - start.column).0;
|
|
||||||
} else {
|
|
||||||
*last = last.split_at(end.column).0;
|
|
||||||
}
|
}
|
||||||
|
if let Some(last) = lines.last_mut() {
|
||||||
|
// if there is only one line the start index of last line will be the start of the rsx!, not the start of the line
|
||||||
|
if start.line == end.line {
|
||||||
|
*last = last
|
||||||
|
.split_at(end.column - start.column)
|
||||||
|
.0;
|
||||||
|
} else {
|
||||||
|
*last = last.split_at(end.column).0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let rsx = lines.join("\n");
|
||||||
|
messages.push(SetRsxMessage {
|
||||||
|
location: hr,
|
||||||
|
new_text: rsx,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
let rsx = lines.join("\n");
|
|
||||||
messages.push(SetRsxMessage {
|
|
||||||
location: hr,
|
|
||||||
new_text: rsx,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// if this is a new file, rebuild the project
|
||||||
|
*last_file_rebuild = FileMap::new(crate_dir.clone());
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// if this is a new file, rebuild the project
|
|
||||||
*last_file_rebuild = FileMap::new(crate_dir.clone());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if needs_rebuild {
|
||||||
if needs_rebuild {
|
match build_manager.rebuild() {
|
||||||
match build_manager.rebuild() {
|
Ok(res) => {
|
||||||
Ok(res) => {
|
print_console_info(
|
||||||
print_console_info(
|
port,
|
||||||
port,
|
&config,
|
||||||
&config,
|
PrettierOptions {
|
||||||
PrettierOptions {
|
changed: evt.paths,
|
||||||
changed: evt.paths,
|
warnings: res.warnings,
|
||||||
warnings: res.warnings,
|
elapsed_time: res.elapsed_time,
|
||||||
elapsed_time: res.elapsed_time,
|
},
|
||||||
},
|
);
|
||||||
);
|
}
|
||||||
}
|
Err(err) => {
|
||||||
Err(err) => {
|
log::error!("{}", err);
|
||||||
log::error!("{}", err);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !messages.is_empty() {
|
||||||
|
let _ = hot_reload_tx.send(SetManyRsxMessage(messages));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !messages.is_empty() {
|
last_update_time = chrono::Local::now().timestamp();
|
||||||
let _ = hot_reload_tx.send(SetManyRsxMessage(messages));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
last_update_time = chrono::Local::now().timestamp();
|
},
|
||||||
}
|
notify::Config::default(),
|
||||||
})
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
for sub_path in allow_watch_path {
|
for sub_path in allow_watch_path {
|
||||||
@@ -304,28 +308,31 @@ pub async fn startup_default(port: u16, config: CrateConfig) -> Result<()> {
|
|||||||
.unwrap_or_else(|| vec![PathBuf::from("src")]);
|
.unwrap_or_else(|| vec![PathBuf::from("src")]);
|
||||||
|
|
||||||
let watcher_config = config.clone();
|
let watcher_config = config.clone();
|
||||||
let mut watcher = RecommendedWatcher::new(move |info: notify::Result<notify::Event>| {
|
let mut watcher = RecommendedWatcher::new(
|
||||||
let config = watcher_config.clone();
|
move |info: notify::Result<notify::Event>| {
|
||||||
if info.is_ok() {
|
let config = watcher_config.clone();
|
||||||
if chrono::Local::now().timestamp() > last_update_time {
|
if info.is_ok() {
|
||||||
match build_manager.rebuild() {
|
if chrono::Local::now().timestamp() > last_update_time {
|
||||||
Ok(res) => {
|
match build_manager.rebuild() {
|
||||||
last_update_time = chrono::Local::now().timestamp();
|
Ok(res) => {
|
||||||
print_console_info(
|
last_update_time = chrono::Local::now().timestamp();
|
||||||
port,
|
print_console_info(
|
||||||
&config,
|
port,
|
||||||
PrettierOptions {
|
&config,
|
||||||
changed: info.unwrap().paths,
|
PrettierOptions {
|
||||||
warnings: res.warnings,
|
changed: info.unwrap().paths,
|
||||||
elapsed_time: res.elapsed_time,
|
warnings: res.warnings,
|
||||||
},
|
elapsed_time: res.elapsed_time,
|
||||||
);
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(e) => log::error!("{}", e),
|
||||||
}
|
}
|
||||||
Err(e) => log::error!("{}", e),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
})
|
notify::Config::default(),
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
for sub_path in allow_watch_path {
|
for sub_path in allow_watch_path {
|
||||||
|
|||||||
+10
-16
@@ -1,8 +1,8 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fs::{create_dir_all, File},
|
fs::{create_dir_all, File},
|
||||||
|
io::{Read, Write},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::Command,
|
process::Command,
|
||||||
io::{Read, Write}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
@@ -121,15 +121,9 @@ impl Tool {
|
|||||||
/// get tool version
|
/// get tool version
|
||||||
pub fn tool_version(&self) -> &str {
|
pub fn tool_version(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
Self::Binaryen => {
|
Self::Binaryen => "version_105",
|
||||||
"version_105"
|
Self::Sass => "1.51.0",
|
||||||
}
|
Self::Tailwind => "v3.1.6",
|
||||||
Self::Sass => {
|
|
||||||
"1.51.0"
|
|
||||||
}
|
|
||||||
Self::Tailwind => {
|
|
||||||
"v3.1.6"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,7 +148,7 @@ impl Tool {
|
|||||||
Self::Tailwind => {
|
Self::Tailwind => {
|
||||||
let windows_extension = match self.target_platform() {
|
let windows_extension = match self.target_platform() {
|
||||||
"windows" => ".exe",
|
"windows" => ".exe",
|
||||||
_ => ""
|
_ => "",
|
||||||
};
|
};
|
||||||
format!(
|
format!(
|
||||||
"https://github.com/tailwindlabs/tailwindcss/releases/download/{version}/tailwindcss-{target}-x64{optional_ext}",
|
"https://github.com/tailwindlabs/tailwindcss/releases/download/{version}/tailwindcss-{target}-x64{optional_ext}",
|
||||||
@@ -177,7 +171,7 @@ impl Tool {
|
|||||||
"tar.gz"
|
"tar.gz"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Self::Tailwind => "bin"
|
Self::Tailwind => "bin",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,7 +212,7 @@ impl Tool {
|
|||||||
let dir_name = match self {
|
let dir_name = match self {
|
||||||
Self::Binaryen => format!("binaryen-{}", self.tool_version()),
|
Self::Binaryen => format!("binaryen-{}", self.tool_version()),
|
||||||
Self::Sass => "dart-sass".to_string(),
|
Self::Sass => "dart-sass".to_string(),
|
||||||
Self::Tailwind => self.name().to_string()
|
Self::Tailwind => self.name().to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if self.extension() == "tar.gz" {
|
if self.extension() == "tar.gz" {
|
||||||
@@ -234,10 +228,10 @@ impl Tool {
|
|||||||
} else if self.extension() == "bin" {
|
} else if self.extension() == "bin" {
|
||||||
let bin_path = match self.target_platform() {
|
let bin_path = match self.target_platform() {
|
||||||
"windows" => tool_path.join(&dir_name).join(self.name()).join(".exe"),
|
"windows" => tool_path.join(&dir_name).join(self.name()).join(".exe"),
|
||||||
_ => tool_path.join(&dir_name).join(self.name())
|
_ => tool_path.join(&dir_name).join(self.name()),
|
||||||
} ;
|
};
|
||||||
// Manualy creating tool directory because we directly download the binary via Github
|
// Manualy creating tool directory because we directly download the binary via Github
|
||||||
std::fs::create_dir( tool_path.join(dir_name))?;
|
std::fs::create_dir(tool_path.join(dir_name))?;
|
||||||
|
|
||||||
let mut final_file = std::fs::File::create(&bin_path)?;
|
let mut final_file = std::fs::File::create(&bin_path)?;
|
||||||
let mut temp_file = File::open(&temp_path)?;
|
let mut temp_file = File::open(&temp_path)?;
|
||||||
|
|||||||
Reference in new issue
Block a user