Finish off init command

This commit is contained in:
SkyfallWasTaken 2024-07-15 20:04:33 +01:00
parent 6164542183
commit c681c7b125
6 changed files with 242 additions and 15 deletions

View file

@ -6,5 +6,6 @@ edition = "2021"
[dependencies]
serde = { version = "1.0.204", features = ["derive"] }
serde_json = "1.0.120"
serde_with = "3.9.0"
thiserror = "1.0.61"
tokio = { version = "1.38.0", features = ["fs"], optional = true }

View file

@ -2,21 +2,41 @@ use std::collections::HashMap;
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, skip_serializing_none};
mod util;
#[serde_as]
#[skip_serializing_none]
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PackageJson {
pub name: String,
pub version: String,
pub author: Option<String>,
#[serde(default = "default_as_false")]
#[serde(skip_serializing_if = "is_false")]
pub private: bool,
pub license: Option<String>,
pub description: Option<String>,
pub main: Option<String>,
pub repository: Option<String>,
pub scripts: Option<Scripts>,
pub dependencies: Option<Dependencies>,
pub dev_dependencies: Option<Dependencies>,
}
// serde :/
fn is_false(value: &bool) -> bool {
!*value
}
fn default_as_false() -> bool {
false
}
pub type Scripts = HashMap<String, String>;
pub type Dependencies = HashMap<String, String>;