1#[tracing::instrument(skip(options))]
7pub async fn Fn(options:crate::Struct::SWC::Option, _parallel:bool) -> anyhow::Result<()> {
16 tracing_subscriber::fmt::init();
17
18 let compiler = std::sync::Arc::new(crate::Fn::OXC::Compiler::Compiler::new(options.config.clone()));
20
21 let input_base = options.entry[0][0].clone();
23 let output_base = options.output.clone();
24 let pattern = options.pattern.clone();
25
26 println!("Starting compilation from {} to {}", input_base, output_base);
27
28 let ts_files:Vec<String> = walkdir::WalkDir::new(&input_base)
31 .follow_links(true)
32 .into_iter()
33 .filter_map(|e| {
34 let entry = e.ok()?;
35 let path = entry.path();
36 let path_str = path.to_string_lossy();
37 if path_str.ends_with(".d.ts") {
39 None
40 } else if path.is_file() && path_str.ends_with(&pattern) {
41 Some(path_str.to_string())
42 } else {
43 None
44 }
45 })
46 .collect();
47
48 println!("Found {} TypeScript files in {}", ts_files.len(), input_base);
49
50 let mut count = 0;
52 let mut error = 0;
53
54 for file_path in ts_files {
55 print!(".");
56 std::io::stdout().flush().unwrap();
57
58 match tokio::fs::read_to_string(&file_path).await {
59 Ok(input) => {
60 let input_path = std::path::Path::new(&file_path);
62 let base_path = std::path::Path::new(&input_base);
63 let relative_path = input_path.strip_prefix(base_path).unwrap_or(input_path);
64
65 let output_path = std::path::Path::new(&output_base).join(relative_path).with_extension("js");
67
68 match compiler.compile_file_to(&file_path, input, &output_path, options.use_define_for_class_fields) {
69 Ok(output) => {
70 debug!("Compiled: {} -> {}", file_path, output);
71 count += 1;
72 },
73 Err(e) => {
74 error!("Compilation error for {}: {}", file_path, e);
75 error += 1;
76 },
77 }
78 },
79 Err(e) => {
80 error!("Failed to read file {}: {}", file_path, e);
81 error += 1;
82 },
83 }
84 }
85
86 println!();
87
88 let outlook = compiler.outlook.lock().unwrap();
89
90 info!(
91 "Compilation complete. Processed {} files in {:?}. {} successful, {} failed.",
92 outlook.count, outlook.elapsed, count, error
93 );
94
95 println!("\n=== Compilation Summary ===");
97 println!("Total files processed: {}", outlook.count);
98 println!("Successful: {}", count);
99 println!("Failed: {}", error);
100 println!("Time elapsed: {:?}\n", outlook.elapsed);
101
102 Ok(())
103}
104
105use std::io::Write;
106
107use tracing::{debug, error, info};