Add fields to package.json

This commit is contained in:
SkyfallWasTaken 2024-07-09 20:49:26 +01:00
parent b729259092
commit 4d4223acdc
3 changed files with 29 additions and 2 deletions

4
Cargo.lock generated
View file

@ -238,6 +238,10 @@ dependencies = [
[[package]]
name = "dinopkg-package-json"
version = "0.1.0"
dependencies = [
"serde",
"serde_json",
]
[[package]]
name = "encoding_rs"

View file

@ -4,3 +4,5 @@ version = "0.1.0"
edition = "2021"
[dependencies]
serde = { version = "1.0.204", features = ["derive"] }
serde_json = "1.0.120"

View file

@ -1,3 +1,24 @@
fn main() {
println!("Hello, world!");
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PackageJson {
pub name: String,
pub version: String,
pub description: Option<String>,
pub main: Option<String>,
pub scripts: Option<Scripts>,
pub dependencies: Option<Dependencies>,
pub dev_dependencies: Option<Dependencies>,
}
pub type Scripts = HashMap<String, String>;
pub type Dependencies = HashMap<String, String>;
impl PackageJson {
pub fn parse(json: &str) -> Result<Self, serde_json::Error> {
serde_json::from_str(json)
}
}