11const fs = require ( 'fs' ) ;
22const path = require ( 'path' ) ;
33const { execSync } = require ( 'child_process' ) ;
4- const packageJSON = require ( '../package.json' ) ;
4+ const packageJSON = require ( '../packages/react-native-gesture-handler/ package.json' ) ;
55
66const ERROR_PREFIX = 'react-native-gesture-handler' ;
7- const ROOT_DIR = path . resolve ( __dirname , '..' ) ;
7+ const ROOT_DIR = path . resolve (
8+ __dirname ,
9+ '../packages/react-native-gesture-handler'
10+ ) ;
811const ANDROID_DIR = path . resolve ( ROOT_DIR , 'android' ) ;
912const GENERATED_DIR = path . resolve ( ANDROID_DIR , 'build/generated' ) ;
1013const OLD_ARCH_DIR = path . resolve ( ANDROID_DIR , 'paper/src/main' ) ;
1114const SPECS_DIR = path . resolve ( ROOT_DIR , packageJSON . codegenConfig . jsSrcsDir ) ;
1215const PACKAGE_NAME = packageJSON . codegenConfig . android . javaPackageName ;
13- const RN_DIR = path . resolve ( ROOT_DIR , 'node_modules/react-native' ) ;
16+ const RN_DIR = path . resolve ( __dirname , '../ node_modules/react-native' ) ;
1417const RN_CODEGEN_DIR = path . resolve (
15- ROOT_DIR ,
16- 'node_modules/@react-native/codegen'
18+ __dirname ,
19+ '../ node_modules/@react-native/codegen'
1720) ;
1821
1922const SOURCE_FOLDER = 'java/com/facebook/react/viewmanagers' ;
20- const GH_SOURCE_FOLDER = 'java/com/swmansion/gesturehandler'
23+ const GH_SOURCE_FOLDER = 'java/com/swmansion/gesturehandler' ;
2124
2225const SOURCE_FOLDERS = [
23- { codegenPath : `${ GENERATED_DIR } /source/codegen/${ SOURCE_FOLDER } ` , oldArchPath : `${ OLD_ARCH_DIR } /${ SOURCE_FOLDER } ` } ,
24- { codegenPath : `${ GENERATED_DIR } /source/codegen/${ GH_SOURCE_FOLDER } ` , oldArchPath : `${ OLD_ARCH_DIR } /${ GH_SOURCE_FOLDER } ` } ,
25- ]
26-
27- const BLACKLISTED_FILES = new Set ( [
28- 'ReactContextExtensions.kt' ,
29- ] ) ;
26+ {
27+ codegenPath : `${ GENERATED_DIR } /source/codegen/${ SOURCE_FOLDER } ` ,
28+ oldArchPath : `${ OLD_ARCH_DIR } /${ SOURCE_FOLDER } ` ,
29+ } ,
30+ {
31+ codegenPath : `${ GENERATED_DIR } /source/codegen/${ GH_SOURCE_FOLDER } ` ,
32+ oldArchPath : `${ OLD_ARCH_DIR } /${ GH_SOURCE_FOLDER } ` ,
33+ } ,
34+ ] ;
35+
36+ const BLACKLISTED_FILES = new Set ( [ 'ReactContextExtensions.kt' ] ) ;
3037
3138function exec ( command ) {
3239 console . log ( `[${ ERROR_PREFIX } ]> ` + command ) ;
3340 execSync ( command ) ;
3441}
3542
3643function readdirSync ( dir ) {
37- return fs . readdirSync ( dir ) . filter ( file => ! BLACKLISTED_FILES . has ( file ) ) ;
44+ return fs . readdirSync ( dir ) . filter ( ( file ) => ! BLACKLISTED_FILES . has ( file ) ) ;
3845}
3946
4047function fixOldArchJavaForRN72Compat ( dir ) {
4148 // see https://github.com/rnmapbox/maps/issues/3193
4249 const files = readdirSync ( dir ) ;
43- files . forEach ( file => {
50+ files . forEach ( ( file ) => {
4451 const filePath = path . join ( dir , file ) ;
4552 const fileExtension = path . extname ( file ) ;
4653 if ( fileExtension === '.java' ) {
@@ -82,12 +89,12 @@ async function generateCodegen() {
8289async function generateCodegenJavaOldArch ( ) {
8390 await generateCodegen ( ) ;
8491
85- SOURCE_FOLDERS . forEach ( ( { codegenPath, oldArchPath} ) => {
92+ SOURCE_FOLDERS . forEach ( ( { codegenPath, oldArchPath } ) => {
8693 const generatedFiles = readdirSync ( codegenPath ) ;
8794 const oldArchFiles = readdirSync ( oldArchPath ) ;
88- const existingFilesSet = new Set ( oldArchFiles . map ( fileName => fileName ) ) ;
95+ const existingFilesSet = new Set ( oldArchFiles . map ( ( fileName ) => fileName ) ) ;
8996
90- generatedFiles . forEach ( generatedFile => {
97+ generatedFiles . forEach ( ( generatedFile ) => {
9198 if ( ! existingFilesSet . has ( generatedFile ) ) {
9299 console . warn (
93100 `[${ ERROR_PREFIX } ] ${ generatedFile } not found in paper dir, if it's used on Android you need to copy it manually and implement yourself before using auto-copy feature.`
@@ -101,7 +108,7 @@ async function generateCodegenJavaOldArch() {
101108 ) ;
102109 }
103110
104- oldArchFiles . forEach ( file => {
111+ oldArchFiles . forEach ( ( file ) => {
105112 if ( ! fs . existsSync ( `${ codegenPath } /${ file } ` ) ) {
106113 console . warn (
107114 `[${ ERROR_PREFIX } ] ${ file } file does not exist in codegen artifacts source destination. Please check if you still need this interface/delagete.`
@@ -127,9 +134,9 @@ function compareFileAtTwoPaths(filename, firstPath, secondPath) {
127134async function checkCodegenIntegrity ( ) {
128135 await generateCodegen ( ) ;
129136
130- SOURCE_FOLDERS . forEach ( ( { codegenPath, oldArchPath} ) => {
137+ SOURCE_FOLDERS . forEach ( ( { codegenPath, oldArchPath } ) => {
131138 const oldArchFiles = readdirSync ( oldArchPath ) ;
132- oldArchFiles . forEach ( file => {
139+ oldArchFiles . forEach ( ( file ) => {
133140 compareFileAtTwoPaths ( file , codegenPath , oldArchPath ) ;
134141 } ) ;
135142 } ) ;
0 commit comments