mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-21 12:01:38 +00:00
Port commands to use common setup code
Initialization logic needed for serve, build, and upload is now much more clear than it was when these functions were written. This commit refactors all of them to use a new common_setup module for all of their initialization that's the same.
This commit is contained in:
parent
83665018d4
commit
24c697bea7
6 changed files with 98 additions and 147 deletions
|
|
@ -9,7 +9,7 @@ use termcolor::{BufferWriter, Color, ColorChoice, ColorSpec, WriteColor};
|
|||
|
||||
use crate::{
|
||||
imfs::{Imfs, RealFetcher, WatchMode},
|
||||
project::{Project, ProjectLoadError},
|
||||
project::ProjectLoadError,
|
||||
serve_session::ServeSession,
|
||||
web::LiveServer,
|
||||
};
|
||||
|
|
@ -33,33 +33,18 @@ impl_from!(ServeError {
|
|||
});
|
||||
|
||||
pub fn serve(options: &ServeOptions) -> Result<(), ServeError> {
|
||||
let maybe_project = match Project::load_fuzzy(&options.fuzzy_project_path) {
|
||||
Ok(project) => Some(project),
|
||||
Err(ProjectLoadError::NotFound) => None,
|
||||
Err(other) => return Err(other.into()),
|
||||
};
|
||||
let imfs = Imfs::new(RealFetcher::new(WatchMode::Enabled));
|
||||
|
||||
let session = Arc::new(ServeSession::new(imfs, &options.fuzzy_project_path));
|
||||
|
||||
let port = options
|
||||
.port
|
||||
.or_else(|| {
|
||||
maybe_project
|
||||
.as_ref()
|
||||
.and_then(|project| project.serve_port)
|
||||
})
|
||||
.or_else(|| session.project_port())
|
||||
.unwrap_or(DEFAULT_PORT);
|
||||
|
||||
let _ = show_start_message(port);
|
||||
|
||||
let imfs = Imfs::new(RealFetcher::new(WatchMode::Enabled));
|
||||
|
||||
let session = Arc::new(ServeSession::new(
|
||||
imfs,
|
||||
&options.fuzzy_project_path,
|
||||
maybe_project,
|
||||
));
|
||||
|
||||
let server = LiveServer::new(session);
|
||||
|
||||
let _ = show_start_message(port);
|
||||
server.start(port);
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue