feat: commit prettier_build
This commit is contained in:
1 parent
eb0145173d
commit
dfe571df1a
3 files changed
+38
-49
No files matched your search
+1
-1
@@ -36,7 +36,7 @@ regex = "1.5.4"
|
|||||||
chrono = "0.4.19"
|
chrono = "0.4.19"
|
||||||
anyhow = "1.0.53"
|
anyhow = "1.0.53"
|
||||||
hyper = "0.14.17"
|
hyper = "0.14.17"
|
||||||
indicatif = "0.16.2"
|
loading = "0.3.0"
|
||||||
|
|
||||||
axum = { version = "0.5.1", features = ["ws", "headers"] }
|
axum = { version = "0.5.1", features = ["ws", "headers"] }
|
||||||
tower-http = { version = "0.2.2", features = ["fs", "trace"] }
|
tower-http = { version = "0.2.2", features = ["fs", "trace"] }
|
||||||
|
|||||||
+37
-21
@@ -2,11 +2,14 @@ use crate::{
|
|||||||
config::{CrateConfig, ExecutableType},
|
config::{CrateConfig, ExecutableType},
|
||||||
error::{Error, Result},
|
error::{Error, Result},
|
||||||
tools::Tool,
|
tools::Tool,
|
||||||
CargoFormatInfo, DioxusConfig,
|
DioxusConfig,
|
||||||
};
|
};
|
||||||
|
use cargo_metadata::Message;
|
||||||
|
use loading::Loading;
|
||||||
use std::{
|
use std::{
|
||||||
|
collections::HashMap,
|
||||||
fs::{copy, create_dir_all, remove_dir_all, File},
|
fs::{copy, create_dir_all, remove_dir_all, File},
|
||||||
io::{BufRead, Read},
|
io::Read,
|
||||||
panic,
|
panic,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
process::Command,
|
process::Command,
|
||||||
@@ -75,25 +78,7 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<()> {
|
|||||||
ExecutableType::Example(name) => cmd.arg("--example").arg(name),
|
ExecutableType::Example(name) => cmd.arg("--example").arg(name),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut child = cmd.spawn()?;
|
prettier_build(cmd).unwrap();
|
||||||
let out = child.stdout.take().unwrap();
|
|
||||||
let mut out = std::io::BufReader::new(out);
|
|
||||||
let mut content = String::new();
|
|
||||||
while let Ok(_) = out.read_line(&mut content) {
|
|
||||||
// 进程退出后结束循环
|
|
||||||
if let Ok(Some(_)) = child.try_wait() {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
let content = content.split('\n').collect::<Vec<&str>>();
|
|
||||||
for json in content {
|
|
||||||
let d = serde_json::from_str::<CargoFormatInfo>(&json);
|
|
||||||
if let Ok(d) = d {
|
|
||||||
println!("\n{:#?}\n", d);
|
|
||||||
} else {
|
|
||||||
println!("\n\n{:?}\n\n", json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if !output.status.success() {
|
// if !output.status.success() {
|
||||||
// log::error!("Build failed!");
|
// log::error!("Build failed!");
|
||||||
@@ -342,6 +327,37 @@ pub fn build_desktop(config: &CrateConfig, is_serve: bool) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn prettier_build(mut cmd: Command) -> anyhow::Result<()> {
|
||||||
|
let loading = Loading::default();
|
||||||
|
let mut record: HashMap<String, String> = HashMap::new();
|
||||||
|
let mut command = cmd.spawn()?;
|
||||||
|
let reader = std::io::BufReader::new(command.stdout.take().unwrap());
|
||||||
|
for message in cargo_metadata::Message::parse_stream(reader) {
|
||||||
|
match message.unwrap() {
|
||||||
|
Message::CompilerMessage(_msg) => {
|
||||||
|
// println!("{:#?}", msg);
|
||||||
|
}
|
||||||
|
Message::CompilerArtifact(artifact) => {
|
||||||
|
record.insert(artifact.package_id.to_string(), artifact.target.name);
|
||||||
|
}
|
||||||
|
Message::BuildScriptExecuted(script) => {
|
||||||
|
let package_id = script.package_id.to_string();
|
||||||
|
if let Some(name) = record.get(&package_id) {
|
||||||
|
loading.text(format!("[{}] build done", name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Message::BuildFinished(finished) => {
|
||||||
|
if finished.success {
|
||||||
|
} else {
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => (), // Unknown message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn gen_page(config: &DioxusConfig, serve: bool) -> String {
|
pub fn gen_page(config: &DioxusConfig, serve: bool) -> String {
|
||||||
let crate_root = crate::cargo::crate_root().unwrap();
|
let crate_root = crate::cargo::crate_root().unwrap();
|
||||||
let custom_html_file = crate_root.join("index.html");
|
let custom_html_file = crate_root.join("index.html");
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
//! Utilities for working with cargo and rust files
|
//! Utilities for working with cargo and rust files
|
||||||
use serde::{Serialize, Deserialize};
|
|
||||||
|
|
||||||
use crate::error::{Error, Result};
|
use crate::error::{Error, Result};
|
||||||
use std::{
|
use std::{
|
||||||
env, fs,
|
env, fs,
|
||||||
@@ -92,28 +90,3 @@ impl Metadata {
|
|||||||
Err(Error::CargoError("InvalidOutput".to_string()))
|
Err(Error::CargoError("InvalidOutput".to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
||||||
pub struct CargoFormatInfo {
|
|
||||||
pub reason: CargoFormatReason,
|
|
||||||
#[serde(default)]
|
|
||||||
pub package_id: String,
|
|
||||||
#[serde(default)]
|
|
||||||
manifest_path: String,
|
|
||||||
#[serde(default)]
|
|
||||||
target: Option<serde_json::Value>,
|
|
||||||
#[serde(default)]
|
|
||||||
message: Option<serde_json::Value>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
||||||
pub enum CargoFormatReason {
|
|
||||||
#[serde(rename = "compiler-message")]
|
|
||||||
CompilerMessage,
|
|
||||||
#[serde(rename = "compiler-artifact")]
|
|
||||||
CompilerArtifact,
|
|
||||||
#[serde(rename = "build-script-executed")]
|
|
||||||
BuildScriptExecuted,
|
|
||||||
#[serde(rename = "build-finished")]
|
|
||||||
BuildFinished,
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user