diff --git a/server/src/bin.rs b/server/src/bin.rs index 625b9d05..6db5da5e 100644 --- a/server/src/bin.rs +++ b/server/src/bin.rs @@ -1,10 +1,10 @@ -#[macro_use] extern crate clap; - use std::{ path::{Path, PathBuf}, env, }; +use clap::clap_app; + use librojo::commands; fn make_path_absolute(value: &Path) -> PathBuf { diff --git a/server/src/commands/build.rs b/server/src/commands/build.rs index 0c7d51eb..d3e81fa2 100644 --- a/server/src/commands/build.rs +++ b/server/src/commands/build.rs @@ -1,5 +1,15 @@ use std::{ path::PathBuf, + fs::File, + process, +}; + +use rbxmx; + +use crate::{ + rbx_session::construct_oneoff_tree, + project::Project, + imfs::Imfs, }; #[derive(Debug)] @@ -9,5 +19,27 @@ pub struct BuildOptions { } pub fn build(options: &BuildOptions) { - println!("build {:#?}", options); + info!("Looking for project at {}", options.fuzzy_project_path.display()); + + let project = match Project::load_fuzzy(&options.fuzzy_project_path) { + Ok(project) => project, + Err(error) => { + error!("{}", error); + process::exit(1); + }, + }; + + info!("Found project at {}", project.file_location.display()); + info!("Using project {:#?}", project); + + let imfs = Imfs::new(&project) + .expect("Could not create in-memory filesystem"); + + let tree = construct_oneoff_tree(&project, &imfs); + let root_id = tree.get_root_id(); + + let mut file = File::create(&options.output_file) + .expect("Could not open output file for write"); + + rbxmx::encode(&tree, &[root_id], &mut file); } \ No newline at end of file diff --git a/server/src/imfs.rs b/server/src/imfs.rs index 519faaaf..47ca782a 100644 --- a/server/src/imfs.rs +++ b/server/src/imfs.rs @@ -5,6 +5,23 @@ use std::{ io, }; +use crate::project::{Project, ProjectNode}; + +fn add_sync_points(imfs: &mut Imfs, project_node: &ProjectNode) -> io::Result<()> { + match project_node { + ProjectNode::Instance(node) => { + for child in node.children.values() { + add_sync_points(imfs, child)?; + } + }, + ProjectNode::SyncPoint(node) => { + imfs.add_root(&node.path)?; + }, + } + + Ok(()) +} + /// The in-memory filesystem keeps a mirror of all files being watcher by Rojo /// in order to deduplicate file changes in the case of bidirectional syncing /// from Roblox Studio. @@ -15,7 +32,15 @@ pub struct Imfs { } impl Imfs { - pub fn new() -> Imfs { + pub fn new(project: &Project) -> io::Result { + let mut imfs = Imfs::empty(); + + add_sync_points(&mut imfs, &project.tree)?; + + Ok(imfs) + } + + pub fn empty() -> Imfs { Imfs { items: HashMap::new(), roots: HashSet::new(), diff --git a/server/src/rbx_session.rs b/server/src/rbx_session.rs index 52f73c08..302f3926 100644 --- a/server/src/rbx_session.rs +++ b/server/src/rbx_session.rs @@ -157,6 +157,10 @@ impl RbxSession { } } +pub fn construct_oneoff_tree(project: &Project, imfs: &Imfs) -> RbxTree { + construct_initial_tree(project, imfs).0 +} + struct ConstructContext<'a> { tree: RbxTree, imfs: &'a Imfs, diff --git a/server/src/session.rs b/server/src/session.rs index ca237dee..90488124 100644 --- a/server/src/session.rs +++ b/server/src/session.rs @@ -5,7 +5,7 @@ use std::{ use crate::{ message_queue::MessageQueue, - project::{Project, ProjectNode}, + project::Project, imfs::Imfs, session_id::SessionId, rbx_session::RbxSession, @@ -20,29 +20,9 @@ pub struct Session { fs_watcher: FsWatcher, } -fn add_sync_points(imfs: &mut Imfs, project_node: &ProjectNode) -> io::Result<()> { - match project_node { - ProjectNode::Instance(node) => { - for child in node.children.values() { - add_sync_points(imfs, child)?; - } - }, - ProjectNode::SyncPoint(node) => { - imfs.add_root(&node.path)?; - }, - } - - Ok(()) -} - impl Session { pub fn new(project: Project) -> io::Result { - let mut imfs = Imfs::new(); - - add_sync_points(&mut imfs, &project.tree) - .expect("Could not add sync points when starting new Rojo session"); - - let imfs = Arc::new(Mutex::new(imfs)); + let imfs = Arc::new(Mutex::new(Imfs::new(&project)?)); let project = Arc::new(project); let message_queue = Arc::new(MessageQueue::new());