diff options
| -rw-r--r-- | .cargo/registry.toml | 19 | ||||
| -rw-r--r-- | build.rs | 100 | ||||
| -rw-r--r-- | src/arguments.rs | 1 | ||||
| -rw-r--r-- | src/outputs.rs | 1 |
4 files changed, 120 insertions, 1 deletions
diff --git a/.cargo/registry.toml b/.cargo/registry.toml index 6ae66bb..060ca0a 100644 --- a/.cargo/registry.toml +++ b/.cargo/registry.toml @@ -23,3 +23,22 @@ type = "crate::renderers::json::JVResultJsonRenderer" [renderer.json_pretty] name = "json-pretty" type = "crate::renderers::json_pretty::JVResultPrettyJsonRenderer" + +#################### +### Auto-Collect ### +#################### + +[collect.outputs] +path = "src/outputs.rs" + +[collect.inputs] +path = "src/inputs.rs" + +[collect.cmds] +path = "src/cmds.rs" + +[collect.arguments] +path = "src/arguments.rs" + +[collect.renderers] +path = "src/renderers.rs" @@ -43,6 +43,11 @@ fn main() { eprintln!("Failed to generate renderer list: {}", e); std::process::exit(1); } + + if let Err(e) = generate_collect_files(&repo_root) { + eprintln!("Failed to generate collect files: {}", e); + std::process::exit(1); + } } /// Generate Inno Setup installer script (Windows only) @@ -414,3 +419,98 @@ fn generate_renderer_list_file(repo_root: &PathBuf) -> Result<(), Box<dyn std::e ); Ok(()) } + +/// Generate collect files from directory structure +fn generate_collect_files(repo_root: &PathBuf) -> Result<(), Box<dyn std::error::Error>> { + // Read and parse the TOML configuration + let config_path = repo_root.join(REGISTRY_TOML); + let config_content = std::fs::read_to_string(&config_path)?; + let config: toml::Value = toml::from_str(&config_content)?; + + // Process each collect configuration + let collect_table = config.get("collect").and_then(|v| v.as_table()); + + let collect_table = match collect_table { + Some(table) => table, + None => return Ok(()), + }; + + for (_collect_name, collect_config) in collect_table { + let config_table = match collect_config.as_table() { + Some(table) => table, + None => continue, + }; + + let path_str = match config_table.get("path").and_then(|v| v.as_str()) { + Some(path) => path, + None => continue, + }; + + let output_path = repo_root.join(path_str); + + // Extract directory name from the path (e.g., "src/renderers.rs" -> "renderers") + let dir_name = match output_path.file_stem().and_then(|s| s.to_str()) { + Some(name) => name.to_string(), + None => continue, + }; + + // Get the directory path for this collect type + // e.g., for "src/renderers.rs", we want "src/renderers/" + let output_parent = output_path.parent().unwrap_or_else(|| repo_root.as_path()); + let dir_path = output_parent.join(&dir_name); + + // Collect all .rs files in the directory (excluding the output file itself) + let mut modules = Vec::new(); + + if dir_path.exists() && dir_path.is_dir() { + for entry in std::fs::read_dir(&dir_path)? { + let entry = entry?; + let path = entry.path(); + + if !path.is_file() { + continue; + } + + let extension = match path.extension() { + Some(ext) => ext, + None => continue, + }; + + if extension != "rs" { + continue; + } + + let file_name = match path.file_stem().and_then(|s| s.to_str()) { + Some(name) => name, + None => continue, + }; + + // Skip files that start with underscore + if !file_name.starts_with('_') { + modules.push(file_name.to_string()); + } + } + } + + // Sort modules alphabetically + modules.sort(); + + // Generate the content + let mut content = String::new(); + for module in &modules { + content.push_str(&format!("pub mod {};\n", module)); + } + + // Write the file + std::fs::write(&output_path, content)?; + + println!( + "Generated {} with {} modules: {:?}", + path_str, + modules.len(), + modules + ); + } + + Ok(()) +} diff --git a/src/arguments.rs b/src/arguments.rs index e69de29..822c729 100644 --- a/src/arguments.rs +++ b/src/arguments.rs @@ -0,0 +1 @@ +pub mod status; diff --git a/src/outputs.rs b/src/outputs.rs index 8b13789..e69de29 100644 --- a/src/outputs.rs +++ b/src/outputs.rs @@ -1 +0,0 @@ - |
