forked from rojo-rbx/rojo
@@ -0,0 +1,19 @@
|
|||||||
|
---
|
||||||
|
source: tests/tests/build.rs
|
||||||
|
assertion_line: 100
|
||||||
|
expression: contents
|
||||||
|
---
|
||||||
|
<roblox version="4">
|
||||||
|
<Item class="LocalizationTable" referent="0">
|
||||||
|
<Properties>
|
||||||
|
<string name="Name">init_csv_with_children</string>
|
||||||
|
<string name="Contents">[{"key":"init.csv","values":{}}]</string>
|
||||||
|
</Properties>
|
||||||
|
<Item class="LocalizationTable" referent="1">
|
||||||
|
<Properties>
|
||||||
|
<string name="Name">other</string>
|
||||||
|
<string name="Contents">[{"key":"other.csv","values":{}}]</string>
|
||||||
|
</Properties>
|
||||||
|
</Item>
|
||||||
|
</Item>
|
||||||
|
</roblox>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "init_csv_with_children",
|
||||||
|
"tree": {
|
||||||
|
"$path": "src"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
Key
|
||||||
|
init.csv
|
||||||
|
@@ -0,0 +1,2 @@
|
|||||||
|
Key
|
||||||
|
other.csv
|
||||||
|
@@ -7,7 +7,11 @@ use serde::Serialize;
|
|||||||
|
|
||||||
use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot};
|
use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot};
|
||||||
|
|
||||||
use super::{meta_file::AdjacentMetadata, util::PathExt};
|
use super::{
|
||||||
|
dir::{dir_meta, snapshot_dir_no_meta},
|
||||||
|
meta_file::AdjacentMetadata,
|
||||||
|
util::PathExt,
|
||||||
|
};
|
||||||
|
|
||||||
pub fn snapshot_csv(
|
pub fn snapshot_csv(
|
||||||
_context: &InstanceContext,
|
_context: &InstanceContext,
|
||||||
@@ -46,6 +50,43 @@ pub fn snapshot_csv(
|
|||||||
Ok(Some(snapshot))
|
Ok(Some(snapshot))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Attempts to snapshot an 'init' csv contained inside of a folder with
|
||||||
|
/// the given name.
|
||||||
|
///
|
||||||
|
/// csv named `init.csv`
|
||||||
|
/// their parents, which acts similarly to `__init__.py` from the Python world.
|
||||||
|
pub fn snapshot_csv_init(
|
||||||
|
context: &InstanceContext,
|
||||||
|
vfs: &Vfs,
|
||||||
|
init_path: &Path,
|
||||||
|
) -> anyhow::Result<Option<InstanceSnapshot>> {
|
||||||
|
let folder_path = init_path.parent().unwrap();
|
||||||
|
let dir_snapshot = snapshot_dir_no_meta(context, vfs, folder_path)?.unwrap();
|
||||||
|
|
||||||
|
if dir_snapshot.class_name != "Folder" {
|
||||||
|
anyhow::bail!(
|
||||||
|
"init.csv can only be used if the instance produced by \
|
||||||
|
the containing directory would be a Folder.\n\
|
||||||
|
\n\
|
||||||
|
The directory {} turned into an instance of class {}.",
|
||||||
|
folder_path.display(),
|
||||||
|
dir_snapshot.class_name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut init_snapshot = snapshot_csv(context, vfs, init_path)?.unwrap();
|
||||||
|
|
||||||
|
init_snapshot.name = dir_snapshot.name;
|
||||||
|
init_snapshot.children = dir_snapshot.children;
|
||||||
|
init_snapshot.metadata = dir_snapshot.metadata;
|
||||||
|
|
||||||
|
if let Some(mut meta) = dir_meta(vfs, folder_path)? {
|
||||||
|
meta.apply_all(&mut init_snapshot)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Some(init_snapshot))
|
||||||
|
}
|
||||||
|
|
||||||
/// Struct that holds any valid row from a Roblox CSV translation table.
|
/// Struct that holds any valid row from a Roblox CSV translation table.
|
||||||
///
|
///
|
||||||
/// We manually deserialize into this table from CSV, but let serde_json handle
|
/// We manually deserialize into this table from CSV, but let serde_json handle
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ use memofs::{IoResultExt, Vfs};
|
|||||||
use crate::snapshot::{InstanceContext, InstanceSnapshot};
|
use crate::snapshot::{InstanceContext, InstanceSnapshot};
|
||||||
|
|
||||||
use self::{
|
use self::{
|
||||||
csv::snapshot_csv,
|
csv::{snapshot_csv, snapshot_csv_init},
|
||||||
dir::snapshot_dir,
|
dir::snapshot_dir,
|
||||||
json::snapshot_json,
|
json::snapshot_json,
|
||||||
json_model::snapshot_json_model,
|
json_model::snapshot_json_model,
|
||||||
@@ -87,12 +87,19 @@ pub fn snapshot_from_vfs(
|
|||||||
return snapshot_lua_init(context, vfs, &init_path);
|
return snapshot_lua_init(context, vfs, &init_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let init_path = path.join("init.csv");
|
||||||
|
if vfs.metadata(&init_path).with_not_found()?.is_some() {
|
||||||
|
return snapshot_csv_init(context, vfs, &init_path);
|
||||||
|
}
|
||||||
|
|
||||||
snapshot_dir(context, vfs, path)
|
snapshot_dir(context, vfs, path)
|
||||||
} else {
|
} else {
|
||||||
let script_name = path
|
let script_name = path
|
||||||
.file_name_trim_end(".lua")
|
.file_name_trim_end(".lua")
|
||||||
.or_else(|_| path.file_name_trim_end(".luau"));
|
.or_else(|_| path.file_name_trim_end(".luau"));
|
||||||
|
|
||||||
|
let csv_name = path.file_name_trim_end(".csv");
|
||||||
|
|
||||||
if let Ok(name) = script_name {
|
if let Ok(name) = script_name {
|
||||||
match name {
|
match name {
|
||||||
// init scripts are handled elsewhere and should not turn into
|
// init scripts are handled elsewhere and should not turn into
|
||||||
@@ -110,8 +117,14 @@ pub fn snapshot_from_vfs(
|
|||||||
return Ok(None);
|
return Ok(None);
|
||||||
} else if path.file_name_ends_with(".json") {
|
} else if path.file_name_ends_with(".json") {
|
||||||
return snapshot_json(context, vfs, path);
|
return snapshot_json(context, vfs, path);
|
||||||
} else if path.file_name_ends_with(".csv") {
|
} else if let Ok(name) = csv_name {
|
||||||
return snapshot_csv(context, vfs, path);
|
match name {
|
||||||
|
// init csv are handled elsewhere and should not turn into
|
||||||
|
// their own children.
|
||||||
|
"init" => return Ok(None),
|
||||||
|
|
||||||
|
_ => return snapshot_csv(context, vfs, path),
|
||||||
|
}
|
||||||
} else if path.file_name_ends_with(".txt") {
|
} else if path.file_name_ends_with(".txt") {
|
||||||
return snapshot_txt(context, vfs, path);
|
return snapshot_txt(context, vfs, path);
|
||||||
} else if path.file_name_ends_with(".rbxmx") {
|
} else if path.file_name_ends_with(".rbxmx") {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ macro_rules! gen_build_tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gen_build_tests! {
|
gen_build_tests! {
|
||||||
|
init_csv_with_children,
|
||||||
attributes,
|
attributes,
|
||||||
client_in_folder,
|
client_in_folder,
|
||||||
client_init,
|
client_init,
|
||||||
|
|||||||
Reference in New Issue
Block a user