Skip to content

Commit

Permalink
optional command patterns, improved default config examples (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
DenysVuika authored Nov 15, 2024
1 parent 7d8d509 commit d72b387
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 22 deletions.
40 changes: 27 additions & 13 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,32 @@ impl Default for Config {
fn default() -> Self {
Config {
base: Some("main".to_string()),
tasks: Some(vec![Task {
name: "lint".to_string(),
description: Some("Runs eslint for all affected files".to_string()),
patterns: vec![
"*.ts".to_string(),
"*.tsx".to_string(),
"*.js".to_string(),
"*.jsx".to_string(),
],
commands: vec!["echo {files}".to_string()],
..Default::default()
}]),
tasks: Some(vec![
Task {
name: "lint".to_string(),
description: Some("Runs eslint for all affected files (example)".to_string()),
patterns: Some(vec![
"*.ts".to_string(),
"*.tsx".to_string(),
"*.js".to_string(),
"*.jsx".to_string(),
]),
commands: vec!["eslint {files}".to_string()],
..Default::default()
},
Task {
name: "prettier".to_string(),
description: Some("Runs prettier for all affected files (example)".to_string()),
patterns: Some(vec![
"*.ts".to_string(),
"*.tsx".to_string(),
"*.js".to_string(),
"*.jsx".to_string(),
]),
commands: vec!["prettier --check {files}".to_string()],
..Default::default()
},
]),
}
}
}
Expand All @@ -45,7 +59,7 @@ impl Default for Config {
pub struct Task {
pub name: String,
pub description: Option<String>,
pub patterns: Vec<String>,
pub patterns: Option<Vec<String>>,
pub separator: Option<String>,
pub commands: Vec<String>,
}
Expand Down
22 changes: 13 additions & 9 deletions src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ pub async fn run_task_by_name(
return Ok(());
}

let filtered_paths: Vec<_> = file_paths
.into_iter()
.filter(|path| {
task.patterns.iter().any(|pattern| {
Pattern::new(pattern)
.map(|p| p.matches(path))
.unwrap_or(false)
let filtered_paths: Vec<_> = if let Some(patterns) = &task.patterns {
file_paths
.into_iter()
.filter(|path| {
patterns.iter().any(|pattern| {
Pattern::new(pattern)
.map(|p| p.matches(path))
.unwrap_or(false)
})
})
})
.collect();
.collect()
} else {
file_paths
};

if filtered_paths.is_empty() {
println!("No files matched the patterns");
Expand Down

0 comments on commit d72b387

Please sign in to comment.