diff --git a/.cursor/rules/command-paths.mdc b/.cursor/rules/command-paths.mdc new file mode 100644 index 0000000..078c935 --- /dev/null +++ b/.cursor/rules/command-paths.mdc @@ -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 \ No newline at end of file diff --git a/build.sh b/build.sh index 49a6d47..923f291 100755 --- a/build.sh +++ b/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