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

Add hooks #221

Merged
merged 9 commits into from
Aug 20, 2021
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ This changelog follows the patterns described here: https://keepachangelog.com/e
Subheadings to categorize changes are `added, changed, deprecated, removed, fixed, security`.

## Unreleased
### added
- Trunk now includes a hooks system. This improves many use cases where another build tool is needed alongside trunk, by allowing trunk to be configured to call them at various stages during the build pipeline. It is configured under `[[hooks]]` in `Trunk.toml`. More information can be found in the [Assets](https://trunkrs.dev/assets/) section of the docs.
- Added `trunk serve` autoreload triggered over websocket that reloads the page when a change is detected. The `--no-autoreload` flag disables this feature.

## 0.13.1
Expand Down
29 changes: 29 additions & 0 deletions Trunk.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,32 @@ backend = "http://localhost:9000/"
# This proxy specifies only the backend, which is the only required field. In this example,
# request URIs are not modified when proxied.
backend = "http://localhost:9000/api/v2/"

## hooks
# Hooks are optional, and default to `None`.
# Hooks are executed as part of Trunk's main build pipeline, no matter how it is run.

[[hooks]]
# This hook example shows all the current available fields. It will execute the equivalent of
# typing "echo Hello Trunk!" right at the start of the build process (even before the HTML file
# is read). By default, the command is spawned directly and no shell is used.
stage = "pre_build"
command = "echo"
command_arguments = ["Hello", "Trunk!"]

[[hooks]]
# This hook example shows running a command inside a shell. As a result, features such as variable
# interpolation are available. This shows the TRUNK_STAGING_DIR environment variable, one of a set
# of default variables that Trunk inserts into your hook's environment. Additionally, this hook
# uses the build stage, meaning it executes in parallel with all of the existing asset pipelines.
stage = "build"
command = "sh"
command_arguments = ["-c", "echo Staging directory: $TRUNK_STAGING_DIR"]

[[hooks]]
# This hook example shows how command_arguments defaults to an empty list when absent. It also uses
# the post_build stage, meaning it executes after the rest of the build is complete, just before
# the staging directory is copied over the dist directory. This means that it has access to all
# built assets, including the HTML file generated by trunk.
stage = "post_build"
command = "ls"
Loading