-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b80ade6
commit 4c6903b
Showing
4 changed files
with
62 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use anyhow::{Context, Result}; | ||
use std::{fs, path::Path}; | ||
|
||
use package_json_schema::PackageJson; | ||
use serde::de::DeserializeOwned; | ||
|
||
pub struct DepotManifest<Config> { | ||
pub manifest: PackageJson, | ||
pub config: Config, | ||
} | ||
|
||
impl<Config: DeserializeOwned> DepotManifest<Config> { | ||
pub fn load(path: &Path) -> Result<Self> { | ||
let contents = fs::read_to_string(path) | ||
.with_context(|| format!("Missing manifest at: `{}`", path.display()))?; | ||
let manifest = PackageJson::try_from(contents)?; | ||
Self::from_json(manifest, path) | ||
} | ||
|
||
pub fn from_json(mut manifest: PackageJson, path: &Path) -> Result<Self> { | ||
let error_msg = || format!("Missing \"depot\" key from manifest: `{}`", path.display()); | ||
let other = manifest.other.as_mut().with_context(error_msg)?; | ||
let config_value = other.remove("depot").with_context(error_msg)?; | ||
let config: Config = serde_json::from_value(config_value)?; | ||
Ok(DepotManifest { manifest, config }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters