T-B01: XuqmBundleModule 原生模块 - Android: XuqmBundleModule.java(文件读写/manifest/路径) - iOS: XuqmBundleModule.m(对应实现) - JS: NativeBundle.ts 封装 - 注册到 XuqmUpdatePackage T-B02: downloadPluginBundle 添加 onProgress - 使用 ReadableStream 实现下载进度追踪 - checkAndCachePlugin 同步支持 onProgress T-B03: XWebView JSBridge 标准接口文档 - docs/XWebView-JSBridge.md - H5→RN 消息协议 / RN→H5 通信 - 下载处理 / Dialog 覆盖 / 标准 Bridge 接口 T-B04: PushSDK Android 厂商集成文档 - docs/PushSDK-厂商集成.md - 6 厂商配置步骤 / ProGuard 规则 / 调试指南
94 行
2.4 KiB
TypeScript
94 行
2.4 KiB
TypeScript
/**
|
||
* XuqmBundleModule JS 封装。
|
||
*
|
||
* 提供 bundle 文件的原生管理能力:
|
||
* - 读取/写入/删除 bundle 文件
|
||
* - manifest 管理
|
||
* - bundle 路径查询
|
||
*
|
||
* 注意:bundle 注入到运行中的 RN host(loadBundle)
|
||
* 由宿主的 BundleRuntime 负责(RN 0.84 不暴露公开 API)。
|
||
*/
|
||
|
||
import {NativeModules, Platform} from 'react-native'
|
||
|
||
interface XuqmBundleModuleInterface {
|
||
bundleExists(moduleId: string): Promise<boolean>
|
||
readBundle(moduleId: string): Promise<string>
|
||
writeBundle(moduleId: string, source: string, md5: string): Promise<boolean>
|
||
deleteBundle(moduleId: string): Promise<boolean>
|
||
getBundlePath(moduleId: string): Promise<string>
|
||
getManifest(): Promise<string>
|
||
writeManifest(manifestJson: string): Promise<boolean>
|
||
}
|
||
|
||
function getModule(): XuqmBundleModuleInterface {
|
||
const mod = NativeModules.XuqmBundleModule
|
||
if (!mod) {
|
||
throw new Error('[XuqmBundleModule] Native module not available')
|
||
}
|
||
return mod as XuqmBundleModuleInterface
|
||
}
|
||
|
||
export const NativeBundle = {
|
||
/**
|
||
* 检查指定 bundle 文件是否存在。
|
||
*/
|
||
async exists(moduleId: string): Promise<boolean> {
|
||
return getModule().bundleExists(moduleId)
|
||
},
|
||
|
||
/**
|
||
* 读取 bundle 文件内容(JS 源码文本)。
|
||
*/
|
||
async read(moduleId: string): Promise<string> {
|
||
return getModule().readBundle(moduleId)
|
||
},
|
||
|
||
/**
|
||
* 将 bundle 源码写入本地文件。
|
||
*
|
||
* @param moduleId 插件 ID
|
||
* @param source JS 源码文本
|
||
* @param md5 文件 MD5 校验值
|
||
*/
|
||
async write(moduleId: string, source: string, md5: string): Promise<void> {
|
||
await getModule().writeBundle(moduleId, source, md5)
|
||
},
|
||
|
||
/**
|
||
* 删除指定 bundle 文件。
|
||
*/
|
||
async remove(moduleId: string): Promise<void> {
|
||
await getModule().deleteBundle(moduleId)
|
||
},
|
||
|
||
/**
|
||
* 获取 bundle 文件的绝对路径。
|
||
*/
|
||
async getPath(moduleId: string): Promise<string> {
|
||
return getModule().getBundlePath(moduleId)
|
||
},
|
||
|
||
/**
|
||
* 读取 manifest.json 内容。
|
||
*/
|
||
async getManifest(): Promise<string> {
|
||
return getModule().getManifest()
|
||
},
|
||
|
||
/**
|
||
* 写入 manifest.json。
|
||
*/
|
||
async writeManifest(manifestJson: string): Promise<void> {
|
||
await getModule().writeManifest(manifestJson)
|
||
},
|
||
|
||
/**
|
||
* 获取 bundle 文件名(平台相关)。
|
||
*/
|
||
getFileName(moduleId: string): string {
|
||
return `${moduleId}.${Platform.OS}.bundle`
|
||
},
|
||
}
|