@@ -4,27 +4,28 @@ use perseus_cli::parse::SnoopSubcommand;
4
4
use perseus_cli:: {
5
5
build, check_env, delete_artifacts, delete_bad_dir, deploy, eject, export, has_ejected,
6
6
parse:: { Opts , Subcommand } ,
7
- prepare, serve, tinker,
7
+ prepare, serve, serve_exported , tinker,
8
8
} ;
9
9
use perseus_cli:: { errors:: * , snoop_build, snoop_server, snoop_wasm_build} ;
10
10
use std:: env;
11
11
use std:: io:: Write ;
12
12
use std:: path:: PathBuf ;
13
13
14
14
// All this does is run the program and terminate with the acquired exit code
15
- fn main ( ) {
15
+ #[ tokio:: main]
16
+ async fn main ( ) {
16
17
// In development, we'll test in the `basic` example
17
18
if cfg ! ( debug_assertions) {
18
19
let example_to_test =
19
20
env:: var ( "TEST_EXAMPLE" ) . unwrap_or_else ( |_| "../../examples/basic" . to_string ( ) ) ;
20
21
env:: set_current_dir ( example_to_test) . unwrap ( ) ;
21
22
}
22
- let exit_code = real_main ( ) ;
23
+ let exit_code = real_main ( ) . await ;
23
24
std:: process:: exit ( exit_code)
24
25
}
25
26
26
27
// This manages error handling and returns a definite exit code to terminate with
27
- fn real_main ( ) -> i32 {
28
+ async fn real_main ( ) -> i32 {
28
29
// Get the working directory
29
30
let dir = env:: current_dir ( ) ;
30
31
let dir = match dir {
@@ -37,7 +38,7 @@ fn real_main() -> i32 {
37
38
return 1 ;
38
39
}
39
40
} ;
40
- let res = core ( dir. clone ( ) ) ;
41
+ let res = core ( dir. clone ( ) ) . await ;
41
42
match res {
42
43
// If it worked, we pass the executed command's exit code through
43
44
Ok ( exit_code) => exit_code,
@@ -60,7 +61,7 @@ fn real_main() -> i32 {
60
61
// This returns the exit code of the executed command, which we should return from the process itself
61
62
// This prints warnings using the `writeln!` macro, which allows the parsing of `stdout` in production or a vector in testing
62
63
// If at any point a warning can't be printed, the program will panic
63
- fn core ( dir : PathBuf ) -> Result < i32 , Error > {
64
+ async fn core ( dir : PathBuf ) -> Result < i32 , Error > {
64
65
// Get `stdout` so we can write warnings appropriately
65
66
let stdout = & mut std:: io:: stdout ( ) ;
66
67
@@ -88,7 +89,16 @@ fn core(dir: PathBuf) -> Result<i32, Error> {
88
89
// Delete old build/exportation artifacts
89
90
delete_artifacts ( dir. clone ( ) , "static" ) ?;
90
91
delete_artifacts ( dir. clone ( ) , "exported" ) ?;
91
- export ( dir, export_opts) ?
92
+ let exit_code = export ( dir. clone ( ) , export_opts. clone ( ) ) ?;
93
+ if exit_code != 0 {
94
+ return Ok ( exit_code) ;
95
+ }
96
+ // Start a server for those files if requested
97
+ if export_opts. serve {
98
+ serve_exported ( dir, export_opts. host , export_opts. port ) . await ;
99
+ }
100
+
101
+ 0
92
102
}
93
103
Subcommand :: Serve ( serve_opts) => {
94
104
// Delete old build artifacts if `--no-build` wasn't specified
0 commit comments