1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
use crate::settings::toml::{Target, TargetType}; use crate::terminal::message; use crate::wranglerjs; use crate::{commands, install}; use std::path::PathBuf; use std::process::Command; pub fn build(target: &Target) -> Result<(), failure::Error> { let target_type = &target.target_type; match target_type { TargetType::JavaScript => { message::info("JavaScript project found. Skipping unnecessary build!") } TargetType::Rust => { let tool_name = "wasm-pack"; let tool_author = "rustwasm"; let is_binary = true; let version = install::get_latest_version(tool_name)?; let binary_path = install::install(tool_name, tool_author, is_binary, version)?.binary(tool_name)?; let args = ["build", "--target", "no-modules"]; let command = command(&args, &binary_path); let command_name = format!("{:?}", command); commands::run(command, &command_name)?; } TargetType::Webpack => { wranglerjs::run_build(target)?; } } Ok(()) } pub fn command(args: &[&str], binary_path: &PathBuf) -> Command { message::working("Compiling your project to WebAssembly..."); let mut c = if cfg!(target_os = "windows") { let mut c = Command::new("cmd"); c.arg("/C"); c.arg(binary_path); c } else { Command::new(binary_path) }; c.args(args); c }