mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-23 06:05:24 +00:00
First implementation of 'ScriptPlugin', which serves script files as scripts
This commit is contained in:
@@ -4,6 +4,9 @@ use plugin::{Plugin, PluginChain, PluginResult};
|
|||||||
use rbx::{RbxItem, RbxValue};
|
use rbx::{RbxItem, RbxValue};
|
||||||
use vfs::VfsItem;
|
use vfs::VfsItem;
|
||||||
|
|
||||||
|
/// A plugin with simple transforms:
|
||||||
|
/// * Directories become Folder instances
|
||||||
|
/// * Files become StringValue objects with 'Value' as their contents
|
||||||
pub struct DefaultPlugin;
|
pub struct DefaultPlugin;
|
||||||
|
|
||||||
impl DefaultPlugin {
|
impl DefaultPlugin {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
mod default_plugin;
|
mod default_plugin;
|
||||||
|
mod script_plugin;
|
||||||
|
|
||||||
pub use self::default_plugin::*;
|
pub use self::default_plugin::*;
|
||||||
|
pub use self::script_plugin::*;
|
||||||
|
|||||||
57
src/plugins/script_plugin.rs
Normal file
57
src/plugins/script_plugin.rs
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
|
use plugin::{Plugin, PluginChain, PluginResult};
|
||||||
|
use rbx::{RbxItem, RbxValue};
|
||||||
|
use vfs::VfsItem;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref SERVER_PATTERN: Regex = Regex::new(r"^(.*?)\.server\.lua$").unwrap();
|
||||||
|
static ref CLIENT_PATTERN: Regex = Regex::new(r"^(.*?)\.client\.lua$").unwrap();
|
||||||
|
static ref MODULE_PATTERN: Regex = Regex::new(r"^(.*?)\.lua$").unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ScriptPlugin;
|
||||||
|
|
||||||
|
impl ScriptPlugin {
|
||||||
|
pub fn new() -> ScriptPlugin {
|
||||||
|
ScriptPlugin
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Plugin for ScriptPlugin {
|
||||||
|
fn transform_file(&self, plugins: &PluginChain, vfs_item: &VfsItem) -> PluginResult {
|
||||||
|
match vfs_item {
|
||||||
|
&VfsItem::File { ref contents, ref name } => {
|
||||||
|
let (class_name, rbx_name) = {
|
||||||
|
if let Some(captures) = SERVER_PATTERN.captures(name) {
|
||||||
|
("Script".to_string(), captures.get(1).unwrap().as_str().to_string())
|
||||||
|
} else if let Some(captures) = CLIENT_PATTERN.captures(name) {
|
||||||
|
("LocalScript".to_string(), captures.get(1).unwrap().as_str().to_string())
|
||||||
|
} else if let Some(captures) = MODULE_PATTERN.captures(name) {
|
||||||
|
("ModuleScript".to_string(), captures.get(1).unwrap().as_str().to_string())
|
||||||
|
} else {
|
||||||
|
return PluginResult::Pass;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut properties = HashMap::new();
|
||||||
|
|
||||||
|
properties.insert("Source".to_string(), RbxValue::String {
|
||||||
|
value: contents.clone(),
|
||||||
|
});
|
||||||
|
|
||||||
|
PluginResult::Value(Some(RbxItem {
|
||||||
|
name: rbx_name,
|
||||||
|
class_name: class_name,
|
||||||
|
children: Vec::new(),
|
||||||
|
properties,
|
||||||
|
}))
|
||||||
|
},
|
||||||
|
&VfsItem::Dir { ref children, ref name } => {
|
||||||
|
PluginResult::Pass
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@ use project::Project;
|
|||||||
use vfs::{Vfs, VfsChange};
|
use vfs::{Vfs, VfsChange};
|
||||||
use rbx::RbxItem;
|
use rbx::RbxItem;
|
||||||
use plugin::PluginChain;
|
use plugin::PluginChain;
|
||||||
use plugins::DefaultPlugin;
|
use plugins::{ScriptPlugin, DefaultPlugin};
|
||||||
|
|
||||||
static MAX_BODY_SIZE: usize = 25 * 1024 * 1025; // 25 MiB
|
static MAX_BODY_SIZE: usize = 25 * 1024 * 1025; // 25 MiB
|
||||||
|
|
||||||
@@ -104,6 +104,7 @@ pub fn start(config: Config, project: Project, vfs: Arc<Mutex<Vfs>>) {
|
|||||||
// Fine, rouille, I'll put things in a 'static Arc<Mutex>...
|
// Fine, rouille, I'll put things in a 'static Arc<Mutex>...
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref PLUGIN_CHAIN: Arc<Mutex<PluginChain>> = Arc::new(Mutex::new(PluginChain::new(vec![
|
static ref PLUGIN_CHAIN: Arc<Mutex<PluginChain>> = Arc::new(Mutex::new(PluginChain::new(vec![
|
||||||
|
Box::new(ScriptPlugin::new()),
|
||||||
Box::new(DefaultPlugin::new()),
|
Box::new(DefaultPlugin::new()),
|
||||||
])));
|
])));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user