-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost-script.js
More file actions
60 lines (51 loc) · 1.68 KB
/
post-script.js
File metadata and controls
60 lines (51 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* @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/nitroswitch/views',
file
)
const viewManagerStr = await readFile(viewManagerFile, { encoding: 'utf8' })
await writeFile(
viewManagerFile,
viewManagerStr.replace(
/com\.margelo\.nitro\.nitroswitch\.\*/g,
'com.nitroswitch.*'
)
)
}
const androidWorkaround = async () => {
const androidOnLoadFile = path.join(
process.cwd(),
'nitrogen/generated/android',
'NitroSwitchOnLoad.cpp'
)
const viewManagerDir = await readdir(
path.join(
process.cwd(),
'nitrogen/generated/android/kotlin/com/margelo/nitro/nitroswitch/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()