Skip to content

Commit ba5250b

Browse files
committed
Support building and serving examples
1 parent b41a957 commit ba5250b

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Subheadings to categorize changes are `added, changed, deprecated, removed, fixe
99
- Added `data-target-path` to `copy-dir`.
1010
- Allow processing `<script>` tags with the asset pipeline.
1111
- Added `data-loader-shim` to workers to create shim script.
12+
- Added `--example` command line option to `trunk build`, `serve` and `watch`.
1213
### changed
1314
- Updated gloo-worker example to use gloo-worker crate v2.1.
1415
- Our website (trunkrs.dev) now only updates on new releases.

src/config/models.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ pub struct ConfigOptsBuild {
4040
/// [default: ""]
4141
#[arg(long)]
4242
pub features: Option<String>,
43+
/// Whether to build an example.
44+
#[clap(long)]
45+
pub example: Option<String>,
4346
/// Whether to include hash values in the output file names [default: true]
4447
#[arg(long)]
4548
pub filehash: Option<bool>,
@@ -283,21 +286,8 @@ impl ConfigOpts {
283286
}
284287

285288
fn cli_opts_layer_build(cli: ConfigOptsBuild, cfg_base: Self) -> Self {
286-
let opts = ConfigOptsBuild {
287-
target: cli.target,
288-
release: cli.release,
289-
dist: cli.dist,
290-
public_url: cli.public_url,
291-
no_default_features: cli.no_default_features,
292-
all_features: cli.all_features,
293-
features: cli.features,
294-
filehash: cli.filehash,
295-
pattern_script: cli.pattern_script,
296-
pattern_preload: cli.pattern_preload,
297-
pattern_params: cli.pattern_params,
298-
};
299289
let cfg_build = ConfigOpts {
300-
build: Some(opts),
290+
build: Some(cli),
301291
watch: None,
302292
serve: None,
303293
clean: None,

src/config/rt.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ pub struct RtcBuild {
4343
pub staging_dist: PathBuf,
4444
/// The configuration of the features passed to cargo.
4545
pub cargo_features: Features,
46+
/// If set, the example passed to cargo.
47+
pub cargo_example: Option<String>,
4648
/// Configuration for automatic application download.
4749
pub tools: ConfigOptsTools,
4850
/// Build process hooks.
@@ -125,6 +127,7 @@ impl RtcBuild {
125127
staging_dist,
126128
final_dist,
127129
cargo_features,
130+
cargo_example: opts.example,
128131
tools,
129132
hooks,
130133
inject_autoloader,

src/pipelines/rust.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ pub struct RustApp {
3838
/// An optional binary name which will cause cargo & wasm-bindgen to process only the target
3939
/// binary.
4040
bin: Option<String>,
41+
/// An optional example to build.
42+
example: Option<String>,
4143
/// An option to instruct wasm-bindgen to preserve debug info in the final WASM output, even
4244
/// for `--release` mode.
4345
keep_debug: bool,
@@ -161,13 +163,16 @@ impl RustApp {
161163
}
162164
};
163165

166+
let example = cfg.cargo_example.clone();
167+
164168
Ok(Self {
165169
id,
166170
cfg,
167171
cargo_features,
168172
manifest,
169173
ignore_chan,
170174
bin,
175+
example,
171176
keep_debug,
172177
typescript,
173178
no_demangle,
@@ -196,6 +201,7 @@ impl RustApp {
196201
manifest,
197202
ignore_chan,
198203
bin: None,
204+
example: None,
199205
keep_debug: false,
200206
typescript: false,
201207
no_demangle: false,
@@ -240,6 +246,10 @@ impl RustApp {
240246
args.push("--bin");
241247
args.push(bin);
242248
}
249+
if let Some(example) = &self.example {
250+
args.push("--example");
251+
args.push(example);
252+
}
243253

244254
match &self.cargo_features {
245255
Features::All => args.push("--all-features"),

0 commit comments

Comments
 (0)