File tree Expand file tree Collapse file tree 3 files changed +17
-7
lines changed Expand file tree Collapse file tree 3 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -83,9 +83,9 @@ pub struct BuildCommandOpts {
8383 /// Path of the JavaScript input file.
8484 pub input : PathBuf ,
8585
86- #[ arg( short, default_value = "index.wasm" ) ]
86+ #[ arg( short) ]
8787 /// Desired path of the WebAssembly output file.
88- pub output : PathBuf ,
88+ pub output : Option < PathBuf > ,
8989
9090 #[ arg( short = 'C' , long = "codegen" ) ]
9191 /// Code generation options.
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ pub struct JS {
3232}
3333
3434impl JS {
35- fn from_string ( source_code : String ) -> JS {
35+ pub fn from_string ( source_code : String ) -> JS {
3636 JS {
3737 source_code : Rc :: new ( source_code) ,
3838 }
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ use javy_config::Config;
1515use js:: JS ;
1616use std:: fs;
1717use std:: fs:: File ;
18- use std:: io:: Write ;
18+ use std:: io:: { Read , Write } ;
1919
2020fn main ( ) -> Result < ( ) > {
2121 let args = Cli :: parse ( ) ;
@@ -58,7 +58,14 @@ fn main() -> Result<()> {
5858 Ok ( ( ) )
5959 }
6060 Command :: Build ( opts) => {
61- let js = JS :: from_file ( & opts. input ) ?;
61+ let js = match opts. input . to_str ( ) {
62+ Some ( "-" ) => {
63+ let mut content = String :: new ( ) ;
64+ std:: io:: stdin ( ) . read_to_string ( & mut content) ?;
65+ JS :: from_string ( content)
66+ }
67+ _ => JS :: from_file ( & opts. input ) ?,
68+ } ;
6269 let codegen: CodegenOptionGroup = opts. codegen . clone ( ) . try_into ( ) ?;
6370 let mut builder = CodeGenBuilder :: new ( ) ;
6471 builder
@@ -74,8 +81,11 @@ fn main() -> Result<()> {
7481 } ;
7582
7683 let wasm = gen. generate ( & js) ?;
77-
78- fs:: write ( & opts. output , wasm) ?;
84+ if let Some ( path) = opts. output . as_ref ( ) {
85+ fs:: write ( path, wasm) ?;
86+ } else {
87+ std:: io:: stdout ( ) . write_all ( & wasm) ?;
88+ }
7989 Ok ( ( ) )
8090 }
8191 }
You can’t perform that action at this time.
0 commit comments