@react-native/gradle-plugin 0.72.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +16 -0
  2. package/build.gradle.kts +68 -0
  3. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  4. package/gradle/wrapper/gradle-wrapper.properties +5 -0
  5. package/gradlew +234 -0
  6. package/gradlew.bat +89 -0
  7. package/package.json +28 -0
  8. package/settings.gradle.kts +16 -0
  9. package/src/main/kotlin/com/facebook/react/ReactExtension.kt +151 -0
  10. package/src/main/kotlin/com/facebook/react/ReactPlugin.kt +163 -0
  11. package/src/main/kotlin/com/facebook/react/TaskConfiguration.kt +76 -0
  12. package/src/main/kotlin/com/facebook/react/model/ModelCodegenConfig.kt +15 -0
  13. package/src/main/kotlin/com/facebook/react/model/ModelCodegenConfigAndroid.kt +10 -0
  14. package/src/main/kotlin/com/facebook/react/model/ModelPackageJson.kt +10 -0
  15. package/src/main/kotlin/com/facebook/react/tasks/BuildCodegenCLITask.kt +58 -0
  16. package/src/main/kotlin/com/facebook/react/tasks/BundleHermesCTask.kt +190 -0
  17. package/src/main/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTask.kt +81 -0
  18. package/src/main/kotlin/com/facebook/react/tasks/GenerateCodegenSchemaTask.kt +80 -0
  19. package/src/main/kotlin/com/facebook/react/tasks/internal/PrepareBoostTask.kt +46 -0
  20. package/src/main/kotlin/com/facebook/react/tasks/internal/PrepareGlogTask.kt +79 -0
  21. package/src/main/kotlin/com/facebook/react/tasks/internal/PrepareJSCTask.kt +50 -0
  22. package/src/main/kotlin/com/facebook/react/tasks/internal/PrepareLibeventTask.kt +51 -0
  23. package/src/main/kotlin/com/facebook/react/tasks/internal/PreparePrefabHeadersTask.kt +62 -0
  24. package/src/main/kotlin/com/facebook/react/tasks/internal/utils/PrefabPreprocessingEntry.kt +27 -0
  25. package/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt +54 -0
  26. package/src/main/kotlin/com/facebook/react/utils/BackwardCompatUtils.kt +48 -0
  27. package/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt +89 -0
  28. package/src/main/kotlin/com/facebook/react/utils/FileUtils.kt +20 -0
  29. package/src/main/kotlin/com/facebook/react/utils/JsonUtils.kt +21 -0
  30. package/src/main/kotlin/com/facebook/react/utils/NdkConfiguratorUtils.kt +139 -0
  31. package/src/main/kotlin/com/facebook/react/utils/Os.kt +31 -0
  32. package/src/main/kotlin/com/facebook/react/utils/PathUtils.kt +220 -0
  33. package/src/main/kotlin/com/facebook/react/utils/ProjectUtils.kt +46 -0
  34. package/src/main/kotlin/com/facebook/react/utils/TaskUtils.kt +28 -0
@@ -0,0 +1,46 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.facebook.react.tasks.internal
9
+
10
+ import java.io.File
11
+ import org.gradle.api.DefaultTask
12
+ import org.gradle.api.file.ConfigurableFileCollection
13
+ import org.gradle.api.file.DirectoryProperty
14
+ import org.gradle.api.provider.Property
15
+ import org.gradle.api.tasks.*
16
+
17
+ /**
18
+ * A task that takes care of extracting Boost from a source folder/zip and preparing it to be
19
+ * consumed by the NDK
20
+ */
21
+ abstract class PrepareBoostTask : DefaultTask() {
22
+
23
+ @get:InputFiles abstract val boostPath: ConfigurableFileCollection
24
+
25
+ @get:Input abstract val boostVersion: Property<String>
26
+
27
+ @get:OutputDirectory abstract val outputDir: DirectoryProperty
28
+
29
+ @TaskAction
30
+ fun taskAction() {
31
+ project.copy { it ->
32
+ it.from(boostPath)
33
+ it.from(project.file("src/main/jni/third-party/boost"))
34
+ it.include(
35
+ "CMakeLists.txt",
36
+ "boost_${boostVersion.get()}/boost/**/*.hpp",
37
+ "boost/boost/**/*.hpp",
38
+ "asm/**/*.S")
39
+ it.includeEmptyDirs = false
40
+ it.into(outputDir)
41
+ }
42
+ File(outputDir.asFile.get(), "boost").apply {
43
+ renameTo(File(this.parentFile, "boost_${boostVersion.get()}"))
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,79 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.facebook.react.tasks.internal
9
+
10
+ import java.io.File
11
+ import org.apache.tools.ant.filters.ReplaceTokens
12
+ import org.gradle.api.DefaultTask
13
+ import org.gradle.api.file.ConfigurableFileCollection
14
+ import org.gradle.api.file.DirectoryProperty
15
+ import org.gradle.api.file.DuplicatesStrategy
16
+ import org.gradle.api.provider.Property
17
+ import org.gradle.api.tasks.*
18
+
19
+ /**
20
+ * A task that takes care of extracting Glog from a source folder/zip and preparing it to be
21
+ * consumed by the NDK. This task will also take care of applying the mapping for Glog parameters.
22
+ */
23
+ abstract class PrepareGlogTask : DefaultTask() {
24
+
25
+ @get:InputFiles abstract val glogPath: ConfigurableFileCollection
26
+
27
+ @get:Input abstract val glogVersion: Property<String>
28
+
29
+ @get:OutputDirectory abstract val outputDir: DirectoryProperty
30
+
31
+ @TaskAction
32
+ fun taskAction() {
33
+ project.copy {
34
+ it.from(glogPath)
35
+ it.from(project.file("src/main/jni/third-party/glog/"))
36
+ it.include("glog-${glogVersion.get()}/src/**/*", "CMakeLists.txt", "config.h")
37
+ it.duplicatesStrategy = DuplicatesStrategy.WARN
38
+ it.includeEmptyDirs = false
39
+ it.filesMatching("**/*.h.in") { matchedFile ->
40
+ matchedFile.filter(
41
+ mapOf(
42
+ "tokens" to
43
+ mapOf(
44
+ "ac_cv_have_unistd_h" to "1",
45
+ "ac_cv_have_stdint_h" to "1",
46
+ "ac_cv_have_systypes_h" to "1",
47
+ "ac_cv_have_inttypes_h" to "1",
48
+ "ac_cv_have_libgflags" to "0",
49
+ "ac_google_start_namespace" to "namespace google {",
50
+ "ac_cv_have_uint16_t" to "1",
51
+ "ac_cv_have_u_int16_t" to "1",
52
+ "ac_cv_have___uint16" to "0",
53
+ "ac_google_end_namespace" to "}",
54
+ "ac_cv_have___builtin_expect" to "1",
55
+ "ac_google_namespace" to "google",
56
+ "ac_cv___attribute___noinline" to "__attribute__ ((noinline))",
57
+ "ac_cv___attribute___noreturn" to "__attribute__ ((noreturn))",
58
+ "ac_cv___attribute___printf_4_5" to
59
+ "__attribute__((__format__ (__printf__, 4, 5)))")),
60
+ ReplaceTokens::class.java)
61
+ matchedFile.path = (matchedFile.name.removeSuffix(".in"))
62
+ }
63
+ it.into(outputDir)
64
+ }
65
+ val exportedDir = File(outputDir.asFile.get(), "exported/glog/").apply { mkdirs() }
66
+ project.copy {
67
+ it.from(outputDir)
68
+ it.include(
69
+ "stl_logging.h",
70
+ "logging.h",
71
+ "raw_logging.h",
72
+ "vlog_is_on.h",
73
+ "**/src/glog/log_severity.h")
74
+ it.eachFile { file -> file.path = file.name }
75
+ it.includeEmptyDirs = false
76
+ it.into(exportedDir)
77
+ }
78
+ }
79
+ }
@@ -0,0 +1,50 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.facebook.react.tasks.internal
9
+
10
+ import java.io.File
11
+ import org.gradle.api.DefaultTask
12
+ import org.gradle.api.file.DirectoryProperty
13
+ import org.gradle.api.provider.Property
14
+ import org.gradle.api.tasks.*
15
+
16
+ /**
17
+ * A task that takes care of unbundling JSC and preparing it for be consumed by the Android NDK.
18
+ * Specifically it will unbundle shared libs, headers and will copy over the Makefile from
19
+ * `src/main/jni/third-party/jsc/`
20
+ */
21
+ abstract class PrepareJSCTask : DefaultTask() {
22
+
23
+ @get:Input abstract val jscPackagePath: Property<String>
24
+
25
+ @get:OutputDirectory abstract val outputDir: DirectoryProperty
26
+
27
+ @TaskAction
28
+ fun taskAction() {
29
+ if (!jscPackagePath.isPresent || jscPackagePath.orNull == null) {
30
+ error("Could not find the jsc-android npm package")
31
+ }
32
+ val jscDist = File(jscPackagePath.get(), "dist")
33
+ if (!jscDist.exists()) {
34
+ error("The jsc-android npm package is missing its \"dist\" directory")
35
+ }
36
+ val jscAAR =
37
+ project.fileTree(jscDist).matching { it.include("**/android-jsc/**/*.aar") }.singleFile
38
+ val soFiles = project.zipTree(jscAAR).matching { it.include("**/*.so") }
39
+ val headerFiles = project.fileTree(jscDist).matching { it.include("**/include/*.h") }
40
+
41
+ project.copy { it ->
42
+ it.from(soFiles)
43
+ it.from(headerFiles)
44
+ it.from(project.file("src/main/jni/third-party/jsc/CMakeLists.txt"))
45
+ it.filesMatching("**/*.h") { it.path = "JavaScriptCore/${it.name}" }
46
+ it.includeEmptyDirs = false
47
+ it.into(outputDir)
48
+ }
49
+ }
50
+ }
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.facebook.react.tasks.internal
9
+
10
+ import java.io.File
11
+ import org.gradle.api.DefaultTask
12
+ import org.gradle.api.file.ConfigurableFileCollection
13
+ import org.gradle.api.file.DirectoryProperty
14
+ import org.gradle.api.provider.Property
15
+ import org.gradle.api.tasks.*
16
+
17
+ /**
18
+ * A task that takes care of extracting Libevent from a source folder/zip and preparing it to be
19
+ * consumed by the NDK.
20
+ */
21
+ abstract class PrepareLibeventTask : DefaultTask() {
22
+
23
+ @get:InputFiles abstract val libeventPath: ConfigurableFileCollection
24
+
25
+ @get:Input abstract val libeventVersion: Property<String>
26
+
27
+ @get:OutputDirectory abstract val outputDir: DirectoryProperty
28
+
29
+ @TaskAction
30
+ fun taskAction() {
31
+ project.copy { it ->
32
+ it.from(libeventPath)
33
+ it.from(project.file("src/main/jni/third-party/libevent/"))
34
+ it.include(
35
+ "libevent-${libeventVersion.get()}-stable/*.c",
36
+ "libevent-${libeventVersion.get()}-stable/*.h",
37
+ "libevent-${libeventVersion.get()}-stable/include/**/*",
38
+ "evconfig-private.h",
39
+ "event-config.h",
40
+ "CMakeLists.txt")
41
+ it.eachFile { it.path = it.path.removePrefix("libevent-${libeventVersion.get()}-stable/") }
42
+ it.includeEmptyDirs = false
43
+ it.into(outputDir)
44
+ }
45
+ File(outputDir.asFile.get(), "event-config.h").apply {
46
+ val destination =
47
+ File(this.parentFile, "include/event2/event-config.h").apply { parentFile.mkdirs() }
48
+ renameTo(destination)
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,62 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.facebook.react.tasks.internal
9
+
10
+ import com.facebook.react.tasks.internal.utils.PrefabPreprocessingEntry
11
+ import java.io.File
12
+ import javax.inject.Inject
13
+ import org.gradle.api.DefaultTask
14
+ import org.gradle.api.file.DirectoryProperty
15
+ import org.gradle.api.file.FileSystemOperations
16
+ import org.gradle.api.file.RegularFile
17
+ import org.gradle.api.provider.ListProperty
18
+ import org.gradle.api.tasks.Input
19
+ import org.gradle.api.tasks.OutputDirectory
20
+ import org.gradle.api.tasks.TaskAction
21
+
22
+ /**
23
+ * A task that takes care of copying headers and filtering them so that can be consumed by the
24
+ * Prefab protocol. This task handles also the header prefixes.
25
+ *
26
+ * It currently filters out some of the Boost headers as they're not used by React Native and are
27
+ * resulting in bigger .aar (250Mb+).
28
+ *
29
+ * You should provide in input a list fo [PrefabPreprocessingEntry] that will be used by this task
30
+ * to do the necessary copy operations.
31
+ */
32
+ abstract class PreparePrefabHeadersTask : DefaultTask() {
33
+
34
+ @get:Input abstract val input: ListProperty<PrefabPreprocessingEntry>
35
+
36
+ @get:OutputDirectory abstract val outputDir: DirectoryProperty
37
+
38
+ @get:Inject abstract val fs: FileSystemOperations
39
+
40
+ @TaskAction
41
+ fun taskAction() {
42
+ input.get().forEach { (libraryName, pathToPrefixCouples) ->
43
+ val outputFolder: RegularFile = outputDir.file(libraryName).get()
44
+ pathToPrefixCouples.forEach { (headerPath, headerPrefix) ->
45
+ fs.copy {
46
+ it.from(headerPath)
47
+ it.include("**/*.h")
48
+ it.exclude("**/*.cpp")
49
+ it.exclude("**/*.txt")
50
+ // We don't want to copy all the boost headers as they are 250Mb+
51
+ it.include("boost/config.hpp")
52
+ it.include("boost/config/**/*.hpp")
53
+ it.include("boost/core/*.hpp")
54
+ it.include("boost/detail/workaround.hpp")
55
+ it.include("boost/operators.hpp")
56
+ it.include("boost/preprocessor/**/*.hpp")
57
+ it.into(File(outputFolder.asFile, headerPrefix))
58
+ }
59
+ }
60
+ }
61
+ }
62
+ }
@@ -0,0 +1,27 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.facebook.react.tasks.internal.utils
9
+
10
+ import java.io.Serializable
11
+
12
+ /**
13
+ * This data class represents an entry that can be consumed by the [PreparePrefabHeadersTask].
14
+ * @param libraryName The name of the library that you're preparing for Prefab
15
+ * @param pathToPrefixCouples A list of pairs Path to Header prefix. You can use this list to supply
16
+ * a list of paths that you want to be considered for prefab. Each path can specify an header prefix
17
+ * that will be used by prefab to re-created the header layout.
18
+ */
19
+ data class PrefabPreprocessingEntry(
20
+ val libraryName: String,
21
+ val pathToPrefixCouples: List<Pair<String, String>>,
22
+ ) : Serializable {
23
+ constructor(
24
+ libraryName: String,
25
+ pathToPrefixCouple: Pair<String, String>
26
+ ) : this(libraryName, listOf(pathToPrefixCouple))
27
+ }
@@ -0,0 +1,54 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.facebook.react.utils
9
+
10
+ import com.android.build.api.variant.AndroidComponentsExtension
11
+ import com.facebook.react.utils.ProjectUtils.isHermesEnabled
12
+ import com.facebook.react.utils.ProjectUtils.isNewArchEnabled
13
+ import org.gradle.api.Action
14
+ import org.gradle.api.Project
15
+ import org.gradle.api.plugins.AppliedPlugin
16
+
17
+ @Suppress("UnstableApiUsage")
18
+ internal object AgpConfiguratorUtils {
19
+
20
+ fun configureBuildConfigFields(project: Project) {
21
+ val action =
22
+ Action<AppliedPlugin> {
23
+ project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext ->
24
+ ext.defaultConfig.buildConfigField(
25
+ "boolean", "IS_NEW_ARCHITECTURE_ENABLED", project.isNewArchEnabled.toString())
26
+ ext.defaultConfig.buildConfigField(
27
+ "boolean", "IS_HERMES_ENABLED", project.isHermesEnabled.toString())
28
+ }
29
+ }
30
+ project.pluginManager.withPlugin("com.android.application", action)
31
+ project.pluginManager.withPlugin("com.android.library", action)
32
+ }
33
+
34
+ fun configureDevPorts(project: Project) {
35
+ val devServerPort =
36
+ project.properties["reactNativeDevServerPort"]?.toString() ?: DEFAULT_DEV_SERVER_PORT
37
+ val inspectorProxyPort =
38
+ project.properties["reactNativeInspectorProxyPort"]?.toString() ?: devServerPort
39
+
40
+ val action =
41
+ Action<AppliedPlugin> {
42
+ project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext ->
43
+ ext.defaultConfig.resValue("integer", "react_native_dev_server_port", devServerPort)
44
+ ext.defaultConfig.resValue(
45
+ "integer", "react_native_inspector_proxy_port", inspectorProxyPort)
46
+ }
47
+ }
48
+
49
+ project.pluginManager.withPlugin("com.android.application", action)
50
+ project.pluginManager.withPlugin("com.android.library", action)
51
+ }
52
+ }
53
+
54
+ const val DEFAULT_DEV_SERVER_PORT = "8081"
@@ -0,0 +1,48 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.facebook.react.utils
9
+
10
+ import java.util.*
11
+ import org.gradle.api.Project
12
+
13
+ internal object BackwardCompatUtils {
14
+
15
+ fun configureBackwardCompatibilityReactMap(project: Project) {
16
+ if (project.extensions.extraProperties.has("react")) {
17
+ @Suppress("UNCHECKED_CAST")
18
+ val reactMap =
19
+ project.extensions.extraProperties.get("react") as? Map<String, Any?> ?: mapOf()
20
+ if (reactMap.isNotEmpty()) {
21
+ project.logger.error(
22
+ """
23
+ ********************************************************************************
24
+
25
+ ERROR: Using old project.ext.react configuration.
26
+ We identified that your project is using a old configuration block as:
27
+
28
+ project.ext.react = [
29
+ // ...
30
+ ]
31
+
32
+ You should migrate to the new configuration:
33
+
34
+ react {
35
+ // ...
36
+ }
37
+ You can find documentation inside `android/app/build.gradle` on how to use it.
38
+
39
+ ********************************************************************************
40
+ """
41
+ .trimIndent())
42
+ }
43
+ }
44
+
45
+ // We set an empty react[] map so if a library is reading it, they will find empty values.
46
+ project.extensions.extraProperties.set("react", mapOf<String, String>())
47
+ }
48
+ }
@@ -0,0 +1,89 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.facebook.react.utils
9
+
10
+ import java.io.File
11
+ import java.net.URI
12
+ import java.util.*
13
+ import org.gradle.api.Project
14
+ import org.gradle.api.artifacts.repositories.MavenArtifactRepository
15
+
16
+ internal object DependencyUtils {
17
+
18
+ /**
19
+ * This method takes care of configuring the repositories{} block for both the app and all the 3rd
20
+ * party libraries which are auto-linked.
21
+ */
22
+ fun configureRepositories(project: Project, reactNativeDir: File) {
23
+ project.rootProject.allprojects { eachProject ->
24
+ with(eachProject) {
25
+ if (hasProperty("REACT_NATIVE_MAVEN_LOCAL_REPO")) {
26
+ val mavenLocalRepoPath = property("REACT_NATIVE_MAVEN_LOCAL_REPO") as String
27
+ mavenRepoFromURI(File(mavenLocalRepoPath).toURI())
28
+ }
29
+ // We add the snapshot for users on nightlies.
30
+ mavenRepoFromUrl("https://oss.sonatype.org/content/repositories/snapshots/")
31
+ repositories.mavenCentral()
32
+ // Android JSC is installed from npm
33
+ mavenRepoFromURI(File(reactNativeDir, "../jsc-android/dist").toURI())
34
+ repositories.google()
35
+ mavenRepoFromUrl("https://www.jitpack.io")
36
+ }
37
+ }
38
+ }
39
+
40
+ /**
41
+ * This method takes care of configuring the resolution strategy for both the app and all the 3rd
42
+ * party libraries which are auto-linked. Specifically it takes care of:
43
+ * - Forcing the react-android/hermes-android version to the one specified in the package.json
44
+ * - Substituting `react-native` with `react-android` and `hermes-engine` with `hermes-android`.
45
+ */
46
+ fun configureDependencies(project: Project, versionString: String) {
47
+ if (versionString.isBlank()) return
48
+ project.rootProject.allprojects { eachProject ->
49
+ eachProject.configurations.all { configuration ->
50
+ // Here we set a dependencySubstitution for both react-native and hermes-engine as those
51
+ // coordinates are voided due to https://github.com/facebook/react-native/issues/35210
52
+ // This allows users to import libraries that are still using
53
+ // implementation("com.facebook.react:react-native:+") and resolve the right dependency.
54
+ configuration.resolutionStrategy.dependencySubstitution {
55
+ it.substitute(it.module("com.facebook.react:react-native"))
56
+ .using(it.module("com.facebook.react:react-android:${versionString}"))
57
+ .because(
58
+ "The react-native artifact was deprecated in favor of react-android due to https://github.com/facebook/react-native/issues/35210.")
59
+ it.substitute(it.module("com.facebook.react:hermes-engine"))
60
+ .using(it.module("com.facebook.react:hermes-android:${versionString}"))
61
+ .because(
62
+ "The hermes-engine artifact was deprecated in favor of hermes-android due to https://github.com/facebook/react-native/issues/35210.")
63
+ }
64
+ configuration.resolutionStrategy.force(
65
+ "com.facebook.react:react-android:${versionString}",
66
+ "com.facebook.react:hermes-android:${versionString}",
67
+ )
68
+ }
69
+ }
70
+ }
71
+
72
+ fun readVersionString(propertiesFile: File): String {
73
+ val reactAndroidProperties = Properties()
74
+ propertiesFile.inputStream().use { reactAndroidProperties.load(it) }
75
+ val versionString = reactAndroidProperties["VERSION_NAME"] as? String ?: ""
76
+ // If on a nightly, we need to fetch the -SNAPSHOT artifact from Sonatype.
77
+ return if (versionString.startsWith("0.0.0")) {
78
+ "$versionString-SNAPSHOT"
79
+ } else {
80
+ versionString
81
+ }
82
+ }
83
+
84
+ fun Project.mavenRepoFromUrl(url: String): MavenArtifactRepository =
85
+ project.repositories.maven { it.url = URI.create(url) }
86
+
87
+ fun Project.mavenRepoFromURI(uri: URI): MavenArtifactRepository =
88
+ project.repositories.maven { it.url = uri }
89
+ }
@@ -0,0 +1,20 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.facebook.react.utils
9
+
10
+ import java.io.File
11
+
12
+ internal fun File.moveTo(destination: File) {
13
+ copyTo(destination, overwrite = true)
14
+ delete()
15
+ }
16
+
17
+ internal fun File.recreateDir() {
18
+ deleteRecursively()
19
+ mkdirs()
20
+ }
@@ -0,0 +1,21 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.facebook.react.utils
9
+
10
+ import com.facebook.react.model.ModelPackageJson
11
+ import com.google.gson.Gson
12
+ import java.io.File
13
+
14
+ object JsonUtils {
15
+ private val gsonConverter = Gson()
16
+
17
+ fun fromCodegenJson(input: File): ModelPackageJson? =
18
+ input.bufferedReader().use {
19
+ runCatching { gsonConverter.fromJson(it, ModelPackageJson::class.java) }.getOrNull()
20
+ }
21
+ }