|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 5 | +REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" |
| 6 | +PROJECT_NAME="${PROJECT_NAME:-NoteDelight}" |
| 7 | +PREVIEW_FILE="app/android/src/main/java/com/softartdev/notedelight/ScreenshootPreview.kt" |
| 8 | +OUTPUT_ROOT="$REPO_ROOT/docs/screenshoots/store" |
| 9 | + |
| 10 | +if ! command -v android >/dev/null 2>&1; then |
| 11 | + echo "android CLI not found. Install it and make sure it is available on PATH." >&2 |
| 12 | + exit 1 |
| 13 | +fi |
| 14 | + |
| 15 | +if ! command -v sips >/dev/null 2>&1; then |
| 16 | + echo "sips not found. Screenshot dimension checks require macOS sips." >&2 |
| 17 | + exit 1 |
| 18 | +fi |
| 19 | + |
| 20 | +cd "$REPO_ROOT" |
| 21 | + |
| 22 | +if [[ ! -f "$PREVIEW_FILE" ]]; then |
| 23 | + echo "Preview file not found: $PREVIEW_FILE" >&2 |
| 24 | + exit 1 |
| 25 | +fi |
| 26 | + |
| 27 | +STUDIO_CHECK_OUTPUT="$(android studio check)" |
| 28 | +if ! grep -Eq "READY[[:space:]]+$PROJECT_NAME[[:space:]]+" <<< "$STUDIO_CHECK_OUTPUT"; then |
| 29 | + echo "Android Studio project '$PROJECT_NAME' is not READY." >&2 |
| 30 | + echo "Open this repository in Android Studio, wait for indexing, then retry." >&2 |
| 31 | + echo "$STUDIO_CHECK_OUTPUT" >&2 |
| 32 | + exit 1 |
| 33 | +fi |
| 34 | + |
| 35 | +rm -rf "$OUTPUT_ROOT" |
| 36 | + |
| 37 | +SCREENSHOTS=( |
| 38 | + "phone|light|01|notes|StorePhoneLightNotesPreview|1080|1920" |
| 39 | + "phone|light|02|note-detail|StorePhoneLightNoteDetailPreview|1080|1920" |
| 40 | + "phone|light|03|sign-in|StorePhoneLightSignInPreview|1080|1920" |
| 41 | + "phone|light|04|security-settings|StorePhoneLightSecuritySettingsPreview|1080|1920" |
| 42 | + "phone|light|05|backup-settings|StorePhoneLightBackupSettingsPreview|1080|1920" |
| 43 | + "phone|dark|01|notes|StorePhoneDarkNotesPreview|1080|1920" |
| 44 | + "phone|dark|02|note-detail|StorePhoneDarkNoteDetailPreview|1080|1920" |
| 45 | + "phone|dark|03|sign-in|StorePhoneDarkSignInPreview|1080|1920" |
| 46 | + "phone|dark|04|security-settings|StorePhoneDarkSecuritySettingsPreview|1080|1920" |
| 47 | + "phone|dark|05|backup-settings|StorePhoneDarkBackupSettingsPreview|1080|1920" |
| 48 | + "tablet|light|01|notes|StoreTabletLightNotesPreview|1920|1200" |
| 49 | + "tablet|light|02|note-detail|StoreTabletLightNoteDetailPreview|1920|1200" |
| 50 | + "tablet|light|03|sign-in|StoreTabletLightSignInPreview|1920|1200" |
| 51 | + "tablet|light|04|security-settings|StoreTabletLightSecuritySettingsPreview|1920|1200" |
| 52 | + "tablet|light|05|backup-settings|StoreTabletLightBackupSettingsPreview|1920|1200" |
| 53 | + "tablet|dark|01|notes|StoreTabletDarkNotesPreview|1920|1200" |
| 54 | + "tablet|dark|02|note-detail|StoreTabletDarkNoteDetailPreview|1920|1200" |
| 55 | + "tablet|dark|03|sign-in|StoreTabletDarkSignInPreview|1920|1200" |
| 56 | + "tablet|dark|04|security-settings|StoreTabletDarkSecuritySettingsPreview|1920|1200" |
| 57 | + "tablet|dark|05|backup-settings|StoreTabletDarkBackupSettingsPreview|1920|1200" |
| 58 | +) |
| 59 | + |
| 60 | +for screenshot in "${SCREENSHOTS[@]}"; do |
| 61 | + IFS="|" read -r form theme number scenario composable expected_width expected_height <<< "$screenshot" |
| 62 | + output_file="$OUTPUT_ROOT/$form/$theme/$number-$scenario.png" |
| 63 | + mkdir -p "$(dirname "$output_file")" |
| 64 | + |
| 65 | + echo "Rendering $composable -> ${output_file#$REPO_ROOT/}" |
| 66 | + android studio render-compose-preview \ |
| 67 | + --project="$PROJECT_NAME" \ |
| 68 | + "$PREVIEW_FILE" \ |
| 69 | + "$composable" \ |
| 70 | + --output-image-file="$output_file" |
| 71 | + |
| 72 | + if [[ ! -s "$output_file" ]]; then |
| 73 | + echo "Screenshot was not created or is empty: $output_file" >&2 |
| 74 | + exit 1 |
| 75 | + fi |
| 76 | + |
| 77 | + actual_width="$(sips -g pixelWidth "$output_file" | awk '/pixelWidth/ {print $2}')" |
| 78 | + actual_height="$(sips -g pixelHeight "$output_file" | awk '/pixelHeight/ {print $2}')" |
| 79 | + if [[ "$actual_width" != "$expected_width" || "$actual_height" != "$expected_height" ]]; then |
| 80 | + echo "Unexpected dimensions for $output_file: ${actual_width}x${actual_height}, expected ${expected_width}x${expected_height}" >&2 |
| 81 | + exit 1 |
| 82 | + fi |
| 83 | +done |
| 84 | + |
| 85 | +echo "Generated ${#SCREENSHOTS[@]} screenshots in ${OUTPUT_ROOT#$REPO_ROOT/}" |
0 commit comments