Skip to content

Commit

Permalink
fix: check env
Browse files Browse the repository at this point in the history
  • Loading branch information
lencx committed Mar 4, 2022
1 parent 908ba21 commit ef7efa9
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 32 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.7.2

- fix: check env

## 0.7.1

- fix: crate root
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <cxin1314@gmail.com>"]
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
Expand All @@ -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"
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<p align="center">
<img src="./rsw.png" width="120">
<h2 align="center">rsw-rs</h2>
</p>

「🌐 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

Expand Down
5 changes: 2 additions & 3 deletions README.zh_CN.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<p align="center">
<img src="./rsw.png" width="120">
<h2 align="center">rsw-rs</h2>
</p>

「🌐 语言」[English](./README.md)

**`rsw = rs(rust) → w(wasm)`** - 基于 `wasm-pack` 实现的一个命令行工具,当本地文件变更时自动构建。

## rsw-rs
**[English](./README.md) | 简体中文**

## 预安装

Expand Down
2 changes: 1 addition & 1 deletion npm/package.json
Original file line number Diff line number Diff line change
@@ -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 <cxin1314@gmail.com>",
Expand Down
17 changes: 10 additions & 7 deletions src/core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
19 changes: 11 additions & 8 deletions src/core/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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();
Expand Down
15 changes: 7 additions & 8 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit ef7efa9

Please sign in to comment.