rojo/src/cli/serve.rs
Joe 50b9e18514 Refactor and rebrand Rojo to Atlas
- Renamed the project from Rojo to Atlas, updating all relevant files, scripts, and documentation to reflect the new branding.
- Bumped version to 7.7.0-rc.2 and updated protocol version from 5 to 6.
- Modified installation scripts and CI workflows to use the new binary name and paths.
- Adjusted plugin settings and internal identifiers to prevent conflicts with the original Rojo.
- Enhanced session management and API response handling to support the new server fork identifier.
- Updated project templates and README files to guide users on using Atlas.
2026-02-07 13:21:52 -06:00

64 lines
1.6 KiB
Rust

use std::{
net::{IpAddr, Ipv4Addr},
path::PathBuf,
sync::Arc,
};
use clap::Parser;
use memofs::Vfs;
use crate::{serve_session::ServeSession, web::LiveServer};
use super::resolve_path;
const DEFAULT_BIND_ADDRESS: Ipv4Addr = Ipv4Addr::new(127, 0, 0, 1);
const DEFAULT_PORT: u16 = 34873;
/// Expose a Rojo project to the Rojo Studio plugin.
#[derive(Debug, Parser)]
pub struct ServeCommand {
/// Path to the project to serve. Defaults to `default.project.json5`.
#[clap(default_value = "default.project.json5")]
pub project: PathBuf,
/// The IP address to listen on. Defaults to `127.0.0.1`.
#[clap(long)]
pub address: Option<IpAddr>,
/// The port to listen on. Defaults to the project's preference, or `34873` if
/// it has none.
#[clap(long)]
pub port: Option<u16>,
}
impl ServeCommand {
pub fn run(self) -> anyhow::Result<()> {
let project_path = resolve_path(&self.project);
let vfs = Vfs::new_default();
let session = Arc::new(ServeSession::new(vfs, project_path)?);
let ip = self
.address
.or_else(|| session.serve_address())
.unwrap_or(DEFAULT_BIND_ADDRESS.into());
let port = self
.port
.or_else(|| session.project_port())
.unwrap_or(DEFAULT_PORT);
let server = LiveServer::new(session);
let host = if ip.is_loopback() {
"localhost".to_owned()
} else {
ip.to_string()
};
log::info!("Listening: http://{}:{}", host, port);
server.start((ip, port).into());
Ok(())
}
}