schoolx-ota-manager
Version:
React Native library for managing OTA updates with GitLab integration
220 lines (176 loc) • 5.46 kB
Markdown
A React Native library for managing Over-The-Air (OTA) updates with GitLab integration. This library provides automatic version checking, bundle downloading, and installation for React Native apps.
- ✅ **GitLab Integration**: Direct integration with GitLab repositories
- ✅ **Version Compatibility**: Smart version checking with range operators (>, >=, <, <=, =)
- ✅ **Build Number Tracking**: Automatic build number management
- ✅ **Platform Support**: iOS and Android support
- ✅ **Auto Update**: Configurable automatic update checking
- ✅ **Progress Tracking**: Real-time update progress callbacks
- ✅ **No UI**: Pure logic component, integrate with your own UI
## Installation
```bash
npm install schoolx-ota-manager
# or
yarn add schoolx-ota-manager
```
## Dependencies
Make sure you have these dependencies installed:
```bash
npm install react-native-device-info react-native-ota-hot-update react-native-fs @react-native-async-storage/async-storage axios
```
## Quick Start
### 1. Basic Usage with Component
```tsx
import React, { useRef } from 'react';
import { OTAUpdate } from 'schoolx-ota-manager';
const App = () => {
const otaRef = useRef();
const handleProgress = (progress) => {
console.log('Update progress:', progress.status, progress.message);
};
const handleUpdateAvailable = (hasUpdate) => {
if (hasUpdate) {
console.log('Update available!');
// Trigger update installation
otaRef.current?.installUpdate();
}
};
return (
<>
<OTAUpdate
ref={otaRef}
gitlabToken="your-gitlab-token"
gitlabProjectId="your-project-id"
gitlabBaseUrl="https://gitlab.com/api/v4"
repoFolder="schoolx-parent"
onProgress={handleProgress}
onUpdateAvailable={handleUpdateAvailable}
/>
{/* Your app content */}
</>
);
};
```
```tsx
import React, { useEffect } from 'react';
import { OtaManager } from 'schoolx-ota-manager';
const App = () => {
useEffect(() => {
const otaManager = new OtaManager({
gitlabToken: 'your-gitlab-token',
gitlabProjectId: 'your-project-id',
gitlabBaseUrl: 'https://gitlab.com/api/v4',
repoFolder: 'schoolx-parent',
platform: 'ios', // or 'android'
autoUpdate: false,
checkInterval: 300000
});
// Set progress callback
otaManager.onProgress((progress) => {
console.log('Progress:', progress);
});
// Start auto checking
otaManager.startAutoCheck();
// Manual check
otaManager.checkUpdate().then(updateInfo => {
if (updateInfo.hasUpdate) {
otaManager.installUpdate();
}
});
return () => {
otaManager.stopAutoCheck();
};
}, []);
return (
// Your app content
);
};
```
```typescript
interface OtaConfig {
gitlabToken: string; // GitLab private token
gitlabProjectId: string; // GitLab project ID
gitlabBaseUrl: string; // GitLab API base URL
repoFolder: string; // Repository folder name
platform: 'ios' | 'android'; // Target platform
autoUpdate?: boolean; // Auto install updates
}
```
The `version` field in your `version.json` supports range operators:
```json
{
"ios": {
"version": ">=1.0.0", // App version >= 1.0.0
"buildNumber": 20241215001,
"bundleType": "bytecode",
"commitId": "main",
"bundlePath": "ios/main.ios.hbc.jsbundle",
"isForced": false,
"releaseNotes": "Bug fixes and performance improvements"
}
}
```
Supported operators: `>`, `>=`, `<`, `<=`, `=` (or no operator for exact match)
- `gitlabToken`: GitLab private token
- `gitlabProjectId`: GitLab project ID
- `gitlabBaseUrl`: GitLab API base URL
- `repoFolder`: Repository folder name
- `onProgress`: Progress callback
- `onUpdateAvailable`: Update availability callback
- `onUpdateCompleted`: Update completion callback
- `checkUpdate()`: Check for updates
- `installUpdate()`: Install available update
- `checkAndInstallUpdate()`: Check and install if available
- `checkOnAppStart()`: Check for updates when app starts
- `getInstalledBuildNumber()`: Get current build number
- `checkUpdate()`: Check for updates
- `installUpdate()`: Download and install update
- `checkAndInstallUpdate()`: Check and install if available
- `checkOnAppStart()`: Check for updates when app starts
- `onProgress(callback)`: Set progress callback
Your GitLab repository should have this structure:
```
your-repo/
├── version.json
├── ios/
│ └── hermes.ios.hbc.zip
└── android/
└── hermes.android.hbc.zip
```
```json
{
"android": {
"version": ">=1.0.0",
"buildNumber": 20241215001,
"bundleType": "bytecode",
"commitId": "main",
"bundlePath": "android/index.android.hbc.bundle",
"isForced": false,
"releaseNotes": "Bug fixes and performance improvements"
},
"ios": {
"version": ">=1.0.0",
"buildNumber": 20241215001,
"bundleType": "bytecode",
"commitId": "main",
"bundlePath": "ios/main.ios.hbc.jsbundle",
"isForced": false,
"releaseNotes": "Bug fixes and performance improvements"
}
}
```
MIT