Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Refactore gradle task to JS scripts #3001

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/check-archs-consistency.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Test consistency between Paper & Fabric
on:
pull_request:
branches:
- main
paths:
- src/specs/**
- android/paper/**
- .github/workflows/check-archs-consistency.yml
push:
branches:
- main
workflow_dispatch:
maciekstosio marked this conversation as resolved.
Show resolved Hide resolved

jobs:
check:
runs-on: ubuntu-latest
concurrency:
group: check-archs-consistency-${{ github.ref }}
cancel-in-progress: true
steps:
- name: checkout
uses: actions/checkout@v4
- name: Use Node.js 18
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'yarn'
- name: Install node dependencies
run: yarn
- name: Check Android Paper & Fabric generated interfaces consistency
run: yarn architectures-consistency-check
57 changes: 0 additions & 57 deletions .github/workflows/check-paper-integrity.yml

This file was deleted.

2 changes: 0 additions & 2 deletions FabricExample/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,3 @@ newArchEnabled=true
# Use this property to enable or disable the Hermes JS engine.
# If set to false, you will be using JSC instead.
hermesEnabled=true

isGHExampleApp=true
103 changes: 0 additions & 103 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -207,106 +207,3 @@ dependencies {
implementation "androidx.core:core-ktx:1.6.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

def isGHExampleApp() {
return project.hasProperty('isGHExampleApp') && project.property('isGHExampleApp') == "true"
}

def getAbsoluteCodegenArtifactsPaperDestination() {
if (!project.hasProperty('codegenArtifactsPaperDestination')) {
throw new Exception('[react-native-gesture-handler] Please fill codegenArtifactsPaperDestination variable in android/gradle.properties to point to the correct path to generated specs for paper')
}

return "${project.rootDir}/../../${project.property('codegenArtifactsPaperDestination')}"
}

def getAbsoluteCodegenArtifactsSource() {
if (!project.hasProperty('codegenArtifactsSource')) {
throw new Exception('[react-native-gesture-handler] Please fill codegenArtifactsSource variable in android/gradle.properties to point to the correct path to codegenerated artifacts')
}

return "${project.rootDir}/../../${project.property('codegenArtifactsSource')}"
}


tasks.register('copyCodegenArtifacts') {
group 'After build tasks'
description 'Task which copies codegen artifacts to paper architecture'

if (!isGHExampleApp() || !isNewArchitectureEnabled()) {
return
}

dependsOn tasks.generateCodegenArtifactsFromSchema

doLast {

def absoluteCodegenArtifactsPaperDestination = getAbsoluteCodegenArtifactsPaperDestination()
def absoluteCodegenArtifactsSource = getAbsoluteCodegenArtifactsSource()

def existingFiles = fileTree(absoluteCodegenArtifactsPaperDestination).matching {
include '**/*.java'
}

def generatedFiles = fileTree(absoluteCodegenArtifactsSource).matching {
include '**/*.java'
}

def existingFilesMap = [:]

existingFiles.forEach { existingFile ->
println existingFile
existingFilesMap[existingFile.name] = 1
}

generatedFiles.forEach { generatedFile ->
if (!existingFilesMap.containsKey(generatedFile.name)) {
logger.warn("[react-native-gesture-handler] ${generatedFile.name} 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.")
}
}

if (existingFiles.size() == 0) {
logger.warn("[react-native-gesture-handler] Paper destination with codegen interfaces is empty. This might be okay if you don't have any interfaces/delegates used on Android, but if that's not the case please check if codegenArtifactsPaperDestination property in android/gradle.properties is correct.")
}

existingFiles.forEach { existingFile ->
def generatedFile = new File("${absoluteCodegenArtifactsSource}/${existingFile.name}")

if (!generatedFile.exists()) {
logger.warn("[react-native-gesture-handler] ${existingFile.name} file does not exist in codegen artifacts source destination. Please check if you still need this interface/delagete.")
}
}

copy {
from absoluteCodegenArtifactsSource
include existingFiles.collect { it.name }
into absoluteCodegenArtifactsPaperDestination
}
}
}

if (isGHExampleApp() && isNewArchitectureEnabled() && !project.hasProperty('skipCodegenCopyTask')) {
tasks.generateCodegenArtifactsFromSchema.finalizedBy('copyCodegenArtifacts')
}

if (project == rootProject) {
tasks.register('checkIntegrityBetweenArchitectures') {
group 'Verification tasks'
description 'Task to check integrity between fabric and paper architecture in terms of codegen generated interfaces/delegates'

def absoluteCodegenArtifactsPaperDestination = "../${project.property('codegenArtifactsPaperDestination')}"
def absoluteCodegenArtifactsSource = "../${project.property('codegenArtifactsSource')}"

def existingFiles = fileTree(absoluteCodegenArtifactsPaperDestination).matching {
include '**/*.java'
}

existingFiles.forEach { existingFile ->
def generatedFile = new File("${absoluteCodegenArtifactsSource}/${existingFile.name}")

if (existingFile.text != generatedFile.text) {
throw new RuntimeException("[react-native-gesture-handler] The source of ${existingFile.name} does not match with the one generated by codegen. Please check if you commited changes produced by copyCodegenArtifacts task.")
}
}
}
}
7 changes: 0 additions & 7 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,3 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemor
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
RNGH_kotlinVersion=1.6.21

# Path to codegen output directory with this library view managers' interfaces & delegates. Used by `copyCodegenArtifacts` task that helps to synchronize newly generated files with their Paper counterparts.
codegenArtifactsSource=android/build/generated/source/codegen/java/com/facebook/react/viewmanagers

# Path to directory with view managers' interfaces & delegates used while running on Paper architecture. This property is used as the output path for `copyCodegenArtifacts` task.
# Used by copyCodegenArtifacts task that automates copying those interfaces/delegates after codegen is run.
codegenArtifactsPaperDestination=android/paper/src/main/java/com/facebook/react/viewmanagers
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@

/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GenerateModuleJavaSpec.js
*
* @nolint
*/

package com.swmansion.gesturehandler;

import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReactModuleWithSpec;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
import javax.annotation.Nonnull;
import com.facebook.react.bridge.ReactMethod;

public abstract class NativeRNGestureHandlerModuleSpec extends ReactContextBaseJavaModule implements TurboModule {
public abstract class NativeRNGestureHandlerModuleSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
public static final String NAME = "RNGestureHandlerModule";

public NativeRNGestureHandlerModuleSpec(ReactApplicationContext reactContext) {
Expand All @@ -21,35 +33,35 @@ public NativeRNGestureHandlerModuleSpec(ReactApplicationContext reactContext) {
return NAME;
}

@DoNotStrip
@ReactMethod
@DoNotStrip
public abstract void handleSetJSResponder(double tag, boolean blockNativeResponder);

@DoNotStrip
@ReactMethod
@DoNotStrip
public abstract void handleClearJSResponder();

@DoNotStrip
@ReactMethod
@DoNotStrip
public abstract void createGestureHandler(String handlerName, double handlerTag, ReadableMap config);

@DoNotStrip
@ReactMethod
@DoNotStrip
public abstract void attachGestureHandler(double handlerTag, double newView, double actionType);

@DoNotStrip
@ReactMethod
@DoNotStrip
public abstract void updateGestureHandler(double handlerTag, ReadableMap newConfig);

@DoNotStrip
@ReactMethod
@DoNotStrip
public abstract void dropGestureHandler(double handlerTag);

@ReactMethod(isBlockingSynchronousMethod = true)
@DoNotStrip
@ReactMethod
public abstract boolean install();

@DoNotStrip
@ReactMethod
@DoNotStrip
public abstract void flushOperations();
}
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
"lint:js": "eslint --ext '.js,.ts,.tsx' src/ example/src FabricExample/src MacOSExample/src && yarn prettier --check './{src,example,FabricExample,MacOSExample}/**/*.{js,jsx,ts,tsx}'",
"lint:js-root": "eslint --ext '.js,.ts,.tsx' src/ && yarn prettier --check './src/**/*.{js,jsx,ts,tsx}'",
"lint:android": "./android/gradlew -p android spotlessCheck -q",
"cross-arch-integrity-check": "(cd ./FabricExample/android && ./gradlew generateCodegenArtifactsFromSchema -PskipCodegenCopyTask) && (cd ./android && ./gradlew checkIntegrityBetweenArchitectures)",
"circular-dependency-check": "yarn madge --extensions js,ts,tsx --circular src"
"circular-dependency-check": "yarn madge --extensions js,ts,tsx --circular src",
"architectures-consistency-check": "node ./scripts/codegen-check-consistency.js",
"sync-architectures": "node ./scripts/codegen-sync-archs.js"
},
"react-native": "src/index.ts",
"main": "lib/commonjs/index.js",
Expand Down Expand Up @@ -98,13 +99,13 @@
"eslint-plugin-jest": "^26.0.0",
"expo": "^35.0.1",
"husky": "^8.0.1",
"jest": "^26.6.3",
"jest": "^28.1.0",
"lint-staged": "^12.3.2",
"madge": "^6.1.0",
"prettier": "2.7.1",
"react": "18.2.0",
"react-dom": "^16.12.0",
"react-native": "0.74.1",
"react-native": "0.74.3",
"react-native-builder-bob": "^0.17.1",
"react-native-reanimated": "^3.12.0",
"react-native-web": "^0.11.7",
Expand All @@ -119,7 +120,8 @@
"lint-staged": {
"./{src,example,FabricExample,MacOSExample}/**/*.{ts,tsx}": "yarn format:js",
"android/**/*.kt": "yarn format:android",
"apple/**/*.{h,m,mm,cpp}": "yarn format:ios"
"apple/**/*.{h,m,mm,cpp}": "yarn format:ios",
"src/specs/*.ts": "yarn sync-architectures"
},
"release-it": {
"hooks": {
Expand Down
3 changes: 3 additions & 0 deletions scripts/codegen-check-consistency.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { checkCodegenIntegrity } = require('./codegen-utils');

checkCodegenIntegrity();
3 changes: 3 additions & 0 deletions scripts/codegen-sync-archs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { generateCodegenJavaOldArch } = require('./codegen-utils');

generateCodegenJavaOldArch();
Loading
Loading