File size: 2,877 Bytes
e1f81b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env zx
import {setBuildEnv} from "./set-build-env.mjs"
import {startDevMiniapps} from "./local-miniapps.mjs"
import {syncAutolinkingCache} from "./clear-autolinking-cache.mjs"
import {pinLocalBuildNumber} from "./local-build-number.mjs"
// The autolinking guard runs once, after prebuild (below), where it is
// authoritative; skipping the pre-prebuild pass saves ~1.3s.
// A debug build gets the miniapps live instead of packed.
await setBuildEnv({syncAutolinking: false, packMiniapps: false})
// Serve every miniapp of this checkout to the debug build, live.
await startDevMiniapps()

// Pin the build number for this local build so prebuild and Gradle stop
// baking a fresh per-second versionCode into the project on every run
// (see local-build-number.mjs). MENTRAOS_PINNED_BUILD_NUMBER still wins.
await pinLocalBuildNumber()

// Skip @expo/image-utils' global `sharp-cli` discovery during prebuild. It
// spawns npm/yarn/pnpm/bun global lookups plus `sharp --version` for every
// icon/splash layer, and on macOS that leaves the next synchronous spawn in
// the process stalled for ~3s (measured: prebuild 4.9s -> 1.2s). Without a
// global sharp-cli (the default setup) Expo already falls back to the same
// in-process jimp path, so this only removes the probe; with one installed,
// icons/splash are simply generated by jimp instead (visually identical, and
// only local dev builds go through this script). An explicit value in the
// environment wins.
process.env.EXPO_IMAGE_UTILS_NO_SHARP ??= "1"

// prebuild android:
await $({stdio: "inherit"})`bun expo prebuild --platform android`

// Authoritative post-prebuild check: compare the resolved autolinking graph
// to the cached artifact and wipe only on drift (or a poisoned entry point).
await syncAutolinkingCache()

// Get connected devices with details
const adbOutput = await $`adb devices -l`
const lines = adbOutput.stdout.trim().split('\n').slice(1)

// Filter to physical devices that don't contain "live"
const validDevices = lines.filter(line => 
  line.trim() && 
  !line.includes('emulator') && 
  !line.toLowerCase().includes('live') &&
  !line.startsWith('emulator')
)

if (validDevices.length === 0) {
  console.error('No suitable physical device found')
  process.exit(1)
}

// build only for real devices new arch:
process.env.ORG_GRADLE_PROJECT_reactNativeArchitectures = 'arm64-v8a'

if (validDevices.length > 1) {
  console.log('Multiple devices found, launching interactive picker')
  await $({stdio: "inherit"})`bun expo run:android --device`
} else {
  const modelMatch = validDevices[0].match(/model:(\S+)/)
  const deviceName = modelMatch ? modelMatch[1] : validDevices[0].split(/\s+/)[0]
  console.log(`Using device: ${deviceName}`)
  await $({stdio: "inherit"})`bun expo run:android --device ${deviceName}`
}