Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support yarn/pnpm via -p flag #3

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,16 @@ pub struct Script {
pub package_name: String,
config: CommandConfig,
pub dir: PathBuf,
package_manager: String,
}

impl Script {
pub fn new(config: CommandConfig, dir: &PathBuf, package_name: &str) -> Self {
pub fn new(
config: CommandConfig,
dir: &PathBuf,
package_name: &str,
package_manager: String,
) -> Self {
let name = config.command.clone();

let mut status = ScriptStatus::Ready;
Expand All @@ -63,13 +69,14 @@ impl Script {
dir: dir.into(),
command: name.to_string(),
status,
package_manager,
}
}

pub fn execute(&mut self) -> Child {
self.status = ScriptStatus::Running;

let mut command = Command::new("npm");
let mut command = Command::new(self.package_manager.clone());

let mut child = command
.current_dir(&self.dir)
Expand Down
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use hasty::{self, make_script_id, Engine, Script, TOPOLOGICAL_DEP_PREFIX};
#[tokio::main]
async fn main() {
let options = hasty::options::HastyOptions::parse();
println!("Using package manager: {}", options.package_manager.clone());

if let Some(ref dir) = options.dir {
println!("dir: {}", dir.display());
Expand All @@ -25,6 +26,7 @@ async fn main() {
config.pipeline.get(&opts_script).unwrap().clone(),
dir,
"__ROOT__",
options.package_manager.clone(),
);

engine.add_script(&script);
Expand All @@ -49,7 +51,12 @@ async fn main() {
continue;
}

let s = Script::new(config.pipeline.get(&s).unwrap().clone(), dir, "__ROOT__");
let s = Script::new(
config.pipeline.get(&s).unwrap().clone(),
dir,
"__ROOT__",
options.package_manager.clone(),
);
engine.add_script(&s);

if s.has_dependencies() {
Expand Down
12 changes: 10 additions & 2 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ use serde::Deserialize;
#[clap(author, version, about, long_about = None)]
#[derive(Deserialize)]
pub struct HastyOptions {
// The directory of the project
/// The directory of the project
#[arg(short, long)]
pub dir: Option<PathBuf>,

// The script to execute
/// The script to execute
pub script: Option<String>,

/// Package manager
///
/// Valid options are "npm", "yarn", "pnpm"
///
/// Default: "npm"
#[arg(short, long, default_value_t = String::from("npm"))]
pub package_manager: String,
}