mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 14:01:37 +00:00
Implement new oneshot Vfs for CLI commands and enhance JSON5 serialization
- Added `new_oneshot` method to the Vfs struct, providing a backend suitable for one-time operations without file watching. - Updated CLI commands (`fmt_project` and `syncback`) to utilize the new oneshot Vfs, improving error handling during file operations. - Enhanced JSON5 serialization by introducing a custom serializer that directly builds a tree structure, improving performance and maintaining sorted keys. - Improved error logging in JSON serialization to provide more context on failures.
This commit is contained in:
parent
fca802a4e5
commit
5f91a0777a
7 changed files with 3753 additions and 44 deletions
|
|
@ -83,12 +83,32 @@ pub fn syncback_json_model<'sync>(
|
|||
model.schema = old_inst.metadata().schema.clone();
|
||||
}
|
||||
|
||||
let serialized = match crate::json::to_vec_pretty_sorted(&model) {
|
||||
Ok(bytes) => bytes,
|
||||
Err(e) => {
|
||||
// Provide more detail about what's in the model
|
||||
let prop_details: Vec<_> = model
|
||||
.properties
|
||||
.iter()
|
||||
.map(|(k, v)| format!("{}={:?}", k.as_str(), v))
|
||||
.collect();
|
||||
let attr_names: Vec<_> = model.attributes.keys().map(|k| k.as_str()).collect();
|
||||
log::error!(
|
||||
"Failed to serialize JSON model for class '{}': properties=[{}], attributes={:?}, error: {}",
|
||||
model.class_name,
|
||||
prop_details.join(", "),
|
||||
attr_names,
|
||||
e
|
||||
);
|
||||
return Err(e.context(format!(
|
||||
"failed to serialize new JSON Model for class '{}'",
|
||||
model.class_name
|
||||
)));
|
||||
}
|
||||
};
|
||||
|
||||
Ok(SyncbackReturn {
|
||||
fs_snapshot: FsSnapshot::new().with_added_file(
|
||||
&snapshot.path,
|
||||
crate::json::to_vec_pretty_sorted(&model)
|
||||
.context("failed to serialize new JSON Model")?,
|
||||
),
|
||||
fs_snapshot: FsSnapshot::new().with_added_file(&snapshot.path, serialized),
|
||||
children: Vec::new(),
|
||||
removed_children: Vec::new(),
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue