mirror of
https://github.com/zoriya/react-native-omni.git
synced 2026-08-06 06:07:30 +00:00
60 lines
1.6 KiB
JavaScript
60 lines
1.6 KiB
JavaScript
/**
|
|
* @file This script is auto-generated by create-nitro-module and should not be edited.
|
|
*
|
|
* @description This script applies a workaround for Android by modifying the '<ModuleName>OnLoad.cpp' file.
|
|
* It reads the file content and removes the 'margelo/nitro/' string from it. This enables support for custom package names.
|
|
*
|
|
* @module create-nitro-module
|
|
*/
|
|
const path = require('node:path')
|
|
const { writeFile, readFile } = require('node:fs/promises')
|
|
const { readdir } = require('node:fs/promises')
|
|
|
|
|
|
const updateViewManagerFiles = async (file) => {
|
|
const viewManagerFile = path.join(
|
|
process.cwd(),
|
|
'nitrogen/generated/android/kotlin/com/margelo/nitro/omni/views',
|
|
file
|
|
)
|
|
|
|
const viewManagerStr = await readFile(viewManagerFile, { encoding: 'utf8' })
|
|
await writeFile(
|
|
viewManagerFile,
|
|
viewManagerStr.replace(
|
|
/com\.margelo\.nitro\.omni\.\*/g,
|
|
'com.omni.*'
|
|
)
|
|
)
|
|
}
|
|
|
|
|
|
const androidWorkaround = async () => {
|
|
const androidOnLoadFile = path.join(
|
|
process.cwd(),
|
|
'nitrogen/generated/android',
|
|
'OmniOnLoad.cpp'
|
|
)
|
|
|
|
const viewManagerDir = await readdir(
|
|
path.join(
|
|
process.cwd(),
|
|
'nitrogen/generated/android/kotlin/com/margelo/nitro/omni/views'
|
|
)
|
|
)
|
|
const viewManagerFiles = viewManagerDir.filter((file) =>
|
|
file.endsWith('Manager.kt')
|
|
)
|
|
const res = await Promise.allSettled(
|
|
viewManagerFiles.map(updateViewManagerFiles)
|
|
)
|
|
|
|
if (res.some((r) => r.status === 'rejected')) {
|
|
throw new Error(`Error updating view manager files: ${res}`)
|
|
}
|
|
|
|
|
|
const str = await readFile(androidOnLoadFile, { encoding: 'utf8' })
|
|
await writeFile(androidOnLoadFile, str.replace(/margelo\/nitro\//g, ''))
|
|
}
|
|
androidWorkaround() |