mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-25 15:16:07 +00:00
Add test model, shore up 'build' command more
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
use std::{
|
use std::{
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
fs::File,
|
fs::File,
|
||||||
|
io,
|
||||||
fmt,
|
fmt,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -19,9 +20,6 @@ pub enum OutputKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn detect_output_kind(options: &BuildOptions) -> Option<OutputKind> {
|
fn detect_output_kind(options: &BuildOptions) -> Option<OutputKind> {
|
||||||
match options.output_kind {
|
|
||||||
Some(output_kind) => Some(output_kind),
|
|
||||||
None => {
|
|
||||||
let extension = options.output_file.extension()?.to_str()?;
|
let extension = options.output_file.extension()?.to_str()?;
|
||||||
|
|
||||||
match extension {
|
match extension {
|
||||||
@@ -29,8 +27,6 @@ fn detect_output_kind(options: &BuildOptions) -> Option<OutputKind> {
|
|||||||
"rbxmx" => Some(OutputKind::Rbxmx),
|
"rbxmx" => Some(OutputKind::Rbxmx),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -43,6 +39,7 @@ pub struct BuildOptions {
|
|||||||
pub enum BuildError {
|
pub enum BuildError {
|
||||||
UnknownOutputKind,
|
UnknownOutputKind,
|
||||||
ProjectLoadError(ProjectLoadFuzzyError),
|
ProjectLoadError(ProjectLoadFuzzyError),
|
||||||
|
IoError(io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for BuildError {
|
impl fmt::Display for BuildError {
|
||||||
@@ -52,6 +49,7 @@ impl fmt::Display for BuildError {
|
|||||||
write!(output, "Could not detect what kind of output file to create")
|
write!(output, "Could not detect what kind of output file to create")
|
||||||
},
|
},
|
||||||
BuildError::ProjectLoadError(inner) => write!(output, "{}", inner),
|
BuildError::ProjectLoadError(inner) => write!(output, "{}", inner),
|
||||||
|
BuildError::IoError(inner) => write!(output, "{}", inner),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,8 +60,15 @@ impl From<ProjectLoadFuzzyError> for BuildError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<io::Error> for BuildError {
|
||||||
|
fn from(error: io::Error) -> BuildError {
|
||||||
|
BuildError::IoError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn build(options: &BuildOptions) -> Result<(), BuildError> {
|
pub fn build(options: &BuildOptions) -> Result<(), BuildError> {
|
||||||
let output_kind = detect_output_kind(options)
|
let output_kind = options.output_kind
|
||||||
|
.or_else(|| detect_output_kind(options))
|
||||||
.ok_or(BuildError::UnknownOutputKind)?;
|
.ok_or(BuildError::UnknownOutputKind)?;
|
||||||
|
|
||||||
info!("Hoping to generate file of type {:?}", output_kind);
|
info!("Hoping to generate file of type {:?}", output_kind);
|
||||||
@@ -75,20 +80,22 @@ pub fn build(options: &BuildOptions) -> Result<(), BuildError> {
|
|||||||
info!("Found project at {}", project.file_location.display());
|
info!("Found project at {}", project.file_location.display());
|
||||||
info!("Using project {:#?}", project);
|
info!("Using project {:#?}", project);
|
||||||
|
|
||||||
let imfs = Imfs::new(&project)
|
let imfs = Imfs::new(&project)?;
|
||||||
.expect("Could not create in-memory filesystem");
|
|
||||||
|
|
||||||
let tree = construct_oneoff_tree(&project, &imfs);
|
let tree = construct_oneoff_tree(&project, &imfs);
|
||||||
|
let mut file = File::create(&options.output_file)?;
|
||||||
let mut file = File::create(&options.output_file)
|
|
||||||
.expect("Could not open output file for write");
|
|
||||||
|
|
||||||
match output_kind {
|
match output_kind {
|
||||||
OutputKind::Rbxmx => {
|
OutputKind::Rbxmx => {
|
||||||
|
// Model files include the root instance of the tree and all its
|
||||||
|
// descendants.
|
||||||
|
|
||||||
let root_id = tree.get_root_id();
|
let root_id = tree.get_root_id();
|
||||||
rbxmx::encode(&tree, &[root_id], &mut file);
|
rbxmx::encode(&tree, &[root_id], &mut file);
|
||||||
},
|
},
|
||||||
OutputKind::Rbxlx => {
|
OutputKind::Rbxlx => {
|
||||||
|
// Place files don't contain an entry for the DataModel, but our
|
||||||
|
// RbxTree representation does.
|
||||||
|
|
||||||
let root_id = tree.get_root_id();
|
let root_id = tree.get_root_id();
|
||||||
let top_level_ids = tree.get_instance(root_id).unwrap().get_children_ids();
|
let top_level_ids = tree.get_instance(root_id).unwrap().get_children_ids();
|
||||||
rbxmx::encode(&tree, top_level_ids, &mut file);
|
rbxmx::encode(&tree, top_level_ids, &mut file);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "empty",
|
"name": "single-sync-point",
|
||||||
"tree": {
|
"tree": {
|
||||||
"$className": "DataModel",
|
"$className": "DataModel",
|
||||||
"ReplicatedStorage": {
|
"ReplicatedStorage": {
|
||||||
|
|||||||
9
test-projects/test-model/roblox-project.json
Normal file
9
test-projects/test-model/roblox-project.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"name": "empty",
|
||||||
|
"tree": {
|
||||||
|
"$className": "Folder",
|
||||||
|
"Library": {
|
||||||
|
"$path": "src"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
test-projects/test-model/src/main.lua
Normal file
3
test-projects/test-model/src/main.lua
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
local other = require(script.Parent.other)
|
||||||
|
|
||||||
|
print(other)
|
||||||
1
test-projects/test-model/src/other.lua
Normal file
1
test-projects/test-model/src/other.lua
Normal file
@@ -0,0 +1 @@
|
|||||||
|
return "Hello, world!"
|
||||||
Reference in New Issue
Block a user