Skip to content

Commit

Permalink
fix: crate root
Browse files Browse the repository at this point in the history
  • Loading branch information
lencx committed Mar 3, 2022
1 parent c093094 commit 908ba21
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 44 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.1

- fix: crate root

## 0.7.0

- add `.rsw/rsw.crates`
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rsw"
version = "0.7.0"
version = "0.7.1"
description = "wasm-pack based build tool"
edition = "2021"
authors = ["lencx <cxin1314@gmail.com>"]
Expand Down
18 changes: 1 addition & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,6 @@

## rsw-rs

### Feature

- rsw init
- rsw watch
- rsw build
- rsw new
- `wasm-pack`
- `rsw`
- `user`
- debug info

### TODO

- local sub-dependency file changes trigger hot updates
- integrate front-end scaffolding, such as `vite`, `webpack`, etc.

## Pre-installed

- [rust](https://www.rust-lang.org/learn/get-started)
Expand Down Expand Up @@ -62,9 +46,9 @@ rsw clean

## Awesome rsw

- [[rsw demo] learn-wasm](https://github.com/lencx/learn-wasm) - 🎲 Learning WebAssembly
- [vite-plugin-rsw](https://github.com/lencx/vite-plugin-rsw) - 🦀 wasm-pack plugin for Vite
- [create-mpl](https://github.com/lencx/create-mpl) - ⚡️ Create a project in seconds!
- [learn-wasm](https://github.com/lencx/learn-wasm) - 🎲 Learning WebAssembly

## Logger

Expand Down
15 changes: 1 addition & 14 deletions README.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,6 @@

## rsw-rs

### 功能

- `rsw init` - 生成配置文件 `rsw.toml`
- `rsw build` - 基于 `rsw.toml` 配置同时构建多个 `rust crate`
- `rsw watch` - 基于 `rsw.toml` 配置同时监听多个 `rust crate` 中的文件变更,自动触发构建
- `rsw new` - 基于 `rsw.toml` `[new]` 字段配置,默认使用 `wasm-pack` 创建项目
- `RUST_LOG=rsw rsw <SUBCOMMAND>` - 输出关键日志信息,便于错误排查

## TODO

- 本地依赖变更触发热更新
- 集成前端脚手架,如 `vite``webpack`

## 预安装

- [rust](https://www.rust-lang.org/learn/get-started)
Expand Down Expand Up @@ -59,9 +46,9 @@ rsw clean

## Awesome rsw

- [[rsw demo] learn-wasm](https://github.com/lencx/learn-wasm) - 🎲 Learning WebAssembly
- [vite-plugin-rsw](https://github.com/lencx/vite-plugin-rsw) - 🦀 wasm-pack plugin for Vite
- [create-mpl](https://github.com/lencx/create-mpl) - ⚡️ Create a project in seconds!
- [learn-wasm](https://github.com/lencx/learn-wasm) - 🎲 Learning WebAssembly

## 日志

Expand Down
13 changes: 13 additions & 0 deletions npm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@
- [nodejs](https://nodejs.org)
- [wasm-pack](https://github.com/rustwasm/wasm-pack)

## Quick start

```bash
# https://github.com/lencx/create-mpl
# npm 6.x
npm init mpl@latest my-app --type wasm

# npm 7+, extra double-dash is needed:
npm init mpl@latest my-app -- --type wasm
```

---

## Usgae

```bash
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.0",
"version": "0.7.1",
"description": "🦞 wasm-pack based build tool",
"main": "binary.js",
"author": "lencx <cxin1314@gmail.com>",
Expand Down
14 changes: 10 additions & 4 deletions src/core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ impl Build {
let config = &self.config;
let rsw_type = &self.rsw_type;
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 build_name = crate_root.to_string_lossy().to_string();
let target = config.target.as_ref().unwrap();
let mut args = vec!["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 All @@ -46,7 +51,7 @@ impl Build {
args.push(scope.as_str());
}

let metadata = get_crate_metadata(name.as_str());
let metadata = get_crate_metadata(name, crate_root);
info!("🚧 wasm-pack {}", args.join(" "));

let status = Command::new("wasm-pack")
Expand Down Expand Up @@ -88,12 +93,13 @@ impl Build {
None => {}
}

// TODO: link
if config.link.unwrap() {
let cli = &self.cli;
Link::new(
cli.into(),
PathBuf::from(name).join(out_dir),
PathBuf::from(root)
.join(name)
.join(out_dir),
name.to_string(),
)
.init();
Expand Down
14 changes: 10 additions & 4 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};
use crate::utils::{init_rsw_crates, rsw_watch_file};
use crate::core::{Build, Clean, Create, Init, Link, Watch, RswErr};
use crate::utils::{init_rsw_crates, rsw_watch_file, print};

#[derive(Parser)]
#[clap(version, about, long_about = None)]
Expand Down Expand Up @@ -104,19 +104,25 @@ impl Cli {
let mut crates = Vec::new();
for i in &config.crates {
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);

crates.push(format!(
"{} :~> {}",
name,
PathBuf::from(name).join(out).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();

config
}
pub fn wp_build(config: Rc<RswConfig>, rsw_type: &str) {
// let crates_map = Rc::new(RefCell::new(HashMap::new()));
let crates_map = Rc::new(RefCell::new(HashMap::new()));

let cli = &config.cli.to_owned().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/core/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Link {

pub fn yarn_link(&self) {
// register package
// 1. cd <name>
// 1. cd <root>/<name>
// 2. yarn link
Command::new(&self.cli)
.current_dir(&self.cwd)
Expand Down
4 changes: 2 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub fn check_env_cmd(program: &str) -> bool {
}

// get fields from `Cargo.toml`
pub fn get_crate_metadata(name: &str) -> Value {
let crate_root = env::current_dir().unwrap().join(name).join("Cargo.toml");
pub fn get_crate_metadata(name: &str, root: PathBuf) -> Value {
let crate_root = root.join("Cargo.toml");
let content = fs::read_to_string(crate_root).unwrap_or_else(|e| {
// TODO: create crate
print(RswErr::Crate(name.to_string(), e));
Expand Down

0 comments on commit 908ba21

Please sign in to comment.