Skip to content

Commit

Permalink
refactor(manifest): refactor npm package into own mod
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleygwilliams committed Sep 18, 2018
1 parent 5304a49 commit 33eccd3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
29 changes: 3 additions & 26 deletions src/manifest.rs → src/manifest/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Reading and writing Cargo.toml and package.json manifests.

mod npm;

use std::collections::HashMap;
use std::fs::File;
use std::io::prelude::*;
Expand All @@ -8,6 +10,7 @@ use std::path::Path;
use console::style;
use emoji;
use error::Error;
use self::npm::{NpmPackage, Repository};
use progressbar::Step;
use serde_json;
use toml;
Expand Down Expand Up @@ -75,32 +78,6 @@ struct CargoLib {
crate_type: Option<Vec<String>>,
}

#[derive(Serialize)]
struct NpmPackage {
name: String,
#[serde(skip_serializing_if = "Vec::is_empty")]
collaborators: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
description: Option<String>,
version: String,
#[serde(skip_serializing_if = "Option::is_none")]
license: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
repository: Option<Repository>,
#[serde(skip_serializing_if = "Vec::is_empty")]
files: Vec<String>,
main: String,
#[serde(skip_serializing_if = "Option::is_none")]
types: Option<String>,
}

#[derive(Serialize)]
struct Repository {
#[serde(rename = "type")]
ty: String,
url: String,
}

fn read_cargo_toml(path: &Path) -> Result<CargoManifest, Error> {
let manifest_path = path.join("Cargo.toml");
if !manifest_path.is_file() {
Expand Down
25 changes: 25 additions & 0 deletions src/manifest/npm/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#[derive(Serialize)]
pub struct NpmPackage {
pub name: String,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub collaborators: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
pub version: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub license: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub repository: Option<Repository>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub files: Vec<String>,
pub main: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub types: Option<String>,
}

#[derive(Serialize)]
pub struct Repository {
#[serde(rename = "type")]
pub ty: String,
pub url: String,
}

0 comments on commit 33eccd3

Please sign in to comment.