1use serde::{Deserialize, Serialize};
2use std::collections::BTreeMap;
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct VanConfig {
7 pub name: String,
8 pub version: String,
9 #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
10 pub scripts: BTreeMap<String, String>,
11 #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
12 pub dependencies: BTreeMap<String, String>,
13 #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
14 #[serde(rename = "devDependencies")]
15 pub dev_dependencies: BTreeMap<String, String>,
16 #[serde(default, skip_serializing_if = "Option::is_none")]
17 pub registry: Option<String>,
18}
19
20impl VanConfig {
21 pub fn new(name: &str) -> Self {
22 let mut scripts = BTreeMap::new();
23 scripts.insert("dev".into(), "van dev".into());
24 scripts.insert("build".into(), "van build".into());
25
26 Self {
27 name: name.into(),
28 version: "0.1.0".into(),
29 scripts,
30 dependencies: BTreeMap::new(),
31 dev_dependencies: BTreeMap::new(),
32 registry: None,
33 }
34 }
35
36 pub fn to_json_pretty(&self) -> anyhow::Result<String> {
37 Ok(serde_json::to_string_pretty(self)?)
38 }
39}