mirror of
https://github.com/SkyfallWasTaken/dinopkg.git
synced 2024-11-10 06:19:40 +00:00
Add dinopkg-package-json
This commit is contained in:
parent
4d4223acdc
commit
7117a31926
5 changed files with 43 additions and 2 deletions
23
Cargo.lock
generated
23
Cargo.lock
generated
|
@ -230,6 +230,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"clap",
|
||||
"color-eyre",
|
||||
"dinopkg-package-json",
|
||||
"owo-colors 4.0.0",
|
||||
"reqwest",
|
||||
"tokio",
|
||||
|
@ -241,6 +242,8 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1089,6 +1092,26 @@ dependencies = [
|
|||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.61"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.61"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "1.1.8"
|
||||
|
|
|
@ -9,3 +9,4 @@ color-eyre = "0.6.3"
|
|||
owo-colors = "4.0.0"
|
||||
reqwest = "0.12.5"
|
||||
tokio = { version = "1.38.0", features = ["macros", "rt-multi-thread"] }
|
||||
dinopkg-package-json = { path = "../dinopkg-package-json" }
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
use dinopkg_package_json::PackageJson;
|
||||
|
||||
pub async fn run(script_name: Option<String>) {}
|
||||
|
|
|
@ -6,3 +6,5 @@ edition = "2021"
|
|||
[dependencies]
|
||||
serde = { version = "1.0.204", features = ["derive"] }
|
||||
serde_json = "1.0.120"
|
||||
thiserror = "1.0.61"
|
||||
tokio = { version = "1.38.0", features = ["fs"], optional = true }
|
||||
|
|
|
@ -17,8 +17,21 @@ pub struct PackageJson {
|
|||
pub type Scripts = HashMap<String, String>;
|
||||
pub type Dependencies = HashMap<String, String>;
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error("deserialization error: {0}")]
|
||||
Serde(#[from] serde_json::Error),
|
||||
}
|
||||
|
||||
impl PackageJson {
|
||||
pub fn parse(json: &str) -> Result<Self, serde_json::Error> {
|
||||
serde_json::from_str(json)
|
||||
pub fn parse(json: &str) -> Result<Self, Error> {
|
||||
Ok(serde_json::from_str(json)?)
|
||||
}
|
||||
|
||||
#[cfg(feature = "tokio")]
|
||||
pub async fn from_file() -> Result<Self, Error> {
|
||||
let file = tokio::fs::read("package.json").await?;
|
||||
let file = String::from_utf8(file)?;
|
||||
Self::parse(&file)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue