@@ -93,6 +93,9 @@ enum Command {
9393 /// Subcommands for Devnet usage
9494 #[ clap( subcommand, name = "devnet" ) ]
9595 Devnet ( Devnet ) ,
96+ /// Subcommands ts-to-clar transpiler usage
97+ #[ clap( name = "build" , aliases = & [ "transpile" ] , bin_name = "build" ) ]
98+ Build ( Build ) ,
9699 /// Get Clarity autocompletion and inline errors from your code editor (VSCode, vim, emacs, etc)
97100 #[ clap( name = "lsp" , bin_name = "lsp" ) ]
98101 LSP ,
@@ -104,6 +107,12 @@ enum Command {
104107 DAP ,
105108}
106109
110+ #[ derive( Parser , PartialEq , Clone , Debug ) ]
111+ struct Build {
112+ #[ clap( long = "path" , short = 'p' ) ]
113+ pub path : Option < String > ,
114+ }
115+
107116#[ derive( Parser , PartialEq , Clone , Debug ) ]
108117struct Formatter {
109118 #[ clap( long = "manifest-path" , short = 'm' ) ]
@@ -1325,6 +1334,24 @@ pub fn main() {
13251334 }
13261335 Devnet :: DevnetStart ( cmd) => devnet_start ( cmd, clarinetrc) ,
13271336 } ,
1337+ Command :: Build ( Build { path } ) => {
1338+ let file_name = path. unwrap_or_else ( || {
1339+ eprintln ! ( "No file path provided. Please specify a .clar.ts file." ) ;
1340+ process:: exit ( 1 ) ;
1341+ } ) ;
1342+ let file_path = std:: path:: Path :: new ( & file_name) ;
1343+ let extension = file_path. extension ( ) . unwrap_or_default ( ) ;
1344+ assert_eq ! ( extension, "ts" ) ;
1345+ assert ! ( file_path. is_file( ) ) ;
1346+ assert ! ( file_name. ends_with( ".clar.ts" ) ) ;
1347+
1348+ let output_path = file_name. strip_suffix ( ".ts" ) . unwrap ( ) ;
1349+
1350+ let src = std:: fs:: read_to_string ( file_path) . unwrap ( ) ;
1351+ let clarity_code = ts_to_clar:: transpile ( & file_name, & src) . unwrap ( ) ;
1352+ std:: fs:: write ( output_path, clarity_code) . unwrap ( ) ;
1353+ println ! ( "Transpiled {file_name} to {output_path}" ) ;
1354+ }
13281355 } ;
13291356}
13301357
0 commit comments