55 * - Replaces 'com.margelo.nitro.rngooglemapsplus' -> 'com.rngooglemapsplus'
66 * - Replaces 'com/margelo/nitro/rngooglemapsplus' -> 'com/rngooglemapsplus'
77 * - Removes 'margelo/nitro/' in RNGoogleMapsPlusOnLoad.cpp
8- * - Inserts `onDropViewInstance()`
9- * nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/views/HybridRNGoogleMapsPlusViewManager.kt
10- *
118 * iOS
12- * - Inserts `+ (void)dealloc`
13- * nitrogen/generated/ios/c++/views/HybridRNGoogleMapsPlusViewComponent.mm
149 */
1510import { readFile , readdir , writeFile } from 'node:fs/promises' ;
1611import { copyFile , mkdir } from 'node:fs/promises' ;
1712import path from 'node:path' ;
18- import { basename } from 'path' ;
19- import { fileURLToPath } from 'url' ;
2013
2114const ROOT_ANDROID = path . join (
2215 process . cwd ( ) ,
2316 'nitrogen' ,
2417 'generated' ,
2518 'android'
2619) ;
27- const ROOT_IOS = path . join ( process . cwd ( ) , 'nitrogen' , 'generated' , 'ios' ) ;
20+
2821const SRC_JSON_DIR = path . join (
2922 process . cwd ( ) ,
3023 'nitrogen' ,
3124 'generated' ,
3225 'shared' ,
3326 'json'
3427) ;
28+
3529const DEST_JSON_DIR = path . join (
3630 process . cwd ( ) ,
3731 'lib' ,
@@ -46,16 +40,6 @@ const ANDROID_ONLOAD_FILE = path.join(
4640 'RNGoogleMapsPlusOnLoad.cpp'
4741) ;
4842
49- const HYBRID_VIEW_MANAGER = path . join (
50- ROOT_ANDROID ,
51- 'kotlin/com/margelo/nitro/rngooglemapsplus/views/HybridRNGoogleMapsPlusViewManager.kt'
52- ) ;
53-
54- const HYBRID_VIEW_COMPONENT_IOS = path . join (
55- ROOT_IOS ,
56- 'c++/views/HybridRNGoogleMapsPlusViewComponent.mm'
57- ) ;
58-
5943const REPLACEMENTS = [
6044 {
6145 regex : / c o m \. m a r g e l o \. n i t r o \. r n g o o g l e m a p s p l u s / g,
@@ -67,30 +51,6 @@ const REPLACEMENTS = [
6751 } ,
6852] ;
6953
70- const __filename = fileURLToPath ( import . meta. url ) ;
71- const filename = basename ( __filename ) ;
72-
73- const PATCH_MARKER = ` // added by ${ filename } ` ;
74-
75- const ON_DROP_VIEW_INSTANCE_ANDROID = `
76- ${ PATCH_MARKER }
77- override fun onDropViewInstance(view: View) {
78- val hybridView = view.getTag(associated_hybrid_view_tag) as? RNGoogleMapsPlusView
79- hybridView?.dispose()
80- view.setTag(associated_hybrid_view_tag, null)
81- super.onDropViewInstance(view)
82- }` ;
83-
84- const DEALLOC_METHOD_IOS = `
85- ${ PATCH_MARKER }
86- - (void)dealloc {
87- if (_hybridView) {
88- RNGoogleMapsPlus::HybridRNGoogleMapsPlusViewSpec_cxx& swiftPart = _hybridView->getSwiftPart();
89- swiftPart.dispose();
90- _hybridView.reset();
91- }
92- }` ;
93-
9454async function processFile ( filePath ) {
9555 let content = await readFile ( filePath , 'utf8' ) ;
9656 let updated = content ;
@@ -103,36 +63,6 @@ async function processFile(filePath) {
10363 updated = updated . replace ( / m a r g e l o \/ n i t r o \/ / g, '' ) ;
10464 }
10565
106- if ( path . resolve ( filePath ) === path . resolve ( HYBRID_VIEW_MANAGER ) ) {
107- if ( ! updated . includes ( PATCH_MARKER ) ) {
108- const pattern = / ( o v e r r i d e \s + f u n \s + c r e a t e V i e w I n s t a n c e [ \s \S ] * ?\} ) / m;
109-
110- if ( ! pattern . test ( updated ) ) {
111- throw new Error (
112- `Pattern for "createViewInstance" not found in ${ filePath } `
113- ) ;
114- }
115-
116- updated = updated . replace (
117- pattern ,
118- `$1\n${ ON_DROP_VIEW_INSTANCE_ANDROID } `
119- ) ;
120- }
121- }
122-
123- if ( path . resolve ( filePath ) === path . resolve ( HYBRID_VIEW_COMPONENT_IOS ) ) {
124- if ( ! updated . includes ( PATCH_MARKER ) ) {
125- const initPattern =
126- / ( - \s * \( i n s t a n c e t y p e \) \s * i n i t [ \s \S ] * ?r e t u r n \s + s e l f ; \s * \} ) / m;
127-
128- if ( ! initPattern . test ( updated ) ) {
129- throw new Error ( `Pattern for "init" not found in ${ filePath } ` ) ;
130- }
131-
132- updated = updated . replace ( initPattern , `$1\n${ DEALLOC_METHOD_IOS } ` ) ;
133- }
134- }
135-
13666 if ( updated !== content ) {
13767 await writeFile ( filePath , updated , 'utf8' ) ;
13868 console . log ( `Updated: ${ filePath } ` ) ;
@@ -172,7 +102,6 @@ async function copyJsonFiles() {
172102 try {
173103 await copyJsonFiles ( ) ;
174104 await start ( ROOT_ANDROID ) ;
175- await start ( ROOT_IOS ) ;
176105 console . log ( 'All Nitrogen files patched successfully.' ) ;
177106 } catch ( err ) {
178107 console . error ( 'Error while processing files:' , err ) ;
0 commit comments