Skip to content

Commit

Permalink
specialize cargo-generated README
Browse files Browse the repository at this point in the history
  • Loading branch information
Madoshakalaka committed Feb 25, 2025
1 parent 9681c02 commit a1b4c61
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ There is, however, a fair bit of Sass in [index.scss](index.scss) you can remove

### Update metadata

Update the `version`, `description` and `repository` fields in the [Cargo.toml](Cargo.toml) file.
Update the `name`, `version`, `description` and `repository` fields in the [Cargo.toml](Cargo.toml) file.
The [index.html](index.html) file also contains a `<title>` tag that needs updating.

If you cloned this repo without using `cargo generate`, you can safely remove the `cargo-generate` directory.
Expand Down
75 changes: 71 additions & 4 deletions cargo-generate/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,75 @@
If you are a developer of this template repository
# Yew Trunk Template

This is a fairly minimal template for a Yew app that's built with [Trunk].

## Usage

For a more thorough explanation of Trunk and its features, please head over to the [repository][trunk].

### Installation

If you don't already have it installed, it's time to install Rust: <https://www.rust-lang.org/tools/install>.
The rest of this guide assumes a typical Rust installation which contains both `rustup` and Cargo.

To compile Rust to WASM, we need to have the `wasm32-unknown-unknown` target installed.
If you don't already have it, install it with the following command:

```bash
rustup target add wasm32-unknown-unknown
```
cd cargo-gen-gen
cargo run

Now that we have our basics covered, it's time to install the star of the show: [Trunk].
Simply run the following command to install it:

```bash
cargo install trunk wasm-bindgen-cli
```

That's it, we're done!

### Running

```bash
trunk serve
```

Rebuilds the app whenever a change is detected and runs a local server to host it.

There's also the `trunk watch` command which does the same thing but without hosting it.

### Release

```bash
trunk build --release
```

will generate you new file templates for cargo-generate to use.
This builds the app in release mode similar to `cargo build --release`.
You can also pass the `--release` flag to `trunk serve` if you need to get every last drop of performance.

Unless overwritten, the output will be located in the `dist` directory.

## Using this template

There are a few things you have to adjust when adopting this template.

### Remove example code

The code in [src/main.rs](src/main.rs) specific to the example is limited to only the `view` method.
There is, however, a fair bit of Sass in [index.scss](index.scss) you can remove.

### Update metadata

Update the `version`, `description` and `repository` fields in the [Cargo.toml](Cargo.toml) file.
The [index.html](index.html) file also contains a `<title>` tag that needs updating.


Finally, you should update this very `README` file to be about your app.

### License

The template ships with both the Apache and MIT license.
If you don't want to have your app dual licensed, just remove one (or both) of the files and update the `license` field in `Cargo.toml`.

There are two empty spaces in the MIT license you need to fill out: `{{year}}` and `{{authors}}`.

[trunk]: https://github.com/thedodd/trunk
14 changes: 14 additions & 0 deletions cargo-generate/cargo-gen-gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,18 @@ fn main() {
template_manifest_dir.join("Cargo.toml"),
)
.unwrap();

let md = std::fs::read_to_string(template_manifest_dir.join("README.md")).unwrap();
let update_instruction = "Update the `name`,";
assert_eq!(md.match_indices(update_instruction).count(), 1);
let new_md = md.replace(update_instruction, "Update the");
let if_you_cloned = "If you cloned";
assert_eq!(new_md.match_indices(if_you_cloned).count(), 1);
let new_md = new_md
.lines()
.filter(|l| !l.starts_with(if_you_cloned))
.collect::<Vec<&str>>()
.join("\n");

std::fs::write(cargo_gen_dir.join("README.md"), new_md).unwrap();
}
4 changes: 1 addition & 3 deletions cargo-generate/configure_files.rhai
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
file::delete("Cargo.toml");
file::delete("Cargo.lock");

switch variable::get("yew_version"){
"stable" => {
file::rename("cargo-generate/Cargo.lock", "Cargo.lock");
Expand All @@ -11,6 +8,7 @@ switch variable::get("yew_version"){
file::rename("cargo-generate/Cargo.toml.next", "Cargo.toml");
}
}
file::rename("cargo-generate/README.md", "README.md");

file::delete("cargo-generate");
file::delete(".github");

0 comments on commit a1b4c61

Please sign in to comment.