@@ -8,6 +8,7 @@ use std::path::{Path, PathBuf};
88
99use anyhow:: { anyhow, Context , Result } ;
1010use clap:: Parser ;
11+ use inflector:: Inflector ;
1112use serde_json:: Value as JsonValue ;
1213
1314use crate :: formatter:: format_typescript;
@@ -356,7 +357,7 @@ fn add_mapping_file(project_dir: &Path, contract_name: &str, events: &[EventInfo
356357 let src_dir = project_dir. join ( "src" ) ;
357358 fs:: create_dir_all ( & src_dir) . context ( "Failed to create src directory" ) ?;
358359
359- let mapping_file = src_dir. join ( format ! ( "{}.ts" , to_kebab_case( contract_name ) ) ) ;
360+ let mapping_file = src_dir. join ( format ! ( "{}.ts" , contract_name . to_kebab_case( ) ) ) ;
360361
361362 if mapping_file. exists ( ) {
362363 step (
@@ -448,22 +449,6 @@ fn generate_event_handler(event: &EventInfo) -> String {
448449 )
449450}
450451
451- /// Convert a string to kebab-case.
452- fn to_kebab_case ( s : & str ) -> String {
453- let mut result = String :: new ( ) ;
454- for ( i, c) in s. chars ( ) . enumerate ( ) {
455- if c. is_uppercase ( ) {
456- if i > 0 {
457- result. push ( '-' ) ;
458- }
459- result. push ( c. to_lowercase ( ) . next ( ) . unwrap_or ( c) ) ;
460- } else {
461- result. push ( c) ;
462- }
463- }
464- result
465- }
466-
467452/// Update the manifest with the new data source.
468453fn update_manifest (
469454 manifest_path : & Path ,
@@ -555,7 +540,7 @@ fn update_manifest(
555540 ) ;
556541 mapping. insert (
557542 serde_yaml:: Value :: String ( "file" . to_string ( ) ) ,
558- serde_yaml:: Value :: String ( format ! ( "./src/{}.ts" , to_kebab_case( contract_name ) ) ) ,
543+ serde_yaml:: Value :: String ( format ! ( "./src/{}.ts" , contract_name . to_kebab_case( ) ) ) ,
559544 ) ;
560545
561546 // Build the data source
@@ -651,11 +636,11 @@ mod tests {
651636
652637 #[ test]
653638 fn test_to_kebab_case ( ) {
654- assert_eq ! ( to_kebab_case ( "MyContract" ) , "my-contract" ) ;
655- assert_eq ! ( to_kebab_case ( "SimpleToken" ) , "simple-token" ) ;
656- assert_eq ! ( to_kebab_case ( "Contract" ) , "contract" ) ;
657- assert_eq ! ( to_kebab_case ( "contract" ) , "contract" ) ;
658- assert_eq ! ( to_kebab_case ( "ERC20Token" ) , "e-r-c20 -token" ) ;
639+ assert_eq ! ( "MyContract" . to_kebab_case ( ) , "my-contract" ) ;
640+ assert_eq ! ( "SimpleToken" . to_kebab_case ( ) , "simple-token" ) ;
641+ assert_eq ! ( "Contract" . to_kebab_case ( ) , "contract" ) ;
642+ assert_eq ! ( "contract" . to_kebab_case ( ) , "contract" ) ;
643+ assert_eq ! ( "ERC20Token" . to_kebab_case ( ) , "erc20 -token" ) ;
659644 }
660645
661646 #[ test]
0 commit comments