mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-24 06:34:09 +00:00
json5
This commit is contained in:
parent
074e62951f
commit
cd63b5c9c0
84 changed files with 743 additions and 288 deletions
|
|
@ -116,7 +116,7 @@ pub fn syncback_csv<'sync>(
|
|||
new_inst.name.clone()
|
||||
};
|
||||
fs_snapshot.add_file(
|
||||
parent.join(format!("{}.meta.json", meta_name)),
|
||||
parent.join(format!("{}.meta.json5", meta_name)),
|
||||
crate::json::to_vec_pretty_sorted(&meta).context("cannot serialize metadata")?,
|
||||
)
|
||||
}
|
||||
|
|
@ -154,9 +154,9 @@ pub fn syncback_csv_init<'sync>(
|
|||
meta.properties.shift_remove(&ustr("Contents"));
|
||||
if !meta.is_empty() {
|
||||
dir_syncback.fs_snapshot.add_file(
|
||||
snapshot.path.join("init.meta.json"),
|
||||
snapshot.path.join("init.meta.json5"),
|
||||
crate::json::to_vec_pretty_sorted(&meta)
|
||||
.context("could not serialize new init.meta.json")?,
|
||||
.context("could not serialize new init.meta.json5")?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -256,7 +256,7 @@ fn localization_to_csv(csv_contents: &str) -> anyhow::Result<Vec<u8>> {
|
|||
let mut writer = csv::Writer::from_writer(&mut out);
|
||||
|
||||
let mut csv: Vec<LocalizationEntry> =
|
||||
serde_json::from_str(csv_contents).context("cannot decode JSON from localization table")?;
|
||||
json5::from_str(csv_contents).context("cannot decode JSON from localization table")?;
|
||||
|
||||
// TODO sort this better
|
||||
csv.sort_by(|a, b| a.source.partial_cmp(&b.source).unwrap());
|
||||
|
|
|
|||
|
|
@ -106,9 +106,9 @@ pub fn syncback_dir<'sync>(
|
|||
|
||||
if !meta.is_empty() {
|
||||
dir_syncback.fs_snapshot.add_file(
|
||||
snapshot.path.join("init.meta.json"),
|
||||
snapshot.path.join("init.meta.json5"),
|
||||
crate::json::to_vec_pretty_sorted(&meta)
|
||||
.context("could not serialize new init.meta.json")?,
|
||||
.context("could not serialize new init.meta.json5")?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ pub fn syncback_lua<'sync>(
|
|||
meta_name.to_string()
|
||||
};
|
||||
fs_snapshot.add_file(
|
||||
parent_location.join(format!("{}.meta.json", meta_name)),
|
||||
parent_location.join(format!("{}.meta.json5", meta_name)),
|
||||
crate::json::to_vec_pretty_sorted(&meta).context("cannot serialize metadata")?,
|
||||
);
|
||||
}
|
||||
|
|
@ -225,9 +225,9 @@ pub fn syncback_lua_init<'sync>(
|
|||
|
||||
if !meta.is_empty() {
|
||||
dir_syncback.fs_snapshot.add_file(
|
||||
snapshot.path.join("init.meta.json"),
|
||||
snapshot.path.join("init.meta.json5"),
|
||||
crate::json::to_vec_pretty_sorted(&meta)
|
||||
.context("could not serialize new init.meta.json")?,
|
||||
.context("could not serialize new init.meta.json5")?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ impl AdjacentMetadata {
|
|||
.unwrap_or(file_stem);
|
||||
let meta_path_json = path.with_file_name(format!("{base_name}.meta.json"));
|
||||
let meta_path_jsonc = path.with_file_name(format!("{base_name}.meta.jsonc"));
|
||||
let meta_path_json5 = path.with_file_name(format!("{base_name}.meta.json5"));
|
||||
|
||||
if let Some(meta_contents) = vfs.read(&meta_path_json).with_not_found()? {
|
||||
let mut metadata = Self::from_slice(&meta_contents, meta_path_json.clone())?;
|
||||
|
|
@ -72,13 +73,19 @@ impl AdjacentMetadata {
|
|||
}
|
||||
|
||||
if let Some(meta_contents) = vfs.read(&meta_path_jsonc).with_not_found()? {
|
||||
let mut metadata = Self::from_slice(&meta_contents, meta_path_json.clone())?;
|
||||
let mut metadata = Self::from_slice(&meta_contents, meta_path_jsonc.clone())?;
|
||||
metadata.apply_all(snapshot)?;
|
||||
}
|
||||
|
||||
if let Some(meta_contents) = vfs.read(&meta_path_json5).with_not_found()? {
|
||||
let mut metadata = Self::from_slice(&meta_contents, meta_path_json5.clone())?;
|
||||
metadata.apply_all(snapshot)?;
|
||||
}
|
||||
|
||||
// Rather than pushing these in the snapshot middleware, we can just do it here.
|
||||
snapshot.metadata.relevant_paths.push(meta_path_json);
|
||||
snapshot.metadata.relevant_paths.push(meta_path_jsonc);
|
||||
snapshot.metadata.relevant_paths.push(meta_path_json5);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -290,6 +297,7 @@ impl DirectoryMetadata {
|
|||
) -> anyhow::Result<()> {
|
||||
let meta_path_json = path.join("init.meta.json");
|
||||
let meta_path_jsonc = path.join("init.meta.jsonc");
|
||||
let meta_path_json5 = path.join("init.meta.json5");
|
||||
|
||||
if let Some(meta_contents) = vfs.read(&meta_path_json).with_not_found()? {
|
||||
let mut metadata = Self::from_slice(&meta_contents, meta_path_json.clone())?;
|
||||
|
|
@ -301,9 +309,15 @@ impl DirectoryMetadata {
|
|||
metadata.apply_all(snapshot)?;
|
||||
}
|
||||
|
||||
if let Some(meta_contents) = vfs.read(&meta_path_json5).with_not_found()? {
|
||||
let mut metadata = Self::from_slice(&meta_contents, meta_path_json5.clone())?;
|
||||
metadata.apply_all(snapshot)?;
|
||||
}
|
||||
|
||||
// Rather than pushing these in the snapshot middleware, we can just do it here.
|
||||
snapshot.metadata.relevant_paths.push(meta_path_json);
|
||||
snapshot.metadata.relevant_paths.push(meta_path_jsonc);
|
||||
snapshot.metadata.relevant_paths.push(meta_path_json5);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -495,32 +509,34 @@ impl DirectoryMetadata {
|
|||
}
|
||||
|
||||
/// Retrieves the meta file that should be applied for the provided directory,
|
||||
/// if it exists.
|
||||
/// if it exists. Checks for .json5, .jsonc, and .json in that order.
|
||||
pub fn dir_meta(vfs: &Vfs, path: &Path) -> anyhow::Result<Option<DirectoryMetadata>> {
|
||||
let meta_path = path.join("init.meta.json");
|
||||
|
||||
if let Some(meta_contents) = vfs.read(&meta_path).with_not_found()? {
|
||||
let metadata = DirectoryMetadata::from_slice(&meta_contents, meta_path)?;
|
||||
Ok(Some(metadata))
|
||||
} else {
|
||||
Ok(None)
|
||||
// Check json5 first (preferred), then jsonc, then json
|
||||
for ext in ["init.meta.json5", "init.meta.jsonc", "init.meta.json"] {
|
||||
let meta_path = path.join(ext);
|
||||
if let Some(meta_contents) = vfs.read(&meta_path).with_not_found()? {
|
||||
let metadata = DirectoryMetadata::from_slice(&meta_contents, meta_path)?;
|
||||
return Ok(Some(metadata));
|
||||
}
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
/// Retrieves the meta file that should be applied for the provided file,
|
||||
/// if it exists.
|
||||
/// if it exists. Checks for .json5, .jsonc, and .json in that order.
|
||||
///
|
||||
/// The `name` field should be the name the metadata should have.
|
||||
pub fn file_meta(vfs: &Vfs, path: &Path, name: &str) -> anyhow::Result<Option<AdjacentMetadata>> {
|
||||
let mut meta_path = path.with_file_name(name);
|
||||
meta_path.set_extension("meta.json");
|
||||
|
||||
if let Some(meta_contents) = vfs.read(&meta_path).with_not_found()? {
|
||||
let metadata = AdjacentMetadata::from_slice(&meta_contents, meta_path)?;
|
||||
Ok(Some(metadata))
|
||||
} else {
|
||||
Ok(None)
|
||||
// Check json5 first (preferred), then jsonc, then json
|
||||
for ext in ["meta.json5", "meta.jsonc", "meta.json"] {
|
||||
let mut meta_path = path.with_file_name(name);
|
||||
meta_path.set_extension(ext);
|
||||
if let Some(meta_contents) = vfs.read(&meta_path).with_not_found()? {
|
||||
let metadata = AdjacentMetadata::from_slice(&meta_contents, meta_path)?;
|
||||
return Ok(Some(metadata));
|
||||
}
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
|
|
@ -430,10 +430,13 @@ pub fn default_sync_rules() -> &'static [SyncRule] {
|
|||
sync_rule!("*.{lua,luau}", ModuleScript),
|
||||
sync_rule!("*.project.json", Project, ".project.json"),
|
||||
sync_rule!("*.project.jsonc", Project, ".project.jsonc"),
|
||||
sync_rule!("*.project.json5", Project, ".project.json5"),
|
||||
sync_rule!("*.model.json", JsonModel, ".model.json"),
|
||||
sync_rule!("*.model.jsonc", JsonModel, ".model.jsonc"),
|
||||
sync_rule!("*.model.json5", JsonModel, ".model.json5"),
|
||||
sync_rule!("*.json", Json, ".json", "*.meta.json"),
|
||||
sync_rule!("*.jsonc", Json, ".jsonc", "*.meta.jsonc"),
|
||||
sync_rule!("*.json5", Json, ".json5", "*.meta.json5"),
|
||||
sync_rule!("*.toml", Toml),
|
||||
sync_rule!("*.csv", Csv),
|
||||
sync_rule!("*.txt", Text),
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /foo.csv
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ metadata:
|
|||
- /root/init.csv
|
||||
- /root/init.meta.json
|
||||
- /root/init.meta.jsonc
|
||||
- /root/init.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ metadata:
|
|||
- /root/init.csv
|
||||
- /root/init.meta.json
|
||||
- /root/init.meta.jsonc
|
||||
- /root/init.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /foo.csv
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ metadata:
|
|||
- /foo/init.csv
|
||||
- /foo/init.meta.json
|
||||
- /foo/init.meta.jsonc
|
||||
- /foo/init.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ metadata:
|
|||
- /foo/init.csv
|
||||
- /foo/init.meta.json
|
||||
- /foo/init.meta.jsonc
|
||||
- /foo/init.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
@ -44,6 +45,7 @@ children:
|
|||
- /foo/Child/init.csv
|
||||
- /foo/Child/init.meta.json
|
||||
- /foo/Child/init.meta.jsonc
|
||||
- /foo/Child/init.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /foo.json
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /foo.json
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /foo.client.lua
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /foo.lua
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /foo.lua
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /bar.server.lua
|
||||
- /bar.meta.json
|
||||
- /bar.meta.jsonc
|
||||
- /bar.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /foo.server.lua
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /foo.server.lua
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ metadata:
|
|||
- /root/init.csv
|
||||
- /root/init.meta.json
|
||||
- /root/init.meta.jsonc
|
||||
- /root/init.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ metadata:
|
|||
- /root/init.csv
|
||||
- /root/init.meta.json
|
||||
- /root/init.meta.jsonc
|
||||
- /root/init.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /foo.plugin.lua
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: false
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /foo.client.lua
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: false
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /foo.lua
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: false
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /foo.lua
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: false
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /bar.server.lua
|
||||
- /bar.meta.json
|
||||
- /bar.meta.jsonc
|
||||
- /bar.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: false
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /foo.server.lua
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: false
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /foo.server.lua
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: false
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ metadata:
|
|||
relevant_paths:
|
||||
- /foo/bar.meta.json
|
||||
- /foo/bar.meta.jsonc
|
||||
- /foo/bar.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ metadata:
|
|||
relevant_paths:
|
||||
- /foo/bar.meta.json
|
||||
- /foo/bar.meta.jsonc
|
||||
- /foo/bar.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ metadata:
|
|||
relevant_paths:
|
||||
- /foo/init.meta.json
|
||||
- /foo/init.meta.jsonc
|
||||
- /foo/init.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ metadata:
|
|||
relevant_paths:
|
||||
- /foo/init.meta.json
|
||||
- /foo/init.meta.jsonc
|
||||
- /foo/init.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /foo/other.txt
|
||||
- /foo/other.meta.json
|
||||
- /foo/other.meta.jsonc
|
||||
- /foo/other.meta.json5
|
||||
- /foo/default.project.json
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /foo.toml
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- foo.toml
|
||||
- foo.meta.json
|
||||
- foo.meta.jsonc
|
||||
- foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /foo.txt
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /foo.txt
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- /foo.yaml
|
||||
- /foo.meta.json
|
||||
- /foo.meta.jsonc
|
||||
- /foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ metadata:
|
|||
- foo.yaml
|
||||
- foo.meta.json
|
||||
- foo.meta.jsonc
|
||||
- foo.meta.json5
|
||||
context:
|
||||
emit_legacy_scripts: true
|
||||
decode_windows_invalid_chars: false
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ pub fn syncback_txt<'sync>(
|
|||
new_inst.name.clone()
|
||||
};
|
||||
fs_snapshot.add_file(
|
||||
parent.join(format!("{}.meta.json", meta_name)),
|
||||
parent.join(format!("{}.meta.json5", meta_name)),
|
||||
crate::json::to_vec_pretty_sorted(&meta).context("could not serialize metadata")?,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue