Files
Phil HaackandGitHub 4bc5810d64 chore: Add bin scripts for setup, build, and test (#2824)
* Add bin scripts for setup, build, and test

Add standardized bin scripts following the PostHog template pattern:

- bin/setup: installs dependencies via pnpm install
- bin/build: runs setup if needed, then builds all packages
- bin/test: runs tests for specific packages or all packages
  - Interactive menu when no package specified
  - Package aliases (js, rn, lite, etc.)
  - Test type flags (--unit, --functional, --e2e)
  - Pre-flight checks for dependencies and build status
- bin/helpers/_utils.sh: shared utility functions

* Remove run_command and simplify bin scripts

The run_command function had a quoting bug when handling commands with
arguments. Replace it with direct echo statements and command execution.

Applies changes from PostHog/template#6.

* Always run bin/setup in bin/build

Checking for node_modules existence doesn't guarantee dependencies are
up to date with the lockfile. Always running setup is safer and pnpm
is fast when deps are already satisfied.
2026-01-07 17:20:16 +00:00

63 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Common utility functions for scripts
# Print colored text
print_color() {
case $1 in
red) echo -e "\033[31m$2\033[0m";;
green) echo -e "\033[32m$2\033[0m";;
yellow) echo -e "\033[33m$2\033[0m";;
blue) echo -e "\033[34m$2\033[0m";;
*) echo "$2";;
esac
}
# Print error to stderr in red
error() {
print_color red "Error: $*" >&2
}
# Print error and exit
fatal() {
error "$*"
exit 1
}
# Set source and root directories, cd to root
set_source_and_root_dir() {
{ set +x; } 2>/dev/null
source_dir="$( cd -P "$( dirname "$0" )" >/dev/null 2>&1 && pwd )"
root_dir=$(cd "$source_dir" && cd ../ && pwd)
cd "$root_dir"
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Print warning in yellow
warning() {
print_color yellow "Warning: $*" >&2
}
# Print success in green
success() {
print_color green "✓ $*"
}
# Check required commands exist
require_commands() {
local missing=()
for cmd in "$@"; do
command_exists "$cmd" || missing+=("$cmd")
done
[ ${#missing[@]} -eq 0 ] || fatal "Missing commands: ${missing[*]}"
}
# Show help from script comments
show_help() {
sed -n -E 's/^#\/ ?//p' "$0"
}