From ce5ea9207637facf23e9428cf98033b9b5739e8f Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Wed, 9 Jan 2019 21:27:10 -0800 Subject: [PATCH] Add maplit, flesh out 'init' place command --- Cargo.lock | 7 +++++ server/Cargo.toml | 1 + server/src/project.rs | 60 +++++++++++++++++++------------------------ 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 56d24a69..1a37b901 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -704,6 +704,11 @@ dependencies = [ "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "maplit" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "matches" version = "0.1.8" @@ -1287,6 +1292,7 @@ dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "notify 4.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "rbx_binary 0.1.0 (git+https://github.com/LPGhatguy/rbx-tree.git)", @@ -2125,6 +2131,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum lru-cache 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4d06ff7ff06f729ce5f4e227876cb88d10bc59cd4ae1e09fbb2bde15c850dc21" "checksum lz4 1.23.1 (registry+https://github.com/rust-lang/crates.io-index)" = "43c94a9f09a60017f373020cc93d4291db4cd92b0db64ff25927f27d09dc23d5" "checksum lz4-sys 1.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "20ab022822e9331c58d373acdd6b98085bace058ac6837b8266f213a2fccdafe" +"checksum maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08cbb6b4fef96b6d77bfc40ec491b1690c779e77b05cd9f07f787ed376fd4c43" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" "checksum memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a" "checksum memchr 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "db4c41318937f6e76648f42826b1d9ade5c09cafb5aef7e351240a70f39206e9" diff --git a/server/Cargo.toml b/server/Cargo.toml index 88bdf38e..ba818366 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -25,6 +25,7 @@ csv = "1.0" env_logger = "0.5" failure = "0.1.3" log = "0.4" +maplit = "1.0.1" notify = "4.0" rand = "0.4" regex = "1.0" diff --git a/server/src/project.rs b/server/src/project.rs index 10f91118..5647625c 100644 --- a/server/src/project.rs +++ b/server/src/project.rs @@ -6,6 +6,7 @@ use std::{ path::{Path, PathBuf}, }; +use maplit::hashmap; use failure::Fail; use rbx_tree::RbxValue; @@ -238,51 +239,42 @@ pub struct Project { impl Project { pub fn init_place(project_fuzzy_path: &Path) -> Result { - let is_exact = project_fuzzy_path.extension().is_some(); - - let project_name = if is_exact { + let project_path = Project::init_pick_path(project_fuzzy_path)?; + let project_folder_path = project_path.parent().unwrap(); + let project_name = if project_fuzzy_path == project_path { project_fuzzy_path.parent().unwrap().file_name().unwrap().to_str().unwrap() } else { project_fuzzy_path.file_name().unwrap().to_str().unwrap() }; - // TODO: Add children for src folder, potentially client, server, and - // common? - - let mut http_service_properties = HashMap::new(); - http_service_properties.insert("HttpEnabled".to_string(), RbxValue::Bool { - value: true, - }); - - let http_service = ProjectNode::Instance(InstanceProjectNode { - class_name: "HttpService".to_string(), - children: HashMap::new(), - properties: http_service_properties, - metadata: Default::default(), - }); - - let replicated_storage_children = HashMap::new(); - - let replicated_storage = ProjectNode::Instance(InstanceProjectNode { - class_name: "ReplicatedStorage".to_string(), - children: replicated_storage_children, - properties: HashMap::new(), - metadata: Default::default(), - }); - - let mut root_children = HashMap::new(); - root_children.insert("ReplicatedStorage".to_string(), replicated_storage); - root_children.insert("HttpService".to_string(), http_service); - let tree = ProjectNode::Instance(InstanceProjectNode { class_name: "DataModel".to_string(), - children: root_children, + children: hashmap! { + String::from("ReplicatedStorage") => ProjectNode::Instance(InstanceProjectNode { + class_name: String::from("ReplicatedStorage"), + children: hashmap! { + String::from("Source") => ProjectNode::SyncPoint(SyncPointProjectNode { + path: project_folder_path.join("src"), + }), + }, + properties: HashMap::new(), + metadata: Default::default(), + }), + String::from("HttpService") => ProjectNode::Instance(InstanceProjectNode { + class_name: String::from("HttpService"), + children: HashMap::new(), + properties: hashmap! { + String::from("HttpEnabled") => RbxValue::Bool { + value: true, + }, + }, + metadata: Default::default(), + }), + }, properties: HashMap::new(), metadata: Default::default(), }); - let project_path = Project::init_pick_path(project_fuzzy_path)?; - let project = Project { name: project_name.to_string(), tree,