-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Jujulego/feat/parse-manifest
Parse package.json manifest
- Loading branch information
Showing
3 changed files
with
35 additions
and
14 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 |
---|---|---|
@@ -1,14 +1 @@ | ||
pub fn add(left: usize, right: usize) -> usize { | ||
left + right | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn it_works() { | ||
let result = add(2, 2); | ||
assert_eq!(result, 4); | ||
} | ||
} | ||
pub mod manifest; |
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,32 @@ | ||
use std::collections::HashMap; | ||
use std::io; | ||
use std::fs::File; | ||
use serde::Deserialize; | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct PackageManifest { | ||
pub name: String, | ||
pub version: String, | ||
#[serde(default)] | ||
pub workspaces: Vec<String>, | ||
#[serde(default)] | ||
pub scripts: HashMap<String, String>, | ||
#[serde(default)] | ||
pub dependencies: HashMap<String, String>, | ||
#[serde(default, rename = "devDependencies")] | ||
pub dev_dependencies: HashMap<String, String>, | ||
} | ||
|
||
pub enum Error { | ||
Io(io::Error), | ||
Parse(serde_json::Error) | ||
} | ||
|
||
impl PackageManifest { | ||
pub fn parse_file(path: &str) -> Result<PackageManifest, Error> { | ||
let file = File::open(path).map_err(Error::Io)?; | ||
let manifest = serde_json::from_reader(&file).map_err(Error::Parse)?; | ||
|
||
Ok(manifest) | ||
} | ||
} |