Skip to content

Commit

Permalink
Merge branch 'main' into cargo-generate
Browse files Browse the repository at this point in the history
  • Loading branch information
SleeplessOne1917 committed Feb 14, 2025
2 parents b15cd29 + b7d9539 commit 498cbd1
Show file tree
Hide file tree
Showing 19 changed files with 68 additions and 50 deletions.
10 changes: 0 additions & 10 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ eula = false

[dependencies]
brotli = "7"
clap = { version = "4.5.18", features = ["derive"] }
clap = { version = "4.5.27", features = ["derive"] }
serde = { version = "1.0.210", features = ["derive"] }
anyhow = "1.0.89"
libflate = "2"
Expand All @@ -69,7 +69,6 @@ which = "7"
cargo_metadata = { version = "0.19", features = ["builder"] }
serde_json = "1.0.128"
wasm-bindgen-cli-support = "0.2.100"
ansi_term = "0.12"

reqwest = { version = "0.12.8", features = [
"blocking",
Expand Down
1 change: 1 addition & 0 deletions src/command/test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::compile::{front_cargo_process, server_cargo_process};
use crate::config::{Config, Project};
use crate::ext::anyhow::{anyhow, Context, Result};
use crate::ext::Paint;
use crate::logger::GRAY;

pub async fn test_all(conf: &Config) -> Result<()> {
Expand Down
1 change: 1 addition & 0 deletions src/compile/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::sync::Arc;
use super::ChangeSet;
use crate::config::Project;
use crate::ext::anyhow::{Context, Result};
use crate::ext::Paint;
use crate::signal::{Outcome, Product};
use crate::{ext::PathExt, fs, logger::GRAY};
use camino::{Utf8Path, Utf8PathBuf};
Expand Down
5 changes: 4 additions & 1 deletion src/compile/front.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use crate::ext::sync::{wait_interruptible, CommandResult};
use crate::ext::{fs, PathBufExt};
use crate::signal::{Interrupt, Outcome, Product};
use crate::{
ext::anyhow::{Context, Result},
ext::{
anyhow::{Context, Result},
Paint,
},
logger::GRAY,
};
use anyhow::Ok;
Expand Down
1 change: 1 addition & 0 deletions src/compile/sass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
ext::{
anyhow::{Context, Result},
sync::{wait_piped_interruptible, CommandResult, OutputExt},
Paint,
},
logger::GRAY,
signal::{Interrupt, Outcome},
Expand Down
7 changes: 5 additions & 2 deletions src/compile/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ use std::sync::Arc;
use super::ChangeSet;
use crate::{
config::Project,
ext::anyhow::{Context, Result},
ext::sync::{wait_interruptible, CommandResult},
ext::{
anyhow::{Context, Result},
sync::{wait_interruptible, CommandResult},
Paint,
},
logger::GRAY,
signal::{Interrupt, Outcome, Product},
};
Expand Down
2 changes: 1 addition & 1 deletion src/compile/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
config::Project,
ext::{
anyhow::{anyhow, bail, Context, Result},
PathBufExt,
Paint, PathBufExt,
},
fs,
logger::GRAY,
Expand Down
2 changes: 1 addition & 1 deletion src/compile/tailwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
anyhow::Context,
fs,
sync::{wait_piped_interruptible, CommandResult, OutputExt},
Exe,
Exe, Paint,
},
logger::GRAY,
signal::{Interrupt, Outcome},
Expand Down
1 change: 1 addition & 0 deletions src/config/project.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::config::hash_file::HashFile;
use crate::ext::Paint;
use crate::{
config::lib_package::LibPackage,
ext::{
Expand Down
5 changes: 4 additions & 1 deletion src/ext/exe.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::{
ext::anyhow::{bail, Context, Result},
ext::{
anyhow::{bail, Context, Result},
Paint,
},
logger::GRAY,
};
use bytes::Bytes;
Expand Down
2 changes: 1 addition & 1 deletion src/ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ pub use exe::{Exe, ExeMeta};
pub use path::{
append_str_to_filename, determine_pdb_filename, remove_nested, PathBufExt, PathExt,
};
pub use util::{os_arch, StrAdditions};
pub use util::{os_arch, Paint, StrAdditions};
14 changes: 14 additions & 0 deletions src/ext/util.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::ext::anyhow::{bail, Context, Result};
use camino::Utf8PathBuf;
use clap::builder::styling::{Color, Style};
use std::borrow::Cow;

pub fn os_arch() -> Result<(&'static str, &'static str)> {
Expand Down Expand Up @@ -74,3 +75,16 @@ impl StrAdditions for String {
self.as_str().to_created_dir()
}
}

pub trait Paint {
fn paint<'a>(self, text: impl Into<Cow<'a, str>>) -> String;
}

impl Paint for Color {
fn paint<'a>(self, text: impl Into<Cow<'a, str>>) -> String {
let text = text.into();
let style = Style::new().fg_color(Some(self));

format!("{style}{text}{style:#}")
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::ext::PathBufExt;
use crate::logger::GRAY;
use camino::Utf8PathBuf;
use config::{Cli, Config};
use ext::fs;
use ext::{fs, Paint};
use signal::Interrupt;
use std::env;
use std::path::PathBuf;
Expand Down
42 changes: 21 additions & 21 deletions src/logger.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
use ansi_term::{Colour::Fixed, Style};
use clap::builder::styling::{Ansi256Color, Color};
use flexi_logger::{
filter::{LogLineFilter, LogLineWriter},
DeferredNow, Level, Record,
};
use std::io::Write;
use std::sync::OnceLock;

use crate::ext::anyhow::Context;
use crate::ext::{anyhow::Context, Paint};
use crate::{config::Log, ext::StrAdditions};

// https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
lazy_static::lazy_static! {
static ref ERR_RED: ansi_term::Color = Fixed(196);
static ref WARN_YELLOW: ansi_term::Color = Fixed(214);
pub static ref INFO_GREEN: ansi_term::Color = Fixed(77);
static ref DBG_BLUE: ansi_term::Color = Fixed(26);
static ref TRACE_VIOLET: ansi_term::Color = Fixed(98);

pub static ref GRAY: ansi_term::Color = Fixed(241);
pub static ref BOLD: ansi_term::Style = Style::new().bold();
static ref LOG_SELECT: OnceLock<LogFlag> = OnceLock::new();
const fn color(num: u8) -> Color {
Color::Ansi256(Ansi256Color(num))
}

const ERR_RED: Color = color(196);
const WARN_YELLOW: Color = color(214);
const INFO_GREEN: Color = color(77);
const DBG_BLUE: Color = color(26);
const TRACE_VIOLET: Color = color(98);
pub const GRAY: Color = color(241);

static LOG_SELECT: OnceLock<LogFlag> = OnceLock::new();

pub fn setup(verbose: u8, logs: &[Log]) {
let log_level = match verbose {
0 => "info",
Expand Down Expand Up @@ -94,7 +94,7 @@ fn format(
} else {
let (word, rest) = split(&args);
let word = word.pad_left_to(12);
write!(write, "{} {}", lvl_color.paint(word), rest)
write!(write, "{} {rest}", lvl_color.paint(word))
}
}

Expand Down Expand Up @@ -136,17 +136,17 @@ impl LogLineFilter for Filter {
}

trait LevelExt {
fn color(&self) -> ansi_term::Color;
fn color(&self) -> Color;
}

impl LevelExt for Level {
fn color(&self) -> ansi_term::Color {
fn color(&self) -> Color {
match self {
Level::Error => *ERR_RED,
Level::Warn => *WARN_YELLOW,
Level::Info => *INFO_GREEN,
Level::Debug => *DBG_BLUE,
Level::Trace => *TRACE_VIOLET,
Level::Error => ERR_RED,
Level::Warn => WARN_YELLOW,
Level::Info => INFO_GREEN,
Level::Debug => DBG_BLUE,
Level::Trace => TRACE_VIOLET,
}
}
}
15 changes: 8 additions & 7 deletions src/service/notify.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::compile::Change;
use crate::config::Project;
use crate::ext::anyhow::{anyhow, Result};
use crate::ext::Paint;
use crate::signal::Interrupt;
use crate::{
ext::{remove_nested, PathBufExt, PathExt},
Expand Down Expand Up @@ -116,7 +117,7 @@ fn handle(event: Event, proj: Arc<Project>) {
for path in paths {
if let Some(assets) = &proj.assets {
if path.starts_with(&assets.dir) {
log::debug!("Notify asset change {}", GRAY.paint(path.to_string()));
log::debug!("Notify asset change {}", GRAY.paint(path.as_str()));
changes.push(Change::Asset);
}
}
Expand All @@ -125,19 +126,19 @@ fn handle(event: Event, proj: Arc<Project>) {
let lib_js = path.starts_with(&proj.js_dir) && path.is_ext_any(&["js"]);

if lib_rs || lib_js {
log::debug!("Notify lib source change {}", GRAY.paint(path.to_string()));
log::debug!("Notify lib source change {}", GRAY.paint(path.as_str()));
changes.push(Change::LibSource);
}

if path.starts_with_any(&proj.bin.src_paths) && path.is_ext_any(&["rs"]) {
log::debug!("Notify bin source change {}", GRAY.paint(path.to_string()));
log::debug!("Notify bin source change {}", GRAY.paint(path.as_str()));
changes.push(Change::BinSource);
}

if let Some(file) = &proj.style.file {
let src = file.source.clone().without_last();
if path.starts_with(src) && path.is_ext_any(&["scss", "sass", "css"]) {
log::debug!("Notify style change {}", GRAY.paint(path.to_string()));
log::debug!("Notify style change {}", GRAY.paint(path.as_str()));
changes.push(Change::Style)
}
}
Expand All @@ -146,15 +147,15 @@ fn handle(event: Event, proj: Arc<Project>) {
if path.as_path() == tailwind.config_file.as_path()
|| path.as_path() == tailwind.input_file.as_path()
{
log::debug!("Notify style change {}", GRAY.paint(path.to_string()));
log::debug!("Notify style change {}", GRAY.paint(path.as_str()));
changes.push(Change::Style)
}
}

if path.starts_with_any(&proj.watch_additional_files) {
log::debug!(
"Notify additional file change {}",
GRAY.paint(path.to_string())
GRAY.paint(path.as_str())
);
changes.push(Change::Additional);
}
Expand All @@ -164,7 +165,7 @@ fn handle(event: Event, proj: Arc<Project>) {
} else {
log::trace!(
"Notify changed but not watched: {}",
GRAY.paint(path.to_string())
GRAY.paint(path.as_str())
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/service/patch.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::config::Project;
use crate::ext::anyhow::Result;
use crate::ext::PathBufExt;
use crate::ext::{Paint, PathBufExt};
use crate::signal::{Interrupt, ReloadSignal};
use crate::{ext::remove_nested, logger::GRAY};
use camino::Utf8PathBuf;
Expand Down
1 change: 1 addition & 0 deletions src/service/reload.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::config::Project;
use crate::ext::sync::wait_for_socket;
use crate::ext::Paint;
use crate::logger::GRAY;
use crate::signal::Interrupt;
use crate::signal::{ReloadSignal, ReloadType};
Expand Down
2 changes: 1 addition & 1 deletion src/service/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use crate::{
config::Project,
ext::{anyhow::Result, append_str_to_filename, determine_pdb_filename, fs},
ext::{anyhow::Result, append_str_to_filename, determine_pdb_filename, fs, Paint},
logger::GRAY,
signal::{Interrupt, ReloadSignal, ServerRestart},
};
Expand Down

0 comments on commit 498cbd1

Please sign in to comment.