- 增加了wrapper处理原生app的交互

This commit is contained in:
Yudi Xiao
2026-04-08 17:04:29 +08:00
parent 90dcd9605c
commit f9dfde0ace
19 changed files with 1501 additions and 32 deletions

View File

@@ -0,0 +1,38 @@
import { cpSync, existsSync, mkdirSync, rmSync } from 'node:fs'
import path from 'node:path'
import { spawnSync } from 'node:child_process'
import { fileURLToPath } from 'node:url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const rootDir = path.resolve(__dirname, '..')
const distDir = path.join(rootDir, 'dist', 'android')
const mavenDir = path.join(distDir, 'maven')
const wrapperDir = path.join(distDir, 'wrapper')
const wrapperTemplateDir = path.join(rootDir, 'wrappers', 'android')
function run(command, args) {
const executable = process.platform === 'win32' ? `${command}.cmd` : command
const result = spawnSync(executable, args, {
cwd: rootDir,
stdio: 'inherit',
})
if (result.status !== 0) {
process.exit(result.status ?? 1)
}
}
rmSync(distDir, { recursive: true, force: true })
mkdirSync(distDir, { recursive: true })
run('pnpx', ['expo-brownfield', 'build:android', '--release'])
if (!existsSync(mavenDir)) {
throw new Error(`Missing Android Maven output: ${mavenDir}`)
}
cpSync(wrapperTemplateDir, wrapperDir, { recursive: true })
console.log(`Android wrapper package ready: ${wrapperDir}`)
console.log(`Android Maven repo ready: ${mavenDir}`)

64
scripts/package-ios.mjs Normal file
View File

@@ -0,0 +1,64 @@
import { cpSync, existsSync, mkdirSync, readdirSync, rmSync } from 'node:fs'
import path from 'node:path'
import { spawnSync } from 'node:child_process'
import { fileURLToPath } from 'node:url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const rootDir = path.resolve(__dirname, '..')
const distDir = path.join(rootDir, 'dist', 'ios')
const tempArtifactsDir = path.join(distDir, '.artifacts')
const packageDir = path.join(distDir, 'DuooomiBleWrapper')
const frameworksDir = path.join(packageDir, 'Frameworks')
const wrapperTemplateDir = path.join(rootDir, 'wrappers', 'ios')
function run(command, args) {
const executable = process.platform === 'win32' ? `${command}.cmd` : command
const result = spawnSync(executable, args, {
cwd: rootDir,
stdio: 'inherit',
})
if (result.status !== 0) {
process.exit(result.status ?? 1)
}
}
function findDirectoryByName(dir, expectedName) {
for (const entry of readdirSync(dir, { withFileTypes: true })) {
const fullPath = path.join(dir, entry.name)
if (entry.isDirectory() && entry.name === expectedName) {
return fullPath
}
}
return null
}
rmSync(distDir, { recursive: true, force: true })
mkdirSync(frameworksDir, { recursive: true })
run('pnpx', ['expo-brownfield', 'build:ios', '--release', '--artifacts', tempArtifactsDir])
const sdkFramework = findDirectoryByName(tempArtifactsDir, 'DuooomiBleSDK.xcframework')
const hermesFramework = findDirectoryByName(tempArtifactsDir, 'hermesvm.xcframework')
if (!sdkFramework) {
throw new Error(`Missing iOS artifact: ${path.join(tempArtifactsDir, 'DuooomiBleSDK.xcframework')}`)
}
if (!hermesFramework) {
throw new Error(`Missing iOS artifact: ${path.join(tempArtifactsDir, 'hermesvm.xcframework')}`)
}
cpSync(wrapperTemplateDir, packageDir, { recursive: true })
cpSync(sdkFramework, path.join(frameworksDir, 'DuooomiBleSDK.xcframework'), { recursive: true })
cpSync(hermesFramework, path.join(frameworksDir, 'hermesvm.xcframework'), { recursive: true })
rmSync(tempArtifactsDir, { recursive: true, force: true })
if (!existsSync(path.join(packageDir, 'Package.swift'))) {
throw new Error('Swift wrapper package is incomplete: missing Package.swift')
}
console.log(`iOS wrapper package ready: ${packageDir}`)