1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-15 00:35:07 +00:00

Use more robust scripts

This commit is contained in:
Tw93
2025-11-19 09:45:14 +08:00
parent 0154c272fb
commit f8f9d7db7d
7 changed files with 57 additions and 20 deletions

Binary file not shown.

View File

@@ -6,15 +6,31 @@ set -euo pipefail
cd "$(dirname "$0")/.." cd "$(dirname "$0")/.."
# Check if Go is installed
if ! command -v go > /dev/null 2>&1; then
echo "Error: Go not installed"
echo "Install: brew install go"
exit 1
fi
echo "Building analyze-go for multiple architectures..." echo "Building analyze-go for multiple architectures..."
# Get version info
VERSION=$(git describe --tags --always --dirty 2> /dev/null || echo "dev")
BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S')
LDFLAGS="-s -w -X main.Version=$VERSION -X main.BuildTime=$BUILD_TIME"
echo " Version: $VERSION"
echo " Build time: $BUILD_TIME"
echo ""
# Build for arm64 (Apple Silicon) # Build for arm64 (Apple Silicon)
echo " → Building for arm64..." echo " → Building for arm64..."
GOARCH=arm64 go build -ldflags="-s -w" -o bin/analyze-go-arm64 ./cmd/analyze GOARCH=arm64 go build -ldflags="$LDFLAGS" -trimpath -o bin/analyze-go-arm64 ./cmd/analyze
# Build for amd64 (Intel) # Build for amd64 (Intel)
echo " → Building for amd64..." echo " → Building for amd64..."
GOARCH=amd64 go build -ldflags="-s -w" -o bin/analyze-go-amd64 ./cmd/analyze GOARCH=amd64 go build -ldflags="$LDFLAGS" -trimpath -o bin/analyze-go-amd64 ./cmd/analyze
# Create Universal Binary # Create Universal Binary
echo " → Creating Universal Binary..." echo " → Creating Universal Binary..."

View File

@@ -52,10 +52,10 @@ fi
# 3. Unit tests (if available) # 3. Unit tests (if available)
echo -e "${YELLOW}3. Running tests...${NC}" echo -e "${YELLOW}3. Running tests...${NC}"
if command -v bats > /dev/null 2>&1 && [ -d "tests" ]; then if command -v bats > /dev/null 2>&1 && [ -d "tests" ]; then
if bats tests/*.bats 2> /dev/null; then if bats tests/*.bats; then
echo -e "${GREEN}✓ Tests passed${NC}\n" echo -e "${GREEN}✓ Tests passed${NC}\n"
else else
echo -e "${RED}✗ Tests failed${NC}\n" echo -e "${RED}✗ Tests failed (see output above)${NC}\n"
exit 1 exit 1
fi fi
else else
@@ -88,7 +88,7 @@ fi
# Check 3: Log rotation once per session # Check 3: Log rotation once per session
((TOTAL_CHECKS++)) ((TOTAL_CHECKS++))
if grep -q "rotate_log_once" lib/common.sh && ! grep -q "rotate_log()" lib/common.sh | grep -v "rotate_log_once"; then if grep -q "rotate_log_once" lib/common.sh && ! grep "rotate_log()" lib/common.sh | grep -v "rotate_log_once" > /dev/null 2>&1; then
echo -e "${GREEN} ✓ Log rotation optimized (once per session)${NC}" echo -e "${GREEN} ✓ Log rotation optimized (once per session)${NC}"
((OPTIMIZATION_SCORE++)) ((OPTIMIZATION_SCORE++))
else else

View File

@@ -37,24 +37,37 @@ if ! command -v shfmt > /dev/null 2>&1; then
exit 1 exit 1
fi fi
# Find all shell scripts # Find all shell scripts (excluding temp directories and build artifacts)
cd "$PROJECT_ROOT" cd "$PROJECT_ROOT"
# Build list of files to format (exclude .git, node_modules, tmp directories)
FILES=$(find . -type f \( -name "*.sh" -o -name "mole" \) \
-not -path "./.git/*" \
-not -path "*/node_modules/*" \
-not -path "*/tests/tmp-*/*" \
-not -path "*/.*" \
2> /dev/null)
if [[ -z "$FILES" ]]; then
echo "No shell scripts found"
exit 0
fi
# shfmt options: -i 4 (4 spaces), -ci (indent switch cases), -sr (space after redirect) # shfmt options: -i 4 (4 spaces), -ci (indent switch cases), -sr (space after redirect)
if [[ "$CHECK_ONLY" == "true" ]]; then if [[ "$CHECK_ONLY" == "true" ]]; then
echo "Checking formatting..." echo "Checking formatting..."
if shfmt -i 4 -ci -sr -d . > /dev/null 2>&1; then if echo "$FILES" | xargs shfmt -i 4 -ci -sr -d > /dev/null 2>&1; then
echo "✓ All scripts properly formatted" echo "✓ All scripts properly formatted"
exit 0 exit 0
else else
echo "✗ Some scripts need formatting:" echo "✗ Some scripts need formatting:"
shfmt -i 4 -ci -sr -d . echo "$FILES" | xargs shfmt -i 4 -ci -sr -d
echo "" echo ""
echo "Run './scripts/format.sh' to fix" echo "Run './scripts/format.sh' to fix"
exit 1 exit 1
fi fi
else else
echo "Formatting scripts..." echo "Formatting scripts..."
shfmt -i 4 -ci -sr -w . echo "$FILES" | xargs shfmt -i 4 -ci -sr -w
echo "✓ Done" echo "✓ Done"
fi fi

View File

@@ -246,19 +246,27 @@ create_raycast_commands() {
log_success "Scripts ready in: $dir" log_success "Scripts ready in: $dir"
done done
echo ""
if open "raycast://extensions/script-commands" > /dev/null 2>&1; then if open "raycast://extensions/script-commands" > /dev/null 2>&1; then
log_step "Raycast settings opened. Run 'Reload Script Directories'." log_step "Raycast settings opened."
else else
log_warn "Could not auto-open Raycast. Open it manually to reload scripts." log_warn "Could not auto-open Raycast."
fi fi
echo ""
echo "Next steps to activate Raycast commands:"
echo " 1. Open Raycast (⌘ Space)"
echo " 2. Search for 'Reload Script Directories'"
echo " 3. Press Enter to load new commands"
} }
uuid() { uuid() {
if command -v uuidgen > /dev/null 2>&1; then if command -v uuidgen > /dev/null 2>&1; then
uuidgen uuidgen
else else
# Fallback pseudo UUID # Fallback pseudo UUID in format: 8-4-4-4-12
openssl rand -hex 16 | sed 's/\(..\)/\1/g' | cut -c1-32 local hex=$(openssl rand -hex 16)
echo "${hex:0:8}-${hex:8:4}-${hex:12:4}-${hex:16:4}-${hex:20:12}"
fi fi
} }