# Scripts Reference

Complete reference of all available yarn scripts in OrchardGo.

## Development Scripts

### Starting the App

| Script | Description |
|--------|-------------|
| `yarn start` | Start app with default config (iOS, Orchard, Production) |
| `yarn start:ios` | Start iOS app |
| `yarn start:android` | Start Android app |
| `yarn prestart` | Runs before start (validation, setup) |

### Project Setup

| Script | Description |
|--------|-------------|
| `yarn install` | Install dependencies and run postinstall hooks |
| `yarn preinstall` | Validates environment before installation |
| `yarn postinstall` | Patches packages, links assets after installation |
| `yarn setup` | Setup Jenkins secrets for private repos |
| `yarn clean` | Remove libraries and build directories |
| `yarn reset` | Kill React Native process, clear Metro bundler |
| `yarn check:tools` | Verify all required tools are installed |

## Testing Scripts

| Script | Description |
|--------|-------------|
| `yarn test` | Run linter and unit tests |
| `yarn test:unit` | Run unit tests with Jest |
| `yarn test:unit:watch` | Run unit tests in watch mode |
| `yarn test:update:snapshots` | Update Jest snapshots |
| `yarn watch` | Alias for test:unit:watch |
| `yarn lint` | Run TypeScript check and ESLint |
| `yarn prettier:write` | Format code with Prettier |

## Build Scripts

| Script | Description |
|--------|-------------|
| `yarn test:js:bundle` | Test JavaScript bundle creation |
| `yarn create:native:resources` | Generate native resources (icons, splash screens) |
| `yarn create:autogenerated:env` | Generate environment-specific files |
| `yarn assets:apply` | Apply custom assets (fonts, images) |

## Deployment Scripts

| Script | Description |
|--------|-------------|
| `yarn deploy:js` | Deploy JavaScript bundle to CodePush |
| `yarn deploy:binary` | Deploy native binary to app stores |
| `yarn promote` | Promote CodePush release from QA to Production |
| `yarn upload:missed:sentry:mapping` | Upload missed Sentry source maps |

### Sentry Scripts

| Script | Description |
|--------|-------------|
| `yarn sentry:create:release` | Create new Sentry release |
| `yarn sentry:upload:js` | Upload JavaScript source maps to Sentry |
| `yarn sentry:upload:proguard:mapping` | Upload Android ProGuard mapping |

### CodePush Scripts

| Script | Description |
|--------|-------------|
| `yarn codepush:enable` | Enable CodePush updates |
| `yarn codepush:disable` | Disable CodePush updates |
| `yarn codepush:history` | View CodePush deployment history |
| `yarn codepush:bundle:enable` | Enable CodePush bundle |

## iOS Scripts

| Script | Description |
|--------|-------------|
| `yarn xcode` | Open project in Xcode |
| `yarn ios:simulators` | List available iOS simulators |
| `yarn ios:simulator:run [UUID]` | Run specific iOS simulator |
| `yarn patch:pods` | Apply patches to CocoaPods |

## Android Scripts

| Script | Description |
|--------|-------------|
| `yarn android:devices` | List connected Android devices |
| `yarn android:emulators` | List available Android emulators |
| `yarn android:emulator:run [NAME]` | Run specific Android emulator |
| `yarn android:device:prepare` | Prepare Android device for development |
| `yarn android:deeplink:send [URL]` | Send deep link to Android device |
| `yarn android:certificate:fingerprint` | Get Android certificate fingerprint |
| `yarn android:application:id` | Get Android application ID |

## Utility Scripts

| Script | Description |
|--------|-------------|
| `yarn resize:image` | Resize images for different densities |
| `yarn sync:translations` | Sync translations from POEditor |
| `yarn aws:s3:upload` | Upload files to AWS S3 |
| `yarn dynamiclink:create` | Create Firebase dynamic link |
| `yarn git:pr:create` | Create pull request via GitHub CLI |
| `yarn release:start` | Start new release process |
| `yarn remove:dot:env` | Remove .env file (security) |

## Appium Scripts

| Script | Description |
|--------|-------------|
| `yarn appium:run` | Start Appium server |
| `yarn appium:inspector` | Open Appium Inspector app |

## Mac Mini CI Scripts

Scripts for managing CI Mac Mini agents:

### Agent 01

| Script | Description |
|--------|-------------|
| `yarn macmini:agent01:init` | Initialize agent01 |
| `yarn macmini:agent01:install` | Install dependencies on agent01 |
| `yarn macmini:agent01:setup` | Setup agent01 configuration |
| `yarn macmini:agent01:about` | Get agent01 information |
| `yarn macmini:agent01:about:quick` | Quick info about agent01 |
| `yarn macmini:agent01:clean` | Clean agent01 workspace |
| `yarn macmini:agent01:clean:force` | Force clean agent01 |
| `yarn macmini:agent01:clean:deep` | Deep clean agent01 (includes caches) |
| `yarn macmini:agent01:clean:deep:force` | Force deep clean agent01 |
| `yarn macmini:agent01:full` | Full setup of agent01 |
| `yarn macmini:agent01:wait:install` | Wait for agent01 install reboot |
| `yarn macmini:agent01:wait:full` | Wait for agent01 full setup reboot |

### Agent 02 & 03

Similar scripts exist for `agent02` and `agent03`:
- `yarn macmini:agent02:*`
- `yarn macmini:agent03:*`

See [macOS Maintenance Guide](../maintenance/macos-maintenance.md) for details.

## Script Environment Variables

Many scripts accept environment variables:

```bash
# Platform selection
PLATFORM=ios yarn start
PLATFORM=android yarn start

# Brand selection
BRAND=orchard yarn start
BRAND=awal yarn start

# Environment selection
ENV=prod yarn start
ENV=qa yarn start

# Device selection
DEVICE="iPhone 15" yarn start:ios

# CodePush config
LOCALAPPDATA=. yarn code-push-standalone whoami

# Mac Mini host selection
HOST=agent01 yarn macmini:about
```

## Common Script Patterns

### Full Clean Reinstall

```bash
yarn clean
yarn reset
rm -rf node_modules yarn.lock
yarn install
```

### Deploy to CodePush

```bash
# Deploy to QA
yarn deploy:js --env qa

# Test in QA, then promote to Production
yarn promote
```

### Create Release

```bash
# Start release process
yarn release:start

# Deploy binary
yarn deploy:binary
```

### Debug Session

```bash
# Start fresh
yarn reset
yarn start

# In another terminal
yarn test:unit:watch
```

## Script Hooks

### Pre-commit Hooks (Husky)

Automatically run on `git commit`:
- ESLint on staged files
- Prettier formatting
- Unit tests for changed files

### Pre-push Hooks

Run on `git push`:
- Full test suite
- TypeScript checks

## Custom Script Arguments

### Start Script

```bash
yarn start [options]

Options:
  --platform [ios|android]   Target platform
  --brand [orchard|awal]     App brand
  --env [prod|qa]            Environment
  --device [name]            Device name or ID
  --reset-cache              Clear Metro cache
```

### Test Script

```bash
yarn test:unit [options]

Options:
  --watch                    Watch mode
  --coverage                 Generate coverage report
  --updateSnapshot           Update snapshots
  --testNamePattern [name]   Run specific tests
  --verbose                  Verbose output
```

## Next Steps

- [Running the App](./running-the-app.md)
- [Testing](./testing.md)
- [Deployment](../deployment/)
- [Debugging](./debugging.md)
