mirror of
https://github.com/SkyfallWasTaken/dinopkg.git
synced 2025-05-01 01:29:30 +00:00
Add dinopkg-package-json
This commit is contained in:
parent
4d4223acdc
commit
7117a31926
5 changed files with 43 additions and 2 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue