feat(infra): add command path resolution with PATH fallbacks
This commit is contained in:
parent
ad1405bb12
commit
646fc2ba50
2 changed files with 86 additions and 2 deletions
70
.cursor/rules/command-paths.mdc
Normal file
70
.cursor/rules/command-paths.mdc
Normal file
|
@ -0,0 +1,70 @@
|
|||
---
|
||||
description: Standards for handling command paths in scripts, preferring PATH over absolute paths
|
||||
globs: **/*.{sh,bash}
|
||||
---
|
||||
<rule>
|
||||
When writing scripts that use external commands:
|
||||
|
||||
1. Always try PATH first:
|
||||
```bash
|
||||
if command -v COMMAND >/dev/null 2>&1; then
|
||||
CMD="COMMAND"
|
||||
else
|
||||
CMD="/absolute/path/to/COMMAND"
|
||||
fi
|
||||
```
|
||||
|
||||
2. Known fallback paths:
|
||||
- Bun: $HOME/.bun/bin/bun
|
||||
- Go: /usr/local/go/bin/go
|
||||
|
||||
3. Guidelines:
|
||||
- Use command -v to check if command exists in PATH
|
||||
- Store command path in a variable for reuse
|
||||
- Use meaningful variable names (e.g., BUN_CMD, GO_CMD)
|
||||
- Document why absolute paths are needed as fallback
|
||||
- Consider environment-specific paths
|
||||
- Use $HOME instead of ~ for home directory paths
|
||||
|
||||
4. Example pattern:
|
||||
```bash
|
||||
# Find executable
|
||||
if command -v bun >/dev/null 2>&1; then
|
||||
BUN_CMD="bun"
|
||||
else
|
||||
BUN_CMD="$HOME/.bun/bin/bun"
|
||||
fi
|
||||
|
||||
# Use the command
|
||||
$BUN_CMD run build
|
||||
```
|
||||
|
||||
metadata:
|
||||
priority: high
|
||||
version: 1.0
|
||||
</rule>
|
||||
|
||||
examples:
|
||||
- input: |
|
||||
# Bad: Using absolute path directly
|
||||
/usr/local/go/bin/go build
|
||||
output: |
|
||||
# Good: Try PATH first
|
||||
if command -v go >/dev/null 2>&1; then
|
||||
GO_CMD="go"
|
||||
else
|
||||
GO_CMD="/usr/local/go/bin/go"
|
||||
fi
|
||||
$GO_CMD build
|
||||
|
||||
- input: |
|
||||
# Bad: Using tilde expansion
|
||||
~/.bun/bin/bun install
|
||||
output: |
|
||||
# Good: Use $HOME
|
||||
if command -v bun >/dev/null 2>&1; then
|
||||
BUN_CMD="bun"
|
||||
else
|
||||
BUN_CMD="$HOME/.bun/bin/bun"
|
||||
fi
|
||||
$BUN_CMD install
|
18
build.sh
18
build.sh
|
@ -1,9 +1,23 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Find bun executable
|
||||
if command -v bun >/dev/null 2>&1; then
|
||||
BUN_CMD="bun"
|
||||
else
|
||||
BUN_CMD="$HOME/.bun/bin/bun"
|
||||
fi
|
||||
|
||||
# Find go executable
|
||||
if command -v go >/dev/null 2>&1; then
|
||||
GO_CMD="go"
|
||||
else
|
||||
GO_CMD="/usr/local/go/bin/go"
|
||||
fi
|
||||
|
||||
# Build frontend
|
||||
pushd frontend
|
||||
bun run build
|
||||
$BUN_CMD run build
|
||||
|
||||
# Copy static assets
|
||||
mkdir -p build/css
|
||||
|
@ -11,4 +25,4 @@ cp static/css/bulma.min.css build/css/
|
|||
|
||||
# Build backend
|
||||
popd
|
||||
go build -o notes-app
|
||||
$GO_CMD build -o notes-app
|
||||
|
|
Loading…
Add table
Reference in a new issue