pub fn serve(dir: PathBuf, opts: ServeOpts) -> Result<(i32, Option<String>), ExecutionError> {
    // Set the environment variables for the host and port
    env::set_var("PERSEUS_HOST", opts.host);
    env::set_var("PERSEUS_PORT", opts.port.to_string());

    let spinners = MultiProgress::new();
    let did_build = !opts.no_build;
    let should_run = !opts.no_run;
    // We need to have a way of knowing what the executable path to the server is
    let exec = Arc::new(Mutex::new(String::new()));
    // We can begin building the server in a thread without having to deal with the rest of the build stage yet
    let sb_thread = build_server(
        dir.clone(),
        &spinners,
        did_build,
        Arc::clone(&exec),
        opts.release,
        opts.standalone,
        opts.integration,
    )?;
    // Only build if the user hasn't set `--no-build`, handling non-zero exit codes
    if did_build {
        let (sg_thread, wb_thread) = build_internal(dir.clone(), &spinners, 4, opts.release)?;
        let sg_res = sg_thread
            .join()
            .map_err(|_| ExecutionError::ThreadWaitFailed)??;
        let wb_res = wb_thread
            .join()
            .map_err(|_| ExecutionError::ThreadWaitFailed)??;
        if sg_res != 0 {
            return Ok((sg_res, None));
        } else if wb_res != 0 {
            return Ok((wb_res, None));
        }
    }
    // Handle errors from the server building
    let sb_res = sb_thread
        .join()
        .map_err(|_| ExecutionError::ThreadWaitFailed)??;
    if sb_res != 0 {
        return Ok((sb_res, None));
    }

    // And now we can run the finalization stage (only if `--no-build` wasn't specified)
    if did_build {
        finalize(&dir.join(".perseus"))?;
    }

    // Now actually run that executable path if we should
    if should_run {
        let exit_code = run_server(Arc::clone(&exec), dir, did_build)?;
        Ok((exit_code, None))
    } else {
        // The user doesn't want to run the server, so we'll give them the executable path instead
        let exec_str = (*exec.lock().unwrap()).to_string();
        println!("Not running server because `--no-run` was provided. You can run it manually by running the following executable in `.perseus/server/`.\n{}", &exec_str);
        Ok((0, Some(exec_str)))
    }
}
/// Builds the subcrates to get a directory that we can serve and then serves it. If possible, this will return the path to the server
/// executable so that it can be used in deployment.
Builds the subcrates to get a directory that we can serve and then serves it. If possible, this will return the path to the server
executable so that it can be used in deployment.
Builds the subcrates to get a directory that we can serve and then serves it . If possible this will return the path to the server executable so that it can be used in deployment .
pub fn serve(dir: PathBuf, opts: ServeOpts) -> Result<(i32, Option<String>), ExecutionError> {
    // Set the environment variables for the host and port
    env::set_var("PERSEUS_HOST", opts.host);
    env::set_var("PERSEUS_PORT", opts.port.to_string());
    let spinners = MultiProgress::new();
    let did_build = !opts.no_build;
    let should_run = !opts.no_run;
    // We need to have a way of knowing what the executable path to the server is
    let exec = Arc::new(Mutex::new(String::new()));
    // We can begin building the server in a thread without having to deal with the rest of the build stage yet
    let sb_thread = build_server(
        dir.clone(),
        &spinners,
        did_build,
        Arc::clone(&exec),
        opts.release,
        opts.standalone,
        opts.integration,
    )?;
    // Only build if the user hasn't set `--no-build`, handling non-zero exit codes
    if did_build {
        let (sg_thread, wb_thread) = build_internal(dir.clone(), &spinners, 4, opts.release)?;
        let sg_res = sg_thread
            .join()
            .map_err(|_| ExecutionError::ThreadWaitFailed)??;
        let wb_res = wb_thread
            .join()
            .map_err(|_| ExecutionError::ThreadWaitFailed)??;
        if sg_res != 0 {
            return Ok((sg_res, None));
        } else if wb_res != 0 {
            return Ok((wb_res, None));
        }
    }
    // Handle errors from the server building
    let sb_res = sb_thread
        .join()
        .map_err(|_| ExecutionError::ThreadWaitFailed)??;
    if sb_res != 0 {
        return Ok((sb_res, None));
    }
    // And now we can run the finalization stage (only if `--no-build` wasn't specified)
    if did_build {
        finalize(&dir.join(".perseus"))?;
    }
    // Now actually run that executable path if we should
    if should_run {
        let exit_code = run_server(Arc::clone(&exec), dir, did_build)?;
        Ok((exit_code, None))
    } else {
        // The user doesn't want to run the server, so we'll give them the executable path instead
        let exec_str = (*exec.lock().unwrap()).to_string();
        println!("Not running server because `--no-run` was provided. You can run it manually by running the following executable in `.perseus/server/`.\n{}", &exec_str);
        Ok((0, Some(exec_str)))
    }
}
pub fn serve ( dir : PathBuf , opts : ServeOpts ) -> Result < ( i32 , Option < String > ) , ExecutionError > { // Set the environment variables for the host and port env :: set_var ( " " , opts . host ) ; env :: set_var ( " " , opts . port . to_string ( ) ) ; let spinners = MultiProgress :: new ( ) ; let did_build = ! opts . no_build ; let should_run = ! opts . no_run ; // We need to have a way of knowing what the executable path to the server is let exec = Arc :: new ( Mutex :: new ( String :: new ( ) ) ) ; // We can begin building the server in a thread without having to deal with the rest of the build stage yet let sb_thread = build_server ( dir . clone ( ) , & spinners , did_build , Arc :: clone ( & exec ) , opts . release , opts . standalone , opts . integration , ) ? ; // Only build if the user hasn't set `--no-build`, handling non-zero exit codes if did_build { let ( sg_thread , wb_thread ) = build_internal ( dir . clone ( ) , & spinners , 4 , opts . release ) ? ; let sg_res = sg_thread . join ( ) . map_err ( | _ | ExecutionError :: ThreadWaitFailed ) ? ? ; let wb_res = wb_thread . join ( ) . map_err ( | _ | ExecutionError :: ThreadWaitFailed ) ? ? ; if sg_res != 0 { return Ok ( ( sg_res , None ) ) ; } else if wb_res != 0 { return Ok ( ( wb_res , None ) ) ; } } // Handle errors from the server building let sb_res = sb_thread . join ( ) . map_err ( | _ | ExecutionError :: ThreadWaitFailed ) ? ? ; if sb_res != 0 { return Ok ( ( sb_res , None ) ) ; } // And now we can run the finalization stage (only if `--no-build` wasn't specified) if did_build { finalize ( & dir . join ( " " ) ) ? ; } // Now actually run that executable path if we should if should_run { let exit_code = run_server ( Arc :: clone ( & exec ) , dir , did_build ) ? ; Ok ( ( exit_code , None ) ) } else { // The user doesn't want to run the server, so we'll give them the executable path instead let exec_str = ( * exec . lock ( ) . unwrap ( ) ) . to_string ( ) ; println ! ( " \n " exec_str ) ; Ok ( ( 0 , Some ( exec_str ) ) ) } }
Builds the subcrates to get a directory that we can serve and then serves it.
Builds the subcrates to get a directory that we can serve and then serves it .
dir
PathBuf
opts
ServeOpts
dir
PathBuf
opts
ServeOpts