improved the logging
This commit is contained in:
@@ -5,7 +5,7 @@ use std::{
|
|||||||
|
|
||||||
use crate::app::{
|
use crate::app::{
|
||||||
build::{docki_build, DockiBuildResult},
|
build::{docki_build, DockiBuildResult},
|
||||||
fs_util,
|
fs_util, log::display_status,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct BuildExecution {
|
pub struct BuildExecution {
|
||||||
@@ -73,23 +73,21 @@ impl BuildExecution {
|
|||||||
|
|
||||||
match result {
|
match result {
|
||||||
DockiBuildResult::Err(err) => {
|
DockiBuildResult::Err(err) => {
|
||||||
self.display_status("Error", in_path, "");
|
self.display_building_status("Error", in_path, "");
|
||||||
println!("{}", err)
|
println!("{}", err)
|
||||||
},
|
},
|
||||||
DockiBuildResult::Copy(out_path) => self.display_status("Copy", &in_path, &out_path),
|
DockiBuildResult::Copy(out_path) => self.display_building_status("Copy", &in_path, &out_path),
|
||||||
DockiBuildResult::Slide(out_path) => self.display_status("Slide", &in_path, &out_path),
|
DockiBuildResult::Slide(out_path) => self.display_building_status("Slide", &in_path, &out_path),
|
||||||
DockiBuildResult::Doc(out_path) => self.display_status("Doc", &in_path, &out_path)
|
DockiBuildResult::Doc(out_path) => self.display_building_status("Doc", &in_path, &out_path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn display_status(&self, status_type: &str, in_path: &str, out_path: &str) -> () {
|
fn display_building_status(&self, status_type: &str, in_path: &str, out_path: &str) -> () {
|
||||||
println!(
|
let progress_str = format!("{} / {}", self.progress, self.goal);
|
||||||
"({} / {}) [{}] {} -> {}",
|
display_status(&progress_str, status_type, in_path, out_path);
|
||||||
self.progress, self.goal, status_type, in_path, out_path
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,13 @@ use notify::{
|
|||||||
event::ModifyKind,
|
event::ModifyKind,
|
||||||
Event, EventKind, RecursiveMode, Watcher,
|
Event, EventKind, RecursiveMode, Watcher,
|
||||||
};
|
};
|
||||||
use std::{env, path::Path};
|
use std::{env, path::Path, process::Output};
|
||||||
|
|
||||||
use crate::app::{ watcher::watcher, build::docki_build};
|
use crate::app::{ watcher::watcher, build::{docki_build, DockiBuildResult}, commands::build::build, log::display_status};
|
||||||
|
|
||||||
|
|
||||||
pub async fn serve() {
|
pub async fn serve() {
|
||||||
|
build().await;
|
||||||
tokio::join!(watch_and_build(), start_server());
|
tokio::join!(watch_and_build(), start_server());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,7 +22,7 @@ async fn watch_and_build() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn start_server() {
|
async fn start_server() {
|
||||||
println!("Serving at http://localhost:8080");
|
println!("\nServing at {} ", "http://localhost:8080".bold());
|
||||||
|
|
||||||
let Ok(()) = listen("localhost", 8080, "./dist").await else {
|
let Ok(()) = listen("localhost", 8080, "./dist").await else {
|
||||||
panic!("could not start server")
|
panic!("could not start server")
|
||||||
@@ -44,14 +45,13 @@ async fn watch(path: &Path) -> notify::Result<()> {
|
|||||||
fn file_change(event: Event) {
|
fn file_change(event: Event) {
|
||||||
match event.kind {
|
match event.kind {
|
||||||
EventKind::Modify(ModifyKind::Data(_)) => {
|
EventKind::Modify(ModifyKind::Data(_)) => {
|
||||||
build_file(event.paths).expect("building file failed");
|
build_file(event.paths)
|
||||||
()
|
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_file(paths: Vec<std::path::PathBuf>) -> Result<(), String> {
|
fn build_file(paths: Vec<std::path::PathBuf>) {
|
||||||
let invalid_path_message = "changed path is invalid";
|
let invalid_path_message = "changed path is invalid";
|
||||||
let in_path = paths
|
let in_path = paths
|
||||||
.first()
|
.first()
|
||||||
@@ -61,10 +61,22 @@ fn build_file(paths: Vec<std::path::PathBuf>) -> Result<(), String> {
|
|||||||
.replace(¤t_dir(), "")
|
.replace(¤t_dir(), "")
|
||||||
.replace("/./", "./");
|
.replace("/./", "./");
|
||||||
|
|
||||||
println!("{} {}", "[Rebuilding]".green(), in_path);
|
|
||||||
|
|
||||||
docki_build(&in_path);
|
let result = docki_build(&in_path);
|
||||||
return Ok(())
|
|
||||||
|
match result {
|
||||||
|
DockiBuildResult::Slide(out_path) => display_rebuilding_status("Slide", &in_path, &out_path),
|
||||||
|
DockiBuildResult::Doc(out_path) => display_rebuilding_status("Doc", &in_path, &out_path),
|
||||||
|
DockiBuildResult::Copy(out_path) => display_rebuilding_status("Copy", &in_path, &out_path),
|
||||||
|
DockiBuildResult::Err(err) => {
|
||||||
|
display_rebuilding_status("Error", &in_path, "");
|
||||||
|
println!("{}", err);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn display_rebuilding_status(context: &str, in_path: &str, out_path: &str) {
|
||||||
|
display_status("Rebuildng", context, in_path, out_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn current_dir() -> String {
|
fn current_dir() -> String {
|
||||||
|
|||||||
20
src/app/log/mod.rs
Normal file
20
src/app/log/mod.rs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
use colored::Colorize;
|
||||||
|
|
||||||
|
pub fn display_status(context1: &str, context2: &str, in_path: &str, out_path: &str) {
|
||||||
|
let colored_context = color_context(context2);
|
||||||
|
println!(
|
||||||
|
"({}) [{}] {} -> {}",
|
||||||
|
context1.bold(),
|
||||||
|
colored_context,
|
||||||
|
in_path,
|
||||||
|
out_path
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn color_context(context: &str) -> colored::ColoredString {
|
||||||
|
if context == "Error" {
|
||||||
|
return context.bright_red()
|
||||||
|
} else {
|
||||||
|
return context.bright_green()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ mod commands;
|
|||||||
pub mod build;
|
pub mod build;
|
||||||
pub mod fs_util;
|
pub mod fs_util;
|
||||||
pub mod watcher;
|
pub mod watcher;
|
||||||
|
pub mod log;
|
||||||
mod args;
|
mod args;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|||||||
Reference in New Issue
Block a user