|
1 | | -#!/bin/bash |
| 1 | +#!/usr/bin/env bash |
2 | 2 | set -euo pipefail |
3 | 3 |
|
| 4 | +# Run from inside any examples/<demo> directory. |
4 | 5 | ORIGINAL_DIR=$(pwd) |
| 6 | +SDK_ROOT=$(cd "$ORIGINAL_DIR/../.." && pwd) |
5 | 7 |
|
6 | | -# Build and pack the plugin |
7 | | -cd ../../ |
8 | | -bun run build |
| 8 | +info() { echo -e "\033[0;32m[setup]\033[0m $*"; } |
9 | 9 |
|
10 | | -rm -f onesignal-capacitor-plugin*.tgz |
11 | | -bun pm pack |
12 | | -mv onesignal-capacitor-plugin-*.tgz onesignal-capacitor-plugin.tgz |
| 10 | +# ── Plugin tarball cache ───────────────────────────────────────────────────── |
| 11 | +# Skip rebuild/repack/`vp add` when plugin sources haven't changed. |
| 12 | +SDK_STAMP="$SDK_ROOT/.capacitor-sdk-source.stamp" |
| 13 | +INSTALLED_DIR="$ORIGINAL_DIR/node_modules/onesignal-capacitor-plugin" |
13 | 14 |
|
14 | | -# Install the packed plugin in the demo app |
15 | | -cd "$ORIGINAL_DIR" |
| 15 | +SDK_SRC_HASH=$(find "$SDK_ROOT/src" "$SDK_ROOT/android" "$SDK_ROOT/ios" \ |
| 16 | + "$SDK_ROOT/package.json" \ |
| 17 | + "$SDK_ROOT/OneSignalCapacitorPlugin.podspec" \ |
| 18 | + "$SDK_ROOT/Package.swift" \ |
| 19 | + "$SDK_ROOT/vite.config.ts" \ |
| 20 | + -type f 2>/dev/null \ |
| 21 | + | sort \ |
| 22 | + | xargs shasum 2>/dev/null \ |
| 23 | + | shasum \ |
| 24 | + | awk '{print $1}') |
16 | 25 |
|
17 | | -bun pm cache rm |
| 26 | +if [[ -d "$INSTALLED_DIR" ]] && [[ -f "$SDK_STAMP" ]] && [[ "$(cat "$SDK_STAMP")" == "$SDK_SRC_HASH" ]]; then |
| 27 | + info "Capacitor SDK source unchanged, skipping rebuild + repack" |
| 28 | +else |
| 29 | + info "Building Capacitor plugin & packing tarball..." |
| 30 | + (cd "$SDK_ROOT" && vp run build) |
| 31 | + (cd "$SDK_ROOT" && rm -f onesignal-capacitor-plugin*.tgz && vp pm pack && mv onesignal-capacitor-plugin-*.tgz onesignal-capacitor-plugin.tgz) |
18 | 32 |
|
19 | | -bun remove onesignal-capacitor-plugin |
20 | | -bun add file:../../onesignal-capacitor-plugin.tgz |
| 33 | + # Remove before add so bun.lock's integrity hash refreshes against the new |
| 34 | + # tarball; otherwise `vp add` hits a dependency-loop error under bun 1.3+. |
| 35 | + # Keep the relative `file:../../...` path to match package.json's spec. |
| 36 | + info "Registering tarball with vp (refreshes bun.lock integrity hash)..." |
| 37 | + vp remove onesignal-capacitor-plugin 2>/dev/null || true |
| 38 | + vp add file:../../onesignal-capacitor-plugin.tgz |
21 | 39 |
|
22 | | -# Build the web app and sync native projects |
23 | | -bun run build |
24 | | -bunx cap sync |
| 40 | + echo "$SDK_SRC_HASH" > "$SDK_STAMP" |
| 41 | +fi |
| 42 | + |
| 43 | +# ── Web bundle ─────────────────────────────────────────────────────────────── |
| 44 | +info "Building web bundle (vite)..." |
| 45 | +# Same reasoning as the SDK build above: invoke `vp build` directly to skip |
| 46 | +# `vp run`'s task cache, which can be incompatible between vite-plus versions. |
| 47 | +vp run build |
| 48 | + |
| 49 | +# ── Capacitor sync cache ───────────────────────────────────────────────────── |
| 50 | +# `cap sync` runs `pod install` + `xcodebuild clean` (~30-60s); skip when |
| 51 | +# inputs are unchanged. Hash sources (not `dist/`) since bundlers emit |
| 52 | +# content-hashed chunk names that can drift between identical builds. |
| 53 | +SYNC_STAMP="$ORIGINAL_DIR/.cap-sync.stamp" |
| 54 | +SYNC_HASH=$(find "$ORIGINAL_DIR/src" "$ORIGINAL_DIR/index.html" \ |
| 55 | + "$ORIGINAL_DIR/capacitor.config.ts" "$ORIGINAL_DIR/vite.config.ts" \ |
| 56 | + "$ORIGINAL_DIR/package.json" "$ORIGINAL_DIR/bun.lock" \ |
| 57 | + "$ORIGINAL_DIR/ios/App" \ |
| 58 | + -type f \ |
| 59 | + ! -path "*/node_modules/*" \ |
| 60 | + ! -path "*/Pods/*" \ |
| 61 | + ! -path "*/build/*" \ |
| 62 | + ! -path "*/DerivedData/*" \ |
| 63 | + ! -path "*/xcuserdata/*" \ |
| 64 | + \( -name "Podfile" -o -name "Package.swift" -o -name "build.gradle" \ |
| 65 | + -o -name "*.ts" -o -name "*.tsx" \ |
| 66 | + -o -name "*.json" -o -name "*.html" -o -name "*.js" \ |
| 67 | + -o -name "*.css" -o -name "*.svg" -o -name "*.xml" \ |
| 68 | + -o -name "*.swift" -o -name "*.kt" \ |
| 69 | + -o -name "*.lock" \) \ |
| 70 | + 2>/dev/null \ |
| 71 | + | sort \ |
| 72 | + | xargs shasum 2>/dev/null \ |
| 73 | + | shasum \ |
| 74 | + | awk '{print $1}') |
| 75 | +SYNC_HASH="${SYNC_HASH}-${SDK_SRC_HASH}" |
| 76 | + |
| 77 | +if [[ -d "$ORIGINAL_DIR/ios/App/App/public" ]] && [[ -f "$SYNC_STAMP" ]] && [[ "$(cat "$SYNC_STAMP")" == "$SYNC_HASH" ]]; then |
| 78 | + info "Capacitor sync inputs unchanged, skipping cap sync" |
| 79 | +elif ! command -v pod >/dev/null 2>&1; then |
| 80 | + # CI Android jobs run on Linux where CocoaPods isn't installed. |
| 81 | + # Sync only Android so plain `cap sync` doesn't shell out to pod. |
| 82 | + info "CocoaPods not found, syncing Android only..." |
| 83 | + vpx cap sync android |
| 84 | + echo "$SYNC_HASH" > "$SYNC_STAMP" |
| 85 | +else |
| 86 | + info "Syncing Capacitor..." |
| 87 | + vpx cap sync |
| 88 | + echo "$SYNC_HASH" > "$SYNC_STAMP" |
| 89 | +fi |
0 commit comments