diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f94b62..b2ee0fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.7.2 + +- fix: check env + ## 0.7.1 - fix: crate root diff --git a/Cargo.toml b/Cargo.toml index 31ef957..acb866a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "rsw" -version = "0.7.1" +version = "0.7.2" description = "wasm-pack based build tool" edition = "2021" authors = ["lencx "] homepage = "https://github.com/lencx/rsw-rs" repository = "https://github.com/lencx/rsw-rs" -keywords = ["rsw", "wasm-pack"] +keywords = ["rsw", "wasm-pack", "webassembly", "wasm", "npm"] license = "MIT" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -22,3 +22,4 @@ regex = "1.5.4" serde = "1.0.133" serde_derive = "1.0.133" toml = "0.5.8" +which = "4.2.4" diff --git a/README.md b/README.md index 929b00d..3062a06 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,11 @@

+

rsw-rs

-「🌐 Language」[简体中文](./README.zh_CN.md) - **`rsw = rs(rust) → w(wasm)`** - A command-line tool for automatically rebuilding local changes, based on the `wasm-pack` implementation. -## rsw-rs +**Englist | [简体中文](./README.zh_CN.md)** ## Pre-installed diff --git a/README.zh_CN.md b/README.zh_CN.md index 78ffcb1..7e18896 100644 --- a/README.zh_CN.md +++ b/README.zh_CN.md @@ -1,12 +1,11 @@

+

rsw-rs

-「🌐 语言」[English](./README.md) - **`rsw = rs(rust) → w(wasm)`** - 基于 `wasm-pack` 实现的一个命令行工具,当本地文件变更时自动构建。 -## rsw-rs +**[English](./README.md) | 简体中文** ## 预安装 diff --git a/npm/package.json b/npm/package.json index 2fb38df..f0f8a6d 100644 --- a/npm/package.json +++ b/npm/package.json @@ -1,6 +1,6 @@ { "name": "@rsw/cli", - "version": "0.7.1", + "version": "0.7.2", "description": "🦞 wasm-pack based build tool", "main": "binary.js", "author": "lencx ", diff --git a/src/core/build.rs b/src/core/build.rs index c989366..526b69e 100644 --- a/src/core/build.rs +++ b/src/core/build.rs @@ -29,12 +29,17 @@ impl Build { let name = &config.name; let root = config.root.as_ref().unwrap(); let out_dir = config.out_dir.as_ref().unwrap(); - let crate_root = PathBuf::from(root) - .join(name) - .canonicalize().unwrap(); + let crate_root = PathBuf::from(root).join(name).canonicalize().unwrap(); let build_name = crate_root.to_string_lossy().to_string(); let target = config.target.as_ref().unwrap(); - let mut args = vec!["build", &build_name, "--out-dir", out_dir, "--target", target]; + let mut args = vec![ + "build", + &build_name, + "--out-dir", + out_dir, + "--target", + target, + ]; // profile let mut profile = config.build.as_ref().unwrap().profile.as_ref().unwrap(); @@ -97,9 +102,7 @@ impl Build { let cli = &self.cli; Link::new( cli.into(), - PathBuf::from(root) - .join(name) - .join(out_dir), + PathBuf::from(root).join(name).join(out_dir), name.to_string(), ) .init(); diff --git a/src/core/cli.rs b/src/core/cli.rs index 55bf60c..d1bc92f 100644 --- a/src/core/cli.rs +++ b/src/core/cli.rs @@ -7,8 +7,8 @@ use std::path::PathBuf; use std::rc::Rc; use crate::config::{CrateConfig, RswConfig}; -use crate::core::{Build, Clean, Create, Init, Link, Watch, RswErr}; -use crate::utils::{init_rsw_crates, rsw_watch_file, print}; +use crate::core::{Build, Clean, Create, Init, Link, RswErr, Watch}; +use crate::utils::{init_rsw_crates, print, rsw_watch_file}; #[derive(Parser)] #[clap(version, about, long_about = None)] @@ -106,16 +106,19 @@ impl Cli { let name = &i.name; let root = i.root.as_ref().unwrap(); let out = i.out_dir.as_ref().unwrap(); - let crate_out = PathBuf::from(root) - .join(name).join(out); + let crate_out = PathBuf::from(root).join(name).join(out); crates.push(format!( "{} :~> {}", name, - crate_out.canonicalize().unwrap_or_else(|e| { - print(RswErr::Crate(crate_out.to_string_lossy().to_string(), e)); - std::process::exit(1); - }).to_string_lossy().to_string() + crate_out + .canonicalize() + .unwrap_or_else(|e| { + print(RswErr::Crate(crate_out.to_string_lossy().to_string(), e)); + std::process::exit(1); + }) + .to_string_lossy() + .to_string() )); } init_rsw_crates(crates.join("\n").as_bytes()).unwrap(); diff --git a/src/utils.rs b/src/utils.rs index 9a8a264..e7a5bf2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -7,21 +7,20 @@ use std::{ path::{Path, PathBuf}, }; use toml::Value; +use which::which; use crate::config; use crate::core::RswErr; -// https://stackoverflow.com/questions/35045996/check-if-a-command-is-in-path-executable-as-process pub fn check_env_cmd(program: &str) -> bool { - if let Ok(path) = env::var("PATH") { - for p in path.split(":") { - let p_str = format!("{}/{}", p, program); - if fs::metadata(p_str).is_ok() { - return true; - } + let result = which(program); + match result { + Ok(_) => true, + Err(e) => { + eprint!("{}\n", e); + false } } - false } // get fields from `Cargo.toml`