# Restore Local Capacitor Plugins

## Overview

The `restore-local-plugins.js` script ensures that local custom Capacitor plugins (`SafeArea` and `SharedImage`) are automatically restored to `android/app/src/main/assets/capacitor.plugins.json` after running `npx cap sync android`.

## Why This Is Needed

The `capacitor.plugins.json` file is auto-generated by Capacitor during `npx cap sync` and gets overwritten, removing any manually added local plugins. This script automatically restores them.

## Usage

### Automatic (Recommended)

The script is automatically run by:
- `./scripts/build-android.sh` (after `cap sync`)
- `npm run build:capacitor:sync`
- `npm run build:native`

### Manual

If you run `npx cap sync android` directly, you can restore plugins manually:

```bash
node scripts/restore-local-plugins.js
```

## What It Does

1. Reads `android/app/src/main/assets/capacitor.plugins.json`
2. Checks if local plugins (`SafeArea` and `SharedImage`) are present
3. Adds any missing local plugins
4. Preserves the existing JSON format

## Local Plugins

The following local plugins are automatically restored:

- **SafeArea**: `app.timesafari.safearea.SafeAreaPlugin`
- **SharedImage**: `app.timesafari.sharedimage.SharedImagePlugin`

## Adding New Local Plugins

To add a new local plugin, edit `scripts/restore-local-plugins.js` and add it to the `LOCAL_PLUGINS` array:

```javascript
const LOCAL_PLUGINS = [
  // ... existing plugins ...
  {
    pkg: 'YourPluginName',
    classpath: 'app.timesafari.yourpackage.YourPluginClass'
  }
];
```

## Notes

- The script is idempotent - running it multiple times won't create duplicates
- The script preserves the existing JSON formatting (tabs, etc.)
- If the plugins file doesn't exist, the script will exit with an error (run `npx cap sync android` first)
