task_runner_detector/
lib.rs1mod parsers;
21mod scanner;
22
23use std::path::PathBuf;
24use thiserror::Error;
25
26pub use scanner::{scan, scan_with_options, ScanOptions};
27
28#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
30#[serde(rename_all = "lowercase")]
31pub enum RunnerType {
32 Npm,
33 Bun,
34 Yarn,
35 Pnpm,
36 Make,
37 Cargo,
38 Flutter,
39 Dart,
40 Turbo,
41 Poetry,
42 Pdm,
43 Just,
44 Deno,
45}
46
47impl RunnerType {
48 pub fn display_name(&self) -> &'static str {
50 match self {
51 RunnerType::Npm => "npm",
52 RunnerType::Bun => "bun",
53 RunnerType::Yarn => "yarn",
54 RunnerType::Pnpm => "pnpm",
55 RunnerType::Make => "make",
56 RunnerType::Cargo => "cargo",
57 RunnerType::Flutter => "flutter",
58 RunnerType::Dart => "dart",
59 RunnerType::Turbo => "turbo",
60 RunnerType::Poetry => "poetry",
61 RunnerType::Pdm => "pdm",
62 RunnerType::Just => "just",
63 RunnerType::Deno => "deno",
64 }
65 }
66
67 pub fn icon(&self) -> &'static str {
69 match self {
70 RunnerType::Npm => "๐ฆ",
71 RunnerType::Bun => "๐ฅ",
72 RunnerType::Yarn => "๐งถ",
73 RunnerType::Pnpm => "๐ฆ",
74 RunnerType::Make => "๐จ",
75 RunnerType::Cargo => "๐ฆ",
76 RunnerType::Flutter => "๐",
77 RunnerType::Dart => "๐ฏ",
78 RunnerType::Turbo => "โก",
79 RunnerType::Poetry => "๐",
80 RunnerType::Pdm => "๐",
81 RunnerType::Just => "๐",
82 RunnerType::Deno => "๐ฆ",
83 }
84 }
85
86 pub fn color_code(&self) -> u8 {
88 match self {
89 RunnerType::Npm => 1, RunnerType::Bun => 3, RunnerType::Yarn => 4, RunnerType::Pnpm => 3, RunnerType::Make => 2, RunnerType::Cargo => 1, RunnerType::Flutter => 6, RunnerType::Dart => 6, RunnerType::Turbo => 5, RunnerType::Poetry => 2, RunnerType::Pdm => 2, RunnerType::Just => 3, RunnerType::Deno => 2, }
103 }
104}
105
106impl std::fmt::Display for RunnerType {
107 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
108 write!(f, "{}", self.display_name())
109 }
110}
111
112#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
114pub struct Task {
115 pub name: String,
117 pub command: String,
119 #[serde(skip_serializing_if = "Option::is_none")]
121 pub description: Option<String>,
122 #[serde(skip_serializing_if = "Option::is_none")]
124 pub script: Option<String>,
125}
126
127#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
129pub struct TaskRunner {
130 pub config_path: PathBuf,
132 pub runner_type: RunnerType,
134 pub tasks: Vec<Task>,
136}
137
138#[derive(Error, Debug)]
140pub enum ScanError {
141 #[error("IO error: {0}")]
142 Io(#[from] std::io::Error),
143
144 #[error("Failed to parse {path}: {message}")]
145 ParseError { path: PathBuf, message: String },
146
147 #[error("Walk error: {0}")]
148 WalkError(#[from] ignore::Error),
149}
150
151pub type ScanResult<T> = Result<T, ScanError>;