collin/browser-terminal-extension · 09d8336c
Rebuild dist/ from a post-commit hook
Collin Richards · 2026-08-18 07:14 UTC · 09d8336c755f5f0dfb597aa2cd5b279744bf09c4 · parent a17d7d00 · browse files
added.githooks/post-commit+35 −0
| 1 | + | #!/usr/bin/env sh | |
| 2 | + | # Rebuild dist/ after a commit that touched the extension. | |
| 3 | + | # | |
| 4 | + | # The browser loads dist/, never extension/, so an edit under extension/ does | |
| 5 | + | # nothing until build.sh runs. Committing is the moment you believe the edit is | |
| 6 | + | # finished, which makes it the right moment to put it where the browser can see | |
| 7 | + | # it. Nothing here reloads the sidebar — that is still a click. | |
| 8 | + | # | |
| 9 | + | # Enable it once per clone: | |
| 10 | + | # | |
| 11 | + | # git config core.hooksPath .githooks | |
| 12 | + | # | |
| 13 | + | # Hooks are not versioned in .git/hooks, so this directory is the copy that | |
| 14 | + | # travels with the repo and that config line is what points git at it. | |
| 15 | + | set -eu | |
| 16 | + | ||
| 17 | + | root=$(git rev-parse --show-toplevel) | |
| 18 | + | ||
| 19 | + | # Only the extension half is built here, so only its files are worth a rebuild. | |
| 20 | + | # --root makes the first commit in a repo list its files instead of nothing. | |
| 21 | + | if ! git diff-tree --no-commit-id --name-only -r --root HEAD | grep -q '^extension/'; then | |
| 22 | + | exit 0 | |
| 23 | + | fi | |
| 24 | + | ||
| 25 | + | # build.sh ends with a paragraph about loading the unpacked extension, which is | |
| 26 | + | # not news to someone who already has it loaded. Kept only if the build fails. | |
| 27 | + | if out=$("$root/build.sh" 2>&1); then | |
| 28 | + | echo "post-commit: rebuilt dist/chrome and dist/firefox" | |
| 29 | + | else | |
| 30 | + | echo "post-commit: build.sh failed" >&2 | |
| 31 | + | echo "$out" >&2 | |
| 32 | + | fi | |
| 33 | + | ||
| 34 | + | # A failed build must not read as a failed commit: the commit already happened. | |
| 35 | + | exit 0 |
modifiedCLAUDE.md+12 −0
| ⋯ 27 unchanged lines | |||
| 28 | 28 | `extension/mock.html` is deliberately excluded: it renders the sidebar header in | |
| 29 | 29 | a plain tab for layout work, outside the extension. | |
| 30 | 30 | ||
| 31 | + | `.githooks/post-commit` runs `build.sh` after any commit that touched | |
| 32 | + | `extension/`, so a committed change is at least *in* `dist/`. Enable it once per | |
| 33 | + | clone (hooks live outside the repo, so this is what points git at the tracked | |
| 34 | + | copy): | |
| 35 | + | ||
| 36 | + | ```sh | |
| 37 | + | git config core.hooksPath .githooks | |
| 38 | + | ``` | |
| 39 | + | ||
| 40 | + | It does not reload the sidebar, and it does nothing for an uncommitted edit — | |
| 41 | + | `./build.sh` by hand is still the loop while you are working. | |
| 42 | + | ||
| 31 | 43 | ## Checks | |
| 32 | 44 | ||
| 33 | 45 | ```sh | |
| ⋯ 41 unchanged lines | |||