mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-20 20:55:50 +00:00
Add baseline support for adjacent meta files for scripts
This commit is contained in:
@@ -10,6 +10,7 @@ use crate::{
|
||||
|
||||
use super::{
|
||||
dir::SnapshotDir,
|
||||
meta_file::AdjacentMetadata,
|
||||
middleware::{SnapshotFileResult, SnapshotInstanceResult, SnapshotMiddleware},
|
||||
};
|
||||
|
||||
@@ -79,6 +80,7 @@ fn snapshot_lua_file<F: ImfsFetcher>(
|
||||
|
||||
let contents = entry.contents(imfs)?;
|
||||
let contents_str = str::from_utf8(contents)
|
||||
// TODO: Turn into error type
|
||||
.expect("File content was not valid UTF-8")
|
||||
.to_string();
|
||||
|
||||
@@ -88,13 +90,30 @@ fn snapshot_lua_file<F: ImfsFetcher>(
|
||||
},
|
||||
};
|
||||
|
||||
let meta_path = entry
|
||||
.path()
|
||||
.with_file_name(format!("{}.meta.json", instance_name));
|
||||
|
||||
let mut metadata = InstanceMetadata {
|
||||
instigating_source: Some(entry.path().to_path_buf().into()),
|
||||
relevant_paths: vec![entry.path().to_path_buf()],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
if let Some(meta_entry) = imfs.get(meta_path).with_not_found()? {
|
||||
let meta_contents = meta_entry.contents(imfs)?;
|
||||
let parsed: AdjacentMetadata = serde_json::from_slice(meta_contents)
|
||||
// TODO: Turn into error type
|
||||
.expect(".meta.json file was malformed");
|
||||
|
||||
if let Some(ignore) = parsed.ignore_unknown_instances {
|
||||
metadata.ignore_unknown_instances = ignore;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Some(InstanceSnapshot {
|
||||
snapshot_id: None,
|
||||
metadata: InstanceMetadata {
|
||||
instigating_source: Some(entry.path().to_path_buf().into()),
|
||||
relevant_paths: vec![entry.path().to_path_buf()],
|
||||
..Default::default()
|
||||
},
|
||||
metadata,
|
||||
name: Cow::Owned(instance_name.to_owned()),
|
||||
class_name: Cow::Borrowed(class_name),
|
||||
properties,
|
||||
@@ -185,4 +204,46 @@ mod test {
|
||||
|
||||
assert_yaml_snapshot!(instance_snapshot);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn module_with_meta() {
|
||||
let mut imfs = Imfs::new(NoopFetcher);
|
||||
let file = ImfsSnapshot::file("Hello there!");
|
||||
let meta = ImfsSnapshot::file(
|
||||
r#"
|
||||
{
|
||||
"ignoreUnknownInstances": true
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
||||
imfs.debug_load_snapshot("/foo.lua", file);
|
||||
imfs.debug_load_snapshot("/foo.meta.json", meta);
|
||||
|
||||
let entry = imfs.get("/foo.lua").unwrap();
|
||||
let instance_snapshot = SnapshotLua::from_imfs(&mut imfs, &entry).unwrap().unwrap();
|
||||
|
||||
assert_yaml_snapshot!(instance_snapshot);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_with_meta() {
|
||||
let mut imfs = Imfs::new(NoopFetcher);
|
||||
let file = ImfsSnapshot::file("Hello there!");
|
||||
let meta = ImfsSnapshot::file(
|
||||
r#"
|
||||
{
|
||||
"ignoreUnknownInstances": true
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
||||
imfs.debug_load_snapshot("/foo.server.lua", file);
|
||||
imfs.debug_load_snapshot("/foo.meta.json", meta);
|
||||
|
||||
let entry = imfs.get("/foo.server.lua").unwrap();
|
||||
let instance_snapshot = SnapshotLua::from_imfs(&mut imfs, &entry).unwrap().unwrap();
|
||||
|
||||
assert_yaml_snapshot!(instance_snapshot);
|
||||
}
|
||||
}
|
||||
|
||||
15
src/snapshot_middleware/meta_file.rs
Normal file
15
src/snapshot_middleware/meta_file.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AdjacentMetadata {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub ignore_unknown_instances: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct InitMetadata {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub ignore_unknown_instances: Option<bool>,
|
||||
}
|
||||
@@ -9,6 +9,7 @@ mod dir;
|
||||
mod error;
|
||||
mod json_model;
|
||||
mod lua;
|
||||
mod meta_file;
|
||||
mod middleware;
|
||||
mod project;
|
||||
mod rbxlx;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
source: src/snapshot_middleware/lua.rs
|
||||
expression: instance_snapshot
|
||||
---
|
||||
snapshot_id: ~
|
||||
metadata:
|
||||
ignore_unknown_instances: true
|
||||
instigating_source:
|
||||
Path: /foo.lua
|
||||
relevant_paths:
|
||||
- /foo.lua
|
||||
name: foo
|
||||
class_name: ModuleScript
|
||||
properties:
|
||||
Source:
|
||||
Type: String
|
||||
Value: Hello there!
|
||||
children: []
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
source: src/snapshot_middleware/lua.rs
|
||||
expression: instance_snapshot
|
||||
---
|
||||
snapshot_id: ~
|
||||
metadata:
|
||||
ignore_unknown_instances: true
|
||||
instigating_source:
|
||||
Path: /foo.server.lua
|
||||
relevant_paths:
|
||||
- /foo.server.lua
|
||||
name: foo
|
||||
class_name: Script
|
||||
properties:
|
||||
Source:
|
||||
Type: String
|
||||
Value: Hello there!
|
||||
children: []
|
||||
Reference in New Issue
Block a user