mirror of
https://github.com/zoriya/react-native-omni.git
synced 2026-08-05 13:46:59 +00:00
55 lines
1.6 KiB
JavaScript
55 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, "dev.zoriya.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(/com\/margelo\/nitro\//g, "dev/zoriya/"));
|
|
};
|
|
androidWorkaround();
|