use crate::runtimes::CommandGenerator;
use std::{path::PathBuf, process::Command};
const COMMAND_NODE: &str = "node";
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct CommandGeneratorNodeJS {
js_path: PathBuf,
extra_args: Vec<String>,
}
impl CommandGeneratorNodeJS {
pub fn new(
js_path: impl Into<PathBuf>,
extra_args: impl IntoIterator<Item = impl AsRef<str>>,
) -> Self {
Self {
js_path: js_path.into(),
extra_args: extra_args
.into_iter()
.map(|s| s.as_ref().to_string())
.collect::<Vec<_>>(),
}
}
}
impl CommandGenerator for CommandGeneratorNodeJS {
fn generate_command(&self) -> Command {
let mut command_nodejs = Command::new(COMMAND_NODE);
command_nodejs.arg(&self.js_path);
command_nodejs.args(&self.extra_args);
command_nodejs
}
}