@@ -7,8 +7,8 @@ use clap::builder::FalseyValueParser;
7
7
use clap:: { arg, crate_version, value_parser, ArgAction , Command } ;
8
8
use deno_core:: url:: Url ;
9
9
use sb_graph:: emitter:: EmitterFactory ;
10
- use sb_graph:: generate_binary_eszip;
11
10
use sb_graph:: import_map:: load_import_map;
11
+ use sb_graph:: { extract_from_file, generate_binary_eszip} ;
12
12
use std:: fs:: File ;
13
13
use std:: io:: Write ;
14
14
use std:: path:: PathBuf ;
@@ -58,7 +58,12 @@ fn cli() -> Command {
58
58
. arg ( arg ! ( --"output" <DIR > "Path to output eszip file" ) . default_value ( "bin.eszip" ) )
59
59
. arg ( arg ! ( --"entrypoint" <Path > "Path to entrypoint to bundle as an eszip" ) . required ( true ) )
60
60
. arg ( arg ! ( --"import-map" <Path > "Path to import map file" ) )
61
- )
61
+ ) . subcommand (
62
+ Command :: new ( "unbundle" )
63
+ . about ( "Unbundles an .eszip file into the specified directory" )
64
+ . arg ( arg ! ( --"output" <DIR > "Path to extract the ESZIP content" ) . default_value ( "./" ) )
65
+ . arg ( arg ! ( --"eszip" <DIR > "Path of eszip to extract" ) . required ( true ) )
66
+ )
62
67
}
63
68
64
69
//async fn exit_with_code(result: Result<(), Error>) {
@@ -167,6 +172,20 @@ fn main() -> Result<(), anyhow::Error> {
167
172
let mut file = File :: create ( output_path. as_str ( ) ) . unwrap ( ) ;
168
173
file. write_all ( & bin) . unwrap ( ) ;
169
174
}
175
+ Some ( ( "unbundle" , sub_matches) ) => {
176
+ let output_path = sub_matches. get_one :: < String > ( "output" ) . cloned ( ) . unwrap ( ) ;
177
+ let eszip_path = sub_matches. get_one :: < String > ( "eszip" ) . cloned ( ) . unwrap ( ) ;
178
+
179
+ let output_path = PathBuf :: from ( output_path. as_str ( ) ) ;
180
+ let eszip_path = PathBuf :: from ( eszip_path. as_str ( ) ) ;
181
+
182
+ extract_from_file ( eszip_path, output_path. clone ( ) ) . await ;
183
+
184
+ println ! (
185
+ "Eszip extracted successfully inside path {}" ,
186
+ output_path. to_str( ) . unwrap( )
187
+ ) ;
188
+ }
170
189
_ => {
171
190
// unrecognized command
172
191
}
0 commit comments