@@ -4,7 +4,7 @@ mod validators;
44
55use std:: { fs, error:: Error , path:: PathBuf , env } ;
66
7- use validators:: env:: EnvValidator ;
7+ use validators:: { env:: EnvValidator , Recommend :: RecommendValidator } ;
88
99use crate :: validators:: { message:: { Message , self } , package:: { PackageValidator } , config:: ConfigValidator , common:: { Validator } } ;
1010
@@ -15,30 +15,39 @@ extern crate napi_derive;
1515pub fn validate_config ( config_str : String ) {
1616 let result = validate_config_core ( config_str) ;
1717 if let Err ( e) = result {
18- println ! ( "{}" , Message { kind: message:: MessageKind :: Error , content: e. to_string( ) } ) ;
18+ println ! ( "{}" , Message { kind: message:: MessageKind :: Error , content: e. to_string( ) , solution : None } ) ;
1919 }
2020}
2121
2222#[ napi]
2323pub fn validate_package ( app_path : String , node_modules_path : String , cli_version : String ) {
2424 let result = validate_package_core ( app_path, node_modules_path, cli_version) ;
2525 if let Err ( e) = result {
26- println ! ( "{}" , Message { kind: message:: MessageKind :: Error , content: e. to_string( ) } ) ;
26+ println ! ( "{}" , Message { kind: message:: MessageKind :: Error , content: e. to_string( ) , solution : None } ) ;
2727 }
2828}
2929
3030#[ napi]
3131pub fn validate_env ( ) {
3232 let result = validate_env_core ( ) ;
3333 if let Err ( e) = result {
34- println ! ( "{}" , Message { kind: message:: MessageKind :: Error , content: e. to_string( ) } ) ;
34+ println ! ( "{}" , Message { kind: message:: MessageKind :: Error , content: e. to_string( ) , solution: None } ) ;
35+ }
36+ }
37+
38+ #[ napi]
39+ pub fn validate_recommend ( app_path : String , node_modules_path : String ) {
40+ let result = validate_recommend_core ( app_path, node_modules_path) ;
41+ if let Err ( e) = result {
42+ println ! ( "{}" , Message { kind: message:: MessageKind :: Error , content: e. to_string( ) , solution: None } ) ;
3543 }
3644}
3745
3846fn validate_config_core ( config_str : String ) -> Result < ( ) , Box < dyn Error > > {
3947 let tip = Message {
4048 kind : validators:: message:: MessageKind :: Info ,
41- content : String :: from ( "开始进行项目配置验证!" )
49+ content : String :: from ( "开始进行项目配置验证!" ) ,
50+ solution : None
4251 } ;
4352 println ! ( "{}" , tip) ;
4453 let current_dir = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
@@ -55,7 +64,8 @@ fn validate_config_core(config_str: String) -> Result<(), Box<dyn Error>> {
5564 Err ( e) => vec ! [
5665 Message {
5766 kind: validators:: message:: MessageKind :: Error ,
58- content: e. to_string( )
67+ content: e. to_string( ) ,
68+ solution: None
5969 }
6070 ]
6171 } ;
@@ -64,15 +74,16 @@ fn validate_config_core(config_str: String) -> Result<(), Box<dyn Error>> {
6474 println ! ( "{}" , message) ;
6575 }
6676 } else {
67- println ! ( "{}" , Message { kind: message:: MessageKind :: Success , content: "项目配置正确!" . to_string( ) } ) ;
77+ println ! ( "{}" , Message { kind: message:: MessageKind :: Success , content: "项目配置正确!" . to_string( ) , solution : None } ) ;
6878 }
6979 Ok ( ( ) )
7080}
7181
7282fn validate_package_core ( app_path : String , node_modules_path : String , cli_version : String ) -> Result < ( ) , Box < dyn Error > > {
7383 let tip = Message {
7484 kind : validators:: message:: MessageKind :: Info ,
75- content : String :: from ( "开始进行项目依赖安装正确性验证!" )
85+ content : String :: from ( "开始进行项目依赖安装正确性验证!" ) ,
86+ solution : None
7687 } ;
7788 println ! ( "{}" , tip) ;
7889 let mut path = PathBuf :: new ( ) ;
@@ -85,7 +96,8 @@ fn validate_package_core(app_path: String, node_modules_path: String, cli_versio
8596 Err ( e) => vec ! [
8697 Message {
8798 kind: validators:: message:: MessageKind :: Error ,
88- content: e. to_string( )
99+ content: e. to_string( ) ,
100+ solution: None
89101 }
90102 ]
91103 } ;
@@ -103,3 +115,21 @@ fn validate_env_core() -> Result<(), Box<dyn Error>> {
103115 }
104116 Ok ( ( ) )
105117}
118+
119+ fn validate_recommend_core ( app_path : String , node_modules_path : String ) -> Result < ( ) , Box < dyn Error > > {
120+ let recommend_validator_result = RecommendValidator :: build ( & app_path, & node_modules_path) ;
121+ let messages = match recommend_validator_result {
122+ Ok ( recommend_validator) => recommend_validator. validate ( ) ,
123+ Err ( e) => vec ! [
124+ Message {
125+ kind: validators:: message:: MessageKind :: Error ,
126+ content: e. to_string( ) ,
127+ solution: None
128+ }
129+ ]
130+ } ;
131+ for message in messages {
132+ println ! ( "{}" , message) ;
133+ }
134+ Ok ( ( ) )
135+ }
0 commit comments