Skip to content

Commit

Permalink
options scripts in package.json detect
Browse files Browse the repository at this point in the history
  • Loading branch information
coffee-cup committed Apr 2, 2022
1 parent 10e706d commit 4fbce9a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
14 changes: 9 additions & 5 deletions src/providers/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ impl Provider for NpmProvider {

fn suggested_build_cmd(&self, app: &App) -> Result<Option<String>> {
let package_json: PackageJson = app.read_json("package.json")?;
if package_json.scripts.get("build").is_some() {
return Ok(Some("npm run build".to_string()));
if let Some(scripts) = package_json.scripts {
if scripts.get("build").is_some() {
return Ok(Some("npm run build".to_string()));
}
}

Ok(None)
}

fn suggested_start_command(&self, app: &App) -> Result<Option<String>> {
let package_json: PackageJson = app.read_json("package.json")?;
if package_json.scripts.get("start").is_some() {
return Ok(Some("npm run start".to_string()));
if let Some(scripts) = package_json.scripts {
if scripts.get("start").is_some() {
return Ok(Some("npm run start".to_string()));
}
}

if app.includes_file("index.js") {
Expand All @@ -50,5 +54,5 @@ impl Provider for NpmProvider {
#[derive(Serialize, Deserialize, Debug)]
pub struct PackageJson {
pub name: String,
pub scripts: HashMap<String, String>,
pub scripts: Option<HashMap<String, String>>,
}
12 changes: 8 additions & 4 deletions src/providers/yarn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,21 @@ impl Provider for YarnProvider {

fn suggested_build_cmd(&self, app: &App) -> Result<Option<String>> {
let package_json: PackageJson = app.read_json("package.json")?;
if package_json.scripts.get("build").is_some() {
return Ok(Some("yarn build".to_string()));
if let Some(scripts) = package_json.scripts {
if scripts.get("build").is_some() {
return Ok(Some("yarn build".to_string()));
}
}

Ok(None)
}

fn suggested_start_command(&self, app: &App) -> Result<Option<String>> {
let package_json: PackageJson = app.read_json("package.json")?;
if package_json.scripts.get("start").is_some() {
return Ok(Some("yarn start".to_string()));
if let Some(scripts) = package_json.scripts {
if scripts.get("start").is_some() {
return Ok(Some("yarn start".to_string()));
}
}

if app.includes_file("index.js") {
Expand Down

0 comments on commit 4fbce9a

Please sign in to comment.