Skip to content

Commit

Permalink
working pnpm backend
Browse files Browse the repository at this point in the history
  • Loading branch information
tanneberger committed Sep 30, 2023
1 parent 5873e69 commit 8783df4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 13 deletions.
4 changes: 0 additions & 4 deletions src/backends/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ fn do_npm_build(results: &mut BatchBuildResults, options: &BuildCommandOptions)
.join("dist")
.join(file_name + ".js");

//let cmake_binary_name = app.main_reactor.file_stem().unwrap();
// cleanup: rename executable to match the app name
let bin_dir = app.output_root.join("bin");
println!("{:?}", &path);
println!("{:?}", &app.executable_path());
fs::rename(path, app.executable_path())?;
Ok(())
});
Expand Down
66 changes: 58 additions & 8 deletions src/backends/pnpm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use crate::util::errors::LingoError;
use crate::util::execute_command_to_build_result;
use std::error::Error;
use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;

pub struct Pnpm;
Expand All @@ -13,15 +17,61 @@ fn do_pnpm_build(results: &mut BatchBuildResults, options: &BuildCommandOptions)
return;
}

results.map(|app| {
let mut npm_install = Command::new("pnpm");
npm_install.arg("install");
if options.profile == BuildProfile::Release {
npm_install.arg("--production");
let extract_name = |path: &PathBuf| -> Result<String, Box<dyn Error + Send + Sync>> {
match Path::new(&path).file_stem() {
Some(value) => value
.to_str()
.map(|x| String::from(x))

Check warning on line 24 in src/backends/pnpm.rs

View workflow job for this annotation

GitHub Actions / Clippy Output

redundant closure

warning: redundant closure --> src/backends/pnpm.rs:24:22 | 24 | .map(|x| String::from(x)) | ^^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `String::from` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
.ok_or(Box::new(LingoError::InvalidMainReactor)),
None => Err(Box::new(LingoError::InvalidMainReactor)),
}
npm_install.current_dir(&app.output_root);
execute_command_to_build_result(npm_install)
});
};

results
.map(|app| {
let file_name = extract_name(&app.main_reactor)?;
let path = app.output_root.join("src-gen").join(file_name);

let mut npm_install = Command::new("pnpm");
npm_install.current_dir(path);
npm_install.arg("install");
if options.profile == BuildProfile::Release {
npm_install.arg("--prod"); // different to npm
}
execute_command_to_build_result(npm_install)?;
Ok(())
})
.map(|app| {
let file_name = extract_name(&app.main_reactor)?;
let path = app.output_root.join("src-gen").join(file_name);

let mut npm_build = Command::new("pnpm");
npm_build.current_dir(path);
npm_build.arg("run");
npm_build.arg("build");

if options.profile == BuildProfile::Release {
npm_build.arg("--production");
}
execute_command_to_build_result(npm_build)?;

Ok(())
})
.map(|app| {
fs::create_dir_all(&app.output_root.join("bin"))?;

Check warning on line 61 in src/backends/pnpm.rs

View workflow job for this annotation

GitHub Actions / Clippy Output

the borrowed expression implements the required traits

warning: the borrowed expression implements the required traits --> src/backends/pnpm.rs:61:32 | 61 | fs::create_dir_all(&app.output_root.join("bin"))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `app.output_root.join("bin")` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

let file_name = extract_name(&app.main_reactor)?;
let path = app
.output_root
.join("src-gen")
.join(&file_name)
.join("dist")
.join(file_name + ".js");

// cleanup: rename executable to match the app name
fs::rename(path, app.executable_path())?;
Ok(())
});
}

impl BatchBackend for Pnpm {
Expand Down
2 changes: 1 addition & 1 deletion src/util/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Display for LingoError {
LingoError::InvalidMainReactor => {
write!(
f,
"The main reactor was not a valid path to a file containing a main reactor"
"Not a valid path path to a file that contains a main reactor"
)
}
}
Expand Down

0 comments on commit 8783df4

Please sign in to comment.