forked from rojo-rbx/rojo
Prototype plugin architecture, switch instance-based stuff to that
This commit is contained in:
95
src/web.rs
95
src/web.rs
@@ -11,94 +11,12 @@ use regex::Regex;
|
||||
use core::Config;
|
||||
use project::Project;
|
||||
use vfs::{Vfs, VfsChange, VfsItem};
|
||||
use rbx::{RbxItem, RbxValue};
|
||||
use plugin::{Plugin, PluginResult};
|
||||
use plugins::DefaultPlugin;
|
||||
|
||||
static MAX_BODY_SIZE: usize = 25 * 1024 * 1025; // 25 MiB
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct RbxItem {
|
||||
name: String,
|
||||
class_name: String,
|
||||
children: Vec<RbxItem>,
|
||||
properties: HashMap<String, RbxValue>,
|
||||
}
|
||||
|
||||
impl RbxItem {
|
||||
pub fn from_vfs_item(file_name: &String, item: &VfsItem) -> RbxItem {
|
||||
lazy_static! {
|
||||
static ref PT_MODULE: Regex = Regex::new(r"^(.*?)\.lua$").unwrap();
|
||||
}
|
||||
|
||||
match item {
|
||||
&VfsItem::File { ref contents } => {
|
||||
let mut properties = HashMap::new();
|
||||
|
||||
properties.insert("Source".to_string(), RbxValue::String {
|
||||
value: contents.clone()
|
||||
});
|
||||
|
||||
let rbx_name = {
|
||||
if let Some(captures) = PT_MODULE.captures(file_name) {
|
||||
captures.get(1).unwrap().as_str().to_string()
|
||||
} else {
|
||||
file_name.clone()
|
||||
}
|
||||
};
|
||||
|
||||
RbxItem {
|
||||
name: rbx_name,
|
||||
class_name: "ModuleScript".to_string(),
|
||||
children: Vec::new(),
|
||||
properties,
|
||||
}
|
||||
},
|
||||
&VfsItem::Dir { ref children } => {
|
||||
let init = children.get(&"init.lua".to_string());
|
||||
|
||||
if let Some(init) = init {
|
||||
let mut rbx_children = Vec::new();
|
||||
|
||||
for (name, child_item) in children {
|
||||
if name != "init.lua" {
|
||||
rbx_children.push(RbxItem::from_vfs_item(&name, &child_item));
|
||||
}
|
||||
}
|
||||
|
||||
let init_rbx = RbxItem::from_vfs_item(&"init.lua".to_string(), &init);
|
||||
|
||||
RbxItem {
|
||||
name: file_name.clone(),
|
||||
class_name: init_rbx.class_name,
|
||||
children: rbx_children,
|
||||
properties: init_rbx.properties,
|
||||
}
|
||||
} else {
|
||||
let mut rbx_children = Vec::new();
|
||||
|
||||
for (name, child_item) in children {
|
||||
rbx_children.push(RbxItem::from_vfs_item(&name, &child_item));
|
||||
}
|
||||
|
||||
RbxItem {
|
||||
name: file_name.clone(),
|
||||
class_name: "Folder".to_string(),
|
||||
children: rbx_children,
|
||||
properties: HashMap::new(),
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase", tag = "type")]
|
||||
enum RbxValue {
|
||||
String {
|
||||
value: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct ServerInfo<'a> {
|
||||
@@ -243,7 +161,12 @@ pub fn start(config: Config, project: Project, vfs: Arc<Mutex<Vfs>>) {
|
||||
.iter()
|
||||
.map(|item| {
|
||||
match *item {
|
||||
Some(ref item) => Some(RbxItem::from_vfs_item(&"src".to_string(), item)),
|
||||
Some(ref item) => {
|
||||
match DefaultPlugin::transform(item) {
|
||||
PluginResult::Value(rbx_item) => rbx_item,
|
||||
_ => None,
|
||||
}
|
||||
},
|
||||
None => None,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user