@@ -4,6 +4,7 @@ use std::path::{Path, PathBuf};
44use clap:: Arg ;
55use clap:: ArgAction :: SetTrue ;
66use convert_case:: { Case , Casing } ;
7+ use duct:: cmd;
78use spacetimedb_lib:: sats:: { AlgebraicType , Typespace } ;
89use spacetimedb_lib:: { bsatn, MiscModuleExport , ModuleDef , ReducerDef , TableDef , TypeAlias } ;
910use wasmtime:: { AsContext , Caller , ExternType } ;
@@ -110,10 +111,15 @@ Failed to compile module {:?}. See cargo errors above for more details.",
110111 ) ) ;
111112 }
112113
114+ let mut paths = vec ! [ ] ;
113115 for ( fname, code) in generate ( & wasm_file, lang, namespace. as_str ( ) ) ?. into_iter ( ) {
114- fs:: write ( out_dir. join ( fname) , code) ?;
116+ let path = out_dir. join ( fname) ;
117+ paths. push ( path. clone ( ) ) ;
118+ fs:: write ( path, code) ?;
115119 }
116120
121+ format_files ( paths, lang) ?;
122+
117123 println ! ( "Generate finished successfully." ) ;
118124 Ok ( ( ) )
119125}
@@ -433,3 +439,19 @@ impl Memory {
433439 . get ( ..len as usize )
434440 }
435441}
442+
443+ fn format_files ( generated_files : Vec < PathBuf > , lang : Language ) -> anyhow:: Result < ( ) > {
444+ match lang {
445+ Language :: Rust => {
446+ cmd ! ( "rustup" , "component" , "add" , "rustfmt" ) . run ( ) ?;
447+ for path in generated_files {
448+ cmd ! ( "rustfmt" , path. to_str( ) . unwrap( ) ) . run ( ) ?;
449+ }
450+ }
451+ Language :: Csharp => { }
452+ Language :: TypeScript => { }
453+ Language :: Python => { }
454+ }
455+
456+ Ok ( ( ) )
457+ }
0 commit comments