XuqmGroup-RNSDK/packages/update/src/NativeBundle.ts

94 行
2.4 KiB
TypeScript

/**
* XuqmBundleModule JS
*
* bundle
* - // bundle
* - manifest
* - bundle
*
* bundle RN hostloadBundle
* 宿 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`
},
}