This commit is contained in:
2025-04-02 22:02:26 +04:00
parent 2cd6120867
commit 556ae626ae
3 changed files with 74 additions and 16 deletions

View File

@@ -9,6 +9,7 @@ use figment::{
providers::{Format, Serialized, Yaml},
Figment,
};
use indicatif::{ProgressBar, ProgressStyle};
use sea_orm_codegen::{
DateTimeCrate as CodegenDateTimeCrate, EntityTransformer, EntityWriterContext, OutputFile,
WithPrelude, WithSerde,
@@ -53,18 +54,32 @@ async fn main() -> Result<()> {
files.extend(generate_files);
tracing::info!("Generated {} files", files.len());
fs::create_dir_all(&output_internal_entities).await?;
let progress_bar = ProgressBar::new((files.len() * 2) as u64)
.with_style(
ProgressStyle::default_bar()
.template("[{elapsed_precise}] {bar:40.cyan/blue} {pos}/{len} {msg}")?,
)
.with_message("Writing files");
for (file_path, content) in files.iter() {
tracing::info!(?file_path, "Writing file");
progress_bar.set_message(format!("Writing file: {:?}", file_path));
tracing::debug!(?file_path, "Writing file");
let mut file = fs::File::create(&file_path).await?;
file.write_all(content.as_bytes()).await?;
progress_bar.inc(1);
}
progress_bar.set_message("Running rustfmt");
for (file_path, ..) in files.iter() {
tracing::info!(?file_path, "Running rustfmt");
tracing::debug!(?file_path, "Running rustfmt");
progress_bar.set_message(format!("Running rustfmt: {:?}", file_path));
let exit_status = Command::new("rustfmt").arg(file_path).status().await?; // Get the status code
if !exit_status.success() {
// Propagate the error if any
return Err(eyre!("Failed to run rustfmt"));
}
progress_bar.inc(1);
}
progress_bar.finish();
Ok(())
}