mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-20 20:55:50 +00:00
Implement build command, shuffle around some internals to make it easier
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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<Imfs> {
|
||||
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(),
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<Session> {
|
||||
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());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user