# @expo/repack-app

Repacking tool for Expo apps

## API Documentation

### CLI Usage

```sh
repack-app [options] [project-root]
```

#### Options

- `-p, --platform <platform>` (required): Platform to repack the app for (`android` or `ios`)
- `--source-app <path>` (required): Path to the source app file (APK for Android, IPA for iOS)
- `--android-build-tools-dir <path>`: Path to the Android build tools directory
- `-w, --working-directory <path>`: Path to the working directory
- `-o, --output <path>`: Path to the output artifact
- `-v, --verbose`: Enable verbose logging

#### Android-specific Options

- `--ks <path>`: Path to the keystore file
- `--ks-pass <password>`: Keystore password (supported formats: `pass:<password>`, `env:<name>`, `file:<file>`)
- `--ks-key-alias <alias>`: Keystore key alias
- `--ks-key-pass <password>`: Keystore key password (supported formats: `pass:<password>`, `env:<name>`, `file:<file>`)

#### iOS-specific Options

- `--signing-identity <identity>`: Code signing identity
- `--provisioning-profile <path>`: Path to the provisioning profile file(s)
- `--keychain-path <path>`: Path to the keychain file for codesign

#### Bundle Options

- `--embed-bundle-assets`: Force embedding of bundle assets
- `--bundle-assets-sourcemap-output <path>`: Generate sourcemap at the specified path (used with --embed-bundle-assets)

### Programmatic Usage

```typescript
import { repackAppAndroidAsync, repackAppIosAsync } from '@expo/repack-app';

// For Android
await repackAppAndroidAsync({
  platform: 'android',
  projectRoot: '/path/to/project',
  sourceAppPath: '/path/to/source.apk',
  // Optional configurations
  workingDirectory: '/path/to/working/dir',
  outputPath: '/path/to/output.apk',
  verbose: true,
  androidSigningOptions: {
    keyStorePath: '/path/to/keystore.jks',
    keyStorePassword: 'pass:password', // or 'env:KEYSTORE_PASS' or 'file:/path/to/pass'
    keyAlias: 'alias',
    keyPassword: 'pass:key-password', // or 'env:KEY_PASS' or 'file:/path/to/key-pass'
  },
  androidBuildToolsDir: '/path/to/build-tools',
  exportEmbedOptions: {
    sourcemapOutput: '/path/to/sourcemap',
  },
  env: {
    // Additional environment variables
  },
});

// For iOS
await repackAppIosAsync({
  platform: 'ios',
  projectRoot: '/path/to/project',
  sourceAppPath: '/path/to/source.ipa',
  // Optional configurations
  workingDirectory: '/path/to/working/dir',
  outputPath: '/path/to/output.ipa',
  verbose: true,
  iosSigningOptions: {
    signingIdentity: 'Apple Development: Name (Team ID)',
    provisioningProfile: '/path/to/profile.mobileprovision',
    keychainPath: '/path/to/keychain', // Optional
  },
  exportEmbedOptions: {
    sourcemapOutput: '/path/to/sourcemap',
  },
  env: {
    // Additional environment variables
  },
});
```

### Configuration Options

The following options are available when using the API programmatically:

#### Common Options

- `platform`: 'android' | 'ios' - The platform to repack the app for
- `projectRoot`: string - Path to the project root directory
- `sourceAppPath`: string - Path to the prebuilt app file (APK/IPA)
- `workingDirectory?`: string - Working directory for temporary files
- `outputPath?`: string - Path to the output app file (defaults to `projectRoot/repacked.apk` or `projectRoot/repacked.ipa`)
- `verbose?`: boolean - Enable verbose logging
- `exportEmbedOptions?`: ExportEmbedOptions - Options for embedding JS bundle. When specified, repack will generate bundle assets.
- `skipWorkingDirCleanup?`: boolean - Skip working directory cleanup
- `env?`: Record<string, string | undefined> - Environment variables

#### Android-specific Options

- `androidSigningOptions?`: AndroidSigningOptions - Options for signing the Android app
  - `keyStorePath`: string - Path to the keystore file
  - `keyStorePassword`: string - Keystore password (supported formats: `pass:<password>`, `env:<name>`, `file:<file>`)
  - `keyAlias?`: string - Keystore key alias
  - `keyPassword?`: string - Keystore key password (supported formats: `pass:<password>`, `env:<name>`, `file:<file>`)
- `androidBuildToolsDir?`: string - Path to Android SDK build-tools directory

#### iOS-specific Options

- `iosSigningOptions?`: IosSigningOptions - Options for signing the iOS app
  - `signingIdentity`: string - Code signing identity
  - `provisioningProfile`: string | Record<string, string> - Path to provisioning profile file(s)
  - `keychainPath?`: string - Path to the keychain file for codesign

## Environment Variables

- `ANDROID_SDK_ROOT`: Path to the Android SDK root directory (required for Android builds)
