* improve build types by extracing asset opt as a dylib * dont use dylib, but let regular workspace caching do the heavy lifting * add prebuild to cli for better lock contention * hoist deps * disable slow tests * re-enable sequential, debug=0 for dev * use vfs for windows * dont cache on failure, fix windows vfs caceh * free disk space re-order * add clippy + fmt to windows channel * yoink makefile * proper rustfmt/clippy on toolchain * set incremental to zero since cargo-cache disables it
34 lines
943 B
Rust
34 lines
943 B
Rust
use std::{io::Read, path::Path};
|
|
|
|
use anyhow::Context;
|
|
|
|
pub(crate) fn minify_json(source: &str) -> anyhow::Result<String> {
|
|
// First try to parse the json
|
|
let json: serde_json::Value = serde_json::from_str(source)?;
|
|
// Then print it in a minified format
|
|
let json = serde_json::to_string(&json)?;
|
|
Ok(json)
|
|
}
|
|
|
|
pub(crate) fn process_json(source: &Path, output_path: &Path) -> anyhow::Result<()> {
|
|
let mut source_file = std::fs::File::open(source)?;
|
|
let mut source = String::new();
|
|
source_file.read_to_string(&mut source)?;
|
|
let json = match minify_json(&source) {
|
|
Ok(json) => json,
|
|
Err(err) => {
|
|
tracing::error!("Failed to minify json: {}", err);
|
|
source
|
|
}
|
|
};
|
|
|
|
std::fs::write(output_path, json).with_context(|| {
|
|
format!(
|
|
"Failed to write json to output location: {}",
|
|
output_path.display()
|
|
)
|
|
})?;
|
|
|
|
Ok(())
|
|
}
|