Skip to content

Commit 5904c99

Browse files
authored
Merge pull request #17 from thedodd/crate-name-and-index-html
Process crate names as Cargo does & use `index.html` as default target.
2 parents 85462cf + f4d5c0c commit 5904c99

File tree

6 files changed

+16
-9
lines changed

6 files changed

+16
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ changelog
22
=========
33

44
## Unreleased
5+
### fixed
6+
- Closed [#15](https://github.com/thedodd/trunk/issues/15): ensure cargo package name is processed as cargo itself processes package names (`s/-/_/`).
7+
- 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.
58

69
## 0.1.2
710
### changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn main() {
4444
}
4545
```
4646

47-
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`:
47+
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`:
4848

4949
```html
5050
<html>
@@ -54,7 +54,7 @@ Trunk uses a source HTML file to drive all asset building and bundling. Trunk al
5454
</html>
5555
```
5656

57-
`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:
57+
`trunk build` will produce the following HTML at `dist/index.html`, along with the compiled SCSS, WASM & the JS loader for the WASM:
5858

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

7373
## commands
7474
### build
75-
`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`.
75+
`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`.
7676

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

7979
### watch
80-
`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.
80+
`trunk watch [index.html]` does the same thing as `trunk build`, but watches the filesystem for changes, triggering new builds as changes are detected.
8181

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

8585
### clean
8686
`trunk clean` cleans up any build artifacts generated from earlier builds.

src/build.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,12 @@ impl CargoManifest {
441441
let manifest_path = get_cwd().await?.join("Cargo.toml");
442442
let manifest_raw = fs::read_to_string(&manifest_path).await
443443
.map_err(|err| anyhow!("error reading Cargo.toml file: {}", err))?;
444-
let manifest: Self = toml::from_str(&manifest_raw)
444+
let mut manifest: Self = toml::from_str(&manifest_raw)
445445
.map_err(|err| anyhow!("error parsing Cargo.toml: {}", err))?;
446+
447+
// Update the package name to match what its output name will be.
448+
manifest.package.name = manifest.package.name.replace("-", "_");
449+
446450
Ok(manifest)
447451
}
448452
}

src/cmd/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::common::parse_public_url;
1111
#[structopt(name="build")]
1212
pub struct Build {
1313
/// The index HTML file to drive the bundling process.
14-
#[structopt(parse(from_os_str))]
14+
#[structopt(default_value="index.html", parse(from_os_str))]
1515
target: PathBuf,
1616

1717
/// Build in release mode.

src/cmd/serve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::watch::WatchSystem;
1616
#[structopt(name="serve")]
1717
pub struct Serve {
1818
/// The index HTML file to drive the bundling process.
19-
#[structopt(parse(from_os_str))]
19+
#[structopt(default_value="index.html", parse(from_os_str))]
2020
target: PathBuf,
2121

2222
/// The port to serve on.

src/cmd/watch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::watch::WatchSystem;
1111
#[structopt(name="watch")]
1212
pub struct Watch {
1313
/// The index HTML file to drive the bundling process.
14-
#[structopt(parse(from_os_str))]
14+
#[structopt(default_value="index.html", parse(from_os_str))]
1515
target: PathBuf,
1616

1717
/// Build in release mode.

0 commit comments

Comments
 (0)