Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process crate names as Cargo does & use index.html as default target. #17

Merged
merged 1 commit into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ changelog
=========

## Unreleased
### fixed
- Closed [#15](https://github.com/thedodd/trunk/issues/15): ensure cargo package name is processed as cargo itself processes package names (`s/-/_/`).
- Closed [#16](https://github.com/thedodd/trunk/issues/16): default to `index.html` as the default target for all CLI commands which expect a target. This matches the expectation of Seed & Yew.

## 0.1.2
### changed
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn main() {
}
```

Trunk uses a source HTML file to drive all asset building and bundling. Trunk also ships with a [built-in SASS/SCSS compiler](https://github.com/compass-rs/sass-rs), so let's get started with the following example. Copy this HTML to your cargo project's `src` dir at `src/index.html`:
Trunk uses a source HTML file to drive all asset building and bundling. Trunk also ships with a [built-in SASS/SCSS compiler](https://github.com/compass-rs/sass-rs), so let's get started with the following example. Copy this HTML to the root of your project's repo as `index.html`:

```html
<html>
Expand All @@ -54,7 +54,7 @@ Trunk uses a source HTML file to drive all asset building and bundling. Trunk al
</html>
```

`trunk build src/index.html` will produce the following HTML at `dist/index.html`, along with the compiled SCSS, WASM & the JS loader for the WASM:
`trunk build` will produce the following HTML at `dist/index.html`, along with the compiled SCSS, WASM & the JS loader for the WASM:

```html
<html>
Expand All @@ -72,15 +72,15 @@ The contents of your `dist` dir are now ready to be served on the web. But that'

## commands
### build
`trunk build <src/index.html>` runs a cargo build targeting the wasm32 instruction set, runs `wasm-bindgen` on the built WASM, spawns asset build pipelines for any assets defined in the target `index.html`.
`trunk build [index.html]` runs a cargo build targeting the wasm32 instruction set, runs `wasm-bindgen` on the built WASM, spawns asset build pipelines for any assets defined in the target `index.html`.

Trunk leverages Rust's powerful concurrency primitives for maximum build speeds.

### watch
`trunk watch <src/index.html>` does the same thing as `trunk build`, but watches the filesystem for changes, triggering new builds as changes are detected.
`trunk watch [index.html]` does the same thing as `trunk build`, but watches the filesystem for changes, triggering new builds as changes are detected.

### serve
`trunk serve <src/index.html>` does the same thing as `trunk watch`, but also spawns a web server.
`trunk serve [index.html]` does the same thing as `trunk watch`, but also spawns a web server.

### clean
`trunk clean` cleans up any build artifacts generated from earlier builds.
Expand Down
6 changes: 5 additions & 1 deletion src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,12 @@ impl CargoManifest {
let manifest_path = get_cwd().await?.join("Cargo.toml");
let manifest_raw = fs::read_to_string(&manifest_path).await
.map_err(|err| anyhow!("error reading Cargo.toml file: {}", err))?;
let manifest: Self = toml::from_str(&manifest_raw)
let mut manifest: Self = toml::from_str(&manifest_raw)
.map_err(|err| anyhow!("error parsing Cargo.toml: {}", err))?;

// Update the package name to match what its output name will be.
manifest.package.name = manifest.package.name.replace("-", "_");

Ok(manifest)
}
}
2 changes: 1 addition & 1 deletion src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::common::parse_public_url;
#[structopt(name="build")]
pub struct Build {
/// The index HTML file to drive the bundling process.
#[structopt(parse(from_os_str))]
#[structopt(default_value="index.html", parse(from_os_str))]
target: PathBuf,

/// Build in release mode.
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::watch::WatchSystem;
#[structopt(name="serve")]
pub struct Serve {
/// The index HTML file to drive the bundling process.
#[structopt(parse(from_os_str))]
#[structopt(default_value="index.html", parse(from_os_str))]
target: PathBuf,

/// The port to serve on.
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::watch::WatchSystem;
#[structopt(name="watch")]
pub struct Watch {
/// The index HTML file to drive the bundling process.
#[structopt(parse(from_os_str))]
#[structopt(default_value="index.html", parse(from_os_str))]
target: PathBuf,

/// Build in release mode.
Expand Down