65 lines
2.3 KiB
JavaScript
65 lines
2.3 KiB
JavaScript
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}`)
|