1pub mod models;
2pub mod output;
3pub mod github;
4pub mod validators;
5
6use models::ValidationSummary;
7use std::path::Path;
8
9pub struct ValidateOptions {
10 pub check_naming: bool,
11 pub check_json: bool,
12 pub check_frontmatter: bool,
13 pub fail_on_error: bool,
14}
15
16impl Default for ValidateOptions {
17 fn default() -> Self {
18 Self {
19 check_naming: true,
20 check_json: true,
21 check_frontmatter: true,
22 fail_on_error: true,
23 }
24 }
25}
26
27pub fn validate_plugin(plugin_path: &Path, options: &ValidateOptions) -> ValidationSummary {
29 let mut summary = ValidationSummary::new();
30
31 if !plugin_path.exists() {
33 eprintln!("Error: Plugin path does not exist: {}", plugin_path.display());
34 std::process::exit(1);
35 }
36
37 if !plugin_path.is_dir() {
38 eprintln!("Error: Plugin path is not a directory: {}", plugin_path.display());
39 std::process::exit(1);
40 }
41
42 output::print_info(&format!("Validating plugin at: {}", plugin_path.display()));
43 println!();
44
45 if options.check_naming {
47 let result = validators::validate_naming(plugin_path);
48 output::print_validation_result(&result);
49 github::output_github_results(&result);
50 summary.add_result(result);
51 }
52
53 if options.check_json {
54 let result = validators::validate_json(plugin_path);
55 output::print_validation_result(&result);
56 github::output_github_results(&result);
57 summary.add_result(result);
58 }
59
60 if options.check_frontmatter {
61 let result = validators::validate_frontmatter(plugin_path);
62 output::print_validation_result(&result);
63 github::output_github_results(&result);
64 summary.add_result(result);
65 }
66
67 summary
68}
69
70#[cfg(test)]
71mod tests {
72 use super::*;
73 use std::fs;
74 use tempfile::TempDir;
75
76 #[test]
77 fn test_validate_plugin_basic() {
78 let temp_dir = TempDir::new().unwrap();
79 let plugin_dir = temp_dir.path().join("test-plugin");
80 fs::create_dir(&plugin_dir).unwrap();
81
82 let marketplace_json = plugin_dir.join("marketplace.json");
84 fs::write(
85 &marketplace_json,
86 r#"{
87 "name": "test-plugin",
88 "version": "1.0.0",
89 "description": "Test plugin",
90 "author": {
91 "name": "Test Author"
92 }
93 }"#,
94 )
95 .unwrap();
96
97 let options = ValidateOptions::default();
98 let summary = validate_plugin(&plugin_dir, &options);
99
100 assert!(summary.total_checks >= 2);
102 }
103}