fix: repository and author objects in package.json now parse

This commit is contained in:
SkyfallWasTaken 2024-07-30 09:21:01 +01:00
parent 2181a82cb8
commit ee0e593b37
4 changed files with 12 additions and 5 deletions

2
Cargo.lock generated
View file

@ -402,7 +402,7 @@ dependencies = [
[[package]] [[package]]
name = "dinopkg-package-json" name = "dinopkg-package-json"
version = "0.2.0" version = "0.3.0"
dependencies = [ dependencies = [
"serde", "serde",
"serde_json", "serde_json",

View file

@ -4,7 +4,7 @@ use camino::Utf8PathBuf;
use color_eyre::eyre::eyre; use color_eyre::eyre::eyre;
use color_eyre::Result; use color_eyre::Result;
use dialoguer::{theme::ColorfulTheme, Confirm, Input}; use dialoguer::{theme::ColorfulTheme, Confirm, Input};
use dinopkg_package_json::{AuthorVariant, PackageJson}; use dinopkg_package_json::{AuthorVariant, PackageJson, RepositoryVariant};
use gix_config::File as GitConfigFile; use gix_config::File as GitConfigFile;
use maplit::hashmap; use maplit::hashmap;
use owo_colors::OwoColorize; use owo_colors::OwoColorize;
@ -101,7 +101,7 @@ pub async fn init() -> Result<()> {
name: package_name, name: package_name,
version, version,
author: Some(AuthorVariant::String(author)), author: Some(AuthorVariant::String(author)),
repository: Some(git_repository), repository: Some(RepositoryVariant::String(git_repository)),
license: Some(license), license: Some(license),
description: Some(description), description: Some(description),
private, private,

View file

@ -1,6 +1,6 @@
[package] [package]
name = "dinopkg-package-json" name = "dinopkg-package-json"
version = "0.2.0" version = "0.3.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View file

@ -20,7 +20,7 @@ pub struct PackageJson {
pub license: Option<String>, pub license: Option<String>,
pub description: Option<String>, pub description: Option<String>,
pub main: Option<String>, pub main: Option<String>,
pub repository: Option<String>, pub repository: Option<RepositoryVariant>,
pub scripts: Option<Scripts>, pub scripts: Option<Scripts>,
@ -35,6 +35,13 @@ pub enum AuthorVariant {
String(String), String(String),
} }
#[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)]
pub enum RepositoryVariant {
Repository { r#type: String, url: Option<String> },
String(String),
}
// serde :/ // serde :/
#[allow(clippy::trivially_copy_pass_by_ref)] #[allow(clippy::trivially_copy_pass_by_ref)]
#[inline(always)] #[inline(always)]