├── .github └── workflows │ └── release.yml ├── .gitignore ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE ├── README.md ├── README.zh_CN.md ├── npm ├── .gitignore ├── README.md ├── binary.js ├── install.js ├── package.json └── run.js ├── rsw.png └── src ├── config.rs ├── core ├── build.rs ├── clean.rs ├── cli.rs ├── create.rs ├── error.rs ├── info.rs ├── init.rs ├── link.rs ├── mod.rs └── watch.rs ├── lib.rs ├── main.rs ├── template ├── mod.rs ├── rsw.toml ├── rsw_cargo.toml ├── rsw_lib.rs └── rsw_readme.md └── utils.rs /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | tags: 4 | - 'v*' # Run when tag matches v*, i.e. v1.0, v20.15.10 5 | 6 | name: Release 7 | 8 | env: 9 | RELEASE_BIN: rsw 10 | RELEASE_DIR: artifacts 11 | GITHUB_REF: '${{ github.ref }}' 12 | WINDOWS_TARGET: x86_64-pc-windows-msvc 13 | MACOS_TARGET: x86_64-apple-darwin 14 | LINUX_AMD64_TARGET: x86_64-unknown-linux-musl 15 | LINUX_ARM64_TARGET: aarch64-unknown-linux-musl 16 | 17 | # Space separated paths to include in the archive. 18 | RELEASE_ADDS: README.md LICENSE 19 | 20 | jobs: 21 | build: 22 | name: Build artifacts 23 | runs-on: ${{ matrix.os }} 24 | strategy: 25 | matrix: 26 | include: 27 | - target: x86_64-unknown-linux-musl 28 | os: ubuntu-latest 29 | rust: stable 30 | - target: aarch64-unknown-linux-musl 31 | os: ubuntu-latest 32 | rust: stable 33 | - target: x86_64-apple-darwin 34 | os: macos-latest 35 | rust: stable 36 | - target: x86_64-pc-windows-msvc 37 | os: windows-latest 38 | rust: stable 39 | 40 | steps: 41 | - uses: actions/checkout@v2 42 | - uses: actions-rs/toolchain@v1 43 | with: 44 | toolchain: ${{ matrix.rust }} 45 | override: true 46 | target: wasm32-unknown-unknown 47 | 48 | - name: Query version number 49 | id: get_version 50 | shell: bash 51 | run: | 52 | echo "using version tag ${GITHUB_REF:10}" 53 | echo ::set-output name=version::"${GITHUB_REF:10}" 54 | - name: Install C compilation tooling (Linux) 55 | if: matrix.os == 'ubuntu-latest' 56 | run: | 57 | sudo apt-get update -y 58 | sudo apt-get install clang gcc-aarch64-linux-gnu -y 59 | echo "TARGET_CC=clang" >> $GITHUB_ENV 60 | echo "CFLAGS_aarch64_unknown_linux_musl=--sysroot=/usr/aarch64-linux-gnu" >> $GITHUB_ENV 61 | echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=/usr/aarch64-linux-gnu/bin/ld" >> $GITHUB_ENV 62 | - name: Install p7zip (MacOS) 63 | if: matrix.os == 'macos-latest' 64 | run: brew install p7zip 65 | 66 | - name: Add rustup target 67 | run: rustup target add ${{ matrix.target }} 68 | 69 | - name: Build 70 | run: cargo build --release --target ${{ matrix.target }} 71 | 72 | - name: Set RUSTFLAGS (Windows) 73 | if: matrix.os == 'windows-latest' 74 | run: echo "RUSTFLAGS=-Ctarget-feature=+crt-static" >> $GITHUB_ENV 75 | 76 | - name: Create artifact directory 77 | run: | 78 | mkdir ${{ env.RELEASE_DIR }} 79 | mkdir -p ${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }} 80 | - name: Move binaries (Linux/MacOS) 81 | if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' 82 | run: | 83 | mv ./target/${{ matrix.target }}/release/${{ env.RELEASE_BIN }} ${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }}/${{ env.RELEASE_BIN }} 84 | mv ${{ env.RELEASE_ADDS }} ./${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }} 85 | - name: Move binaries (Windows) 86 | if: matrix.os == 'windows-latest' 87 | shell: bash 88 | run: | 89 | cp ./target/${{ matrix.target }}/release/${{ env.RELEASE_BIN }}.exe ./${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }}/${{ env.RELEASE_BIN }}.exe 90 | cp ./target/${{ matrix.target }}/release/${{ env.RELEASE_BIN }}.exe rsw.exe 91 | mv ${{ env.RELEASE_ADDS }} ./${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }} 92 | mv rsw.exe ${{ env.RELEASE_DIR }} 93 | - name: Create tarball 94 | run: 7z a -ttar -so -an ./${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }} | 7z a -si ./${{ env.RELEASE_DIR }}/${{ env.RELEASE_BIN }}-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }}.tar.gz 95 | 96 | - name: Upload Zip 97 | uses: actions/upload-artifact@v1 98 | with: 99 | name: ${{ matrix.target }} 100 | path: ./${{ env.RELEASE_DIR }} 101 | 102 | release: 103 | name: GitHub Release 104 | needs: build 105 | runs-on: ubuntu-latest 106 | steps: 107 | - name: Query version number 108 | id: get_version 109 | shell: bash 110 | run: | 111 | echo "using version tag ${GITHUB_REF:10}" 112 | echo ::set-output name=version::"${GITHUB_REF:10}" 113 | - name: Create Release 114 | id: create_release 115 | uses: actions/create-release@v1 116 | env: 117 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 118 | with: 119 | tag_name: ${{ steps.get_version.outputs.VERSION }} 120 | release_name: ${{ steps.get_version.outputs.VERSION }} 121 | 122 | - name: Download Linux amd64 tarball 123 | uses: actions/download-artifact@v2 124 | with: 125 | name: ${{ env.LINUX_AMD64_TARGET }} 126 | 127 | - name: Download Linux arm64 tarball 128 | uses: actions/download-artifact@v2 129 | with: 130 | name: ${{ env.LINUX_ARM64_TARGET }} 131 | 132 | - name: Download Windows tarball 133 | uses: actions/download-artifact@v2 134 | with: 135 | name: ${{ env.WINDOWS_TARGET }} 136 | 137 | - name: Download MacOS tarball 138 | uses: actions/download-artifact@v2 139 | with: 140 | name: ${{ env.MACOS_TARGET }} 141 | 142 | - name: Release Linux amd64 tarball 143 | uses: actions/upload-release-asset@v1 144 | env: 145 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 146 | with: 147 | upload_url: ${{ steps.create_release.outputs.upload_url }} 148 | asset_path: ./rsw-${{ steps.get_version.outputs.VERSION }}-${{ env.LINUX_AMD64_TARGET }}.tar.gz 149 | asset_content_type: application/gzip 150 | asset_name: rsw-${{ steps.get_version.outputs.VERSION }}-${{ env.LINUX_AMD64_TARGET }}.tar.gz 151 | 152 | - name: Release Linux arm64 tarball 153 | uses: actions/upload-release-asset@v1 154 | env: 155 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 156 | with: 157 | upload_url: ${{ steps.create_release.outputs.upload_url }} 158 | asset_path: ./rsw-${{ steps.get_version.outputs.VERSION }}-${{ env.LINUX_ARM64_TARGET }}.tar.gz 159 | asset_content_type: application/gzip 160 | asset_name: rsw-${{ steps.get_version.outputs.VERSION }}-${{ env.LINUX_ARM64_TARGET }}.tar.gz 161 | 162 | - name: Release Windows tarball 163 | uses: actions/upload-release-asset@v1 164 | env: 165 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 166 | with: 167 | upload_url: ${{ steps.create_release.outputs.upload_url }} 168 | asset_path: ./rsw-${{ steps.get_version.outputs.VERSION }}-${{ env.WINDOWS_TARGET }}.tar.gz 169 | asset_content_type: application/gzip 170 | asset_name: rsw-${{ steps.get_version.outputs.VERSION }}-${{ env.WINDOWS_TARGET }}.tar.gz 171 | 172 | - name: Release Windows init exe 173 | uses: actions/upload-release-asset@v1 174 | env: 175 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 176 | with: 177 | upload_url: ${{ steps.create_release.outputs.upload_url }} 178 | asset_path: ./rsw.exe 179 | asset_content_type: application/vnd.microsoft.portable-executable 180 | asset_name: rsw.exe 181 | 182 | - name: Release MacOS tarball 183 | uses: actions/upload-release-asset@v1 184 | env: 185 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 186 | with: 187 | upload_url: ${{ steps.create_release.outputs.upload_url }} 188 | asset_path: ./rsw-${{ steps.get_version.outputs.VERSION }}-${{ env.MACOS_TARGET }}.tar.gz 189 | asset_content_type: application/gzip 190 | asset_name: rsw-${{ steps.get_version.outputs.VERSION }}-${{ env.MACOS_TARGET }}.tar.gz -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | target/ 4 | Cargo.lock 5 | 6 | node_modules/ 7 | yarn.lock 8 | package-lock.json 9 | 10 | /rsw.toml 11 | /@rsw 12 | /rsw-* 13 | /.rsw 14 | /.watchignore 15 | 16 | # IDE 17 | .vscode/ 18 | .idea/ 19 | /npm/bin/ -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 0.8.0 4 | 5 | - feat: `rsw.toml` adds `scope` field 6 | 7 | ## 0.7.12 8 | 9 | - fix: `config.cli` optional with default to `npm` 10 | 11 | ## 0.7.11 12 | 13 | - fix: watch mode in windows doesn't refresh 14 | 15 | ## 0.7.10 16 | 17 | - fix: build link 18 | 19 | ## 0.7.7 20 | 21 | - fix: npm binary install 22 | 23 | ## 0.7.6 24 | 25 | - feat: watch abort 26 | 27 | ## 0.7.5 28 | 29 | - feat: add .watchignore 30 | 31 | ## 0.7.4 32 | 33 | - fix: yarn link 34 | 35 | ## 0.7.3 36 | 37 | - fix: path clean 38 | - fix: `rsw.toml` - the `run` field is invalid 39 | 40 | ## 0.7.2 41 | 42 | - fix: check env 43 | 44 | ## 0.7.1 45 | 46 | - fix: crate root 47 | 48 | ## 0.7.0 49 | 50 | - add `.rsw/rsw.crates` 51 | 52 | ## 0.6.0 53 | 54 | - add `.rsw` dir 55 | 56 | ## 0.5.0 57 | 58 | - link - npm, yarn or pnpm 59 | - rsw clean - link & build 60 | 61 | ## 0.4.0 62 | 63 | - rsw.log - generate log files in watch mode 64 | 65 | ## 0.3.0 66 | 67 | - npm install 68 | 69 | ## 0.2.0 70 | 71 | - rsw new (rsw | user) 72 | - add logger 73 | 74 | ## 0.1.0 75 | 76 | - rsw new (wasm-pack new) 77 | - rsw init - generate `rsw.toml` 78 | - rsw watch 79 | 80 | ## 0.0.2 81 | 82 | - rsw build 83 | - rsw.toml 84 | 85 | ## 0.0.1 86 | 87 | Initial release. 88 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rsw" 3 | version = "0.8.0" 4 | description = "wasm-pack based build tool" 5 | edition = "2021" 6 | authors = ["lencx "] 7 | homepage = "https://github.com/lencx/rsw-rs" 8 | repository = "https://github.com/lencx/rsw-rs" 9 | keywords = ["rsw", "wasm-pack", "webassembly", "wasm", "npm"] 10 | license = "MIT" 11 | 12 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 13 | 14 | [dependencies] 15 | anyhow = "1.0.52" 16 | clap = { version = "3.0.5", features = ["derive"] } 17 | colored = "2.0.0" 18 | env_logger = "0.9.0" 19 | log = "0.4.14" 20 | notify = "4.0.17" 21 | path-clean = "0.1.0" 22 | regex = "1.5.4" 23 | serde = "1.0.133" 24 | serde_derive = "1.0.133" 25 | toml = "0.5.8" 26 | which = "4.2.5" 27 | ignore = "0.4.18" 28 | tokio = { version = "1.18.0", features = ["macros", "rt-multi-thread"] } 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 lencx 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

rsw-rs

4 |

5 | 6 | **`rsw = rs(rust) → w(wasm)`** - A command-line tool for automatically rebuilding local changes, based on the `wasm-pack` implementation. 7 | 8 | [![Crate Info](https://img.shields.io/crates/v/rsw.svg)](https://crates.io/crates/rsw) 9 | [![API Docs](https://img.shields.io/badge/docs.rs-rsw-654FF0)](https://docs.rs/rsw) 10 | 11 | **Englist | [简体中文](./README.zh_CN.md)** 12 | 13 | ## Pre-installed 14 | 15 | - [rust](https://www.rust-lang.org/learn/get-started) 16 | - [nodejs](https://nodejs.org) 17 | - [wasm-pack](https://github.com/rustwasm/wasm-pack) 18 | 19 | ## Usage 20 | 21 | ```bash 22 | # Rust - install globally 23 | cargo install rsw 24 | ``` 25 | 26 | ```bash 27 | # help 28 | rsw -h 29 | 30 | # rsw.toml - initial configuration 31 | rsw init 32 | 33 | # generate a wasm project 34 | rsw new 35 | 36 | # dev mode 37 | rsw watch 38 | 39 | # release mode 40 | rsw build 41 | 42 | # clean - link & build 43 | rsw clean 44 | ``` 45 | 46 | ## Awesome rsw 47 | 48 | - [[rsw demo] learn-wasm](https://github.com/lencx/learn-wasm) - 🎲 Learning WebAssembly 49 | - [vite-plugin-rsw](https://github.com/lencx/vite-plugin-rsw) - 🦀 wasm-pack plugin for Vite 50 | - [create-mpl](https://github.com/lencx/create-mpl) - ⚡️ Create a project in seconds! 51 | - [Oh My Box](https://github.com/lencx/OhMyBox) - 🔮 Development toolbox, and more... 52 | 53 | ## Logger 54 | 55 | ```bash 56 | # @see: https://github.com/env-logger-rs/env_logger 57 | # RUST_LOG=rsw= rsw 58 | # 1. info 59 | RUST_LOG=rsw=info rsw 60 | 61 | # 2. all: info, trace, debug, error, warn 62 | RUST_LOG=rsw rsw 63 | ``` 64 | 65 | ### .watchignore 66 | 67 | Defines files/paths to be ignored. Similar to `.gitignore`. 68 | 69 | Example: 70 | 71 | ```bash 72 | # .watchignore 73 | *.js 74 | a/b/**/*.txt 75 | !a/b/**/main.txt 76 | ``` 77 | 78 | ## rsw.toml 79 | 80 | > configuration file 81 | 82 | - [TOML Doc](https://toml.io/en/) 83 | - [`wasm-pack build` Doc](https://rustwasm.github.io/docs/wasm-pack/commands/build.html) 84 | 85 | ### Options 86 | 87 | Create `rsw.toml` in the project root path, configure the `rust crate` parameter, and run the `rsw watch` or `rsw build` command. 88 | 89 | - **`name`** - Profile name (optional) 90 | - **`version`** - Profile version (optional) 91 | - **`interval`** - Development mode `rsw watch`, time interval for file changes to trigger `wasm-pack build`, default `50` milliseconds 92 | - **`cli`** - `npm` | `yarn` | `pnpm`, default is `npm`. Execute `link` using the specified `cli`, e.g. `npm link` 93 | - **`[new]`** - Quickly generate a crate with `wasm-pack new`, or set a custom template in `rsw.toml -> [new] -> using` 94 | - **`using`** - `wasm-pack` | `rsw` | `user`, default is `wasm-pack` 95 | - `wasm-pack` - `rsw new --template