forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RNGP - Autolinking - Add model classes for parsing the
config
output
Summary: This diff is part of RFC0759 react-native-community/discussions-and-proposals#759 Here I'm creating data classes that will allow us to parse the `config` JSON output. Code is pretty straightforward and follows the structure as the `config` command output. Changelog: [Internal] [Changed] - RNGP - Autolinking - Add model classes for parsing the `config` output Reviewed By: cipolleschi, blakef Differential Revision: D55475595 fbshipit-source-id: 3457c008ff0c5bce2b47fd637c7b10a5e7427c01
- Loading branch information
Showing
9 changed files
with
330 additions
and
4 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
...dle-plugin/src/main/kotlin/com/facebook/react/model/ModelAutolinkingAndroidProjectJson.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.model | ||
|
||
data class ModelAutolinkingAndroidProjectJson( | ||
val sourceDir: String, | ||
val appName: String, | ||
val packageName: String, | ||
val applicationId: String, | ||
val mainActivity: String, | ||
val watchModeCommandParams: List<String>?, | ||
val dependencyConfiguration: String? | ||
) |
14 changes: 14 additions & 0 deletions
14
...tive-gradle-plugin/src/main/kotlin/com/facebook/react/model/ModelAutolinkingConfigJson.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.model | ||
|
||
data class ModelAutolinkingConfigJson( | ||
val reactNativeVersion: String, | ||
val dependencies: Map<String, ModelAutolinkingDependenciesJson>?, | ||
val project: ModelAutolinkingProjectJson?, | ||
) |
18 changes: 18 additions & 0 deletions
18
...radle-plugin/src/main/kotlin/com/facebook/react/model/ModelAutolinkingDependenciesJson.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.model | ||
|
||
data class ModelAutolinkingDependenciesJson( | ||
val root: String, | ||
val name: String, | ||
val platforms: ModelAutolinkingDependenciesPlatformJson? | ||
) { | ||
|
||
val nameCleansed: String | ||
get() = name.replace(Regex("[~*!'()]+"), "_").replace(Regex("^@([\\w-.]+)/"), "$1_") | ||
} |
22 changes: 22 additions & 0 deletions
22
...c/main/kotlin/com/facebook/react/model/ModelAutolinkingDependenciesPlatformAndroidJson.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.model | ||
|
||
data class ModelAutolinkingDependenciesPlatformAndroidJson( | ||
val sourceDir: String, | ||
val packageImportPath: String, | ||
val packageInstance: String, | ||
val buildTypes: List<String>, | ||
val libraryName: String, | ||
val componentDescriptors: List<String>, | ||
val cmakeListsPath: String, | ||
val cxxModuleCMakeListsModuleName: String?, | ||
val cxxModuleCMakeListsPath: String?, | ||
val cxxModuleHeaderName: String?, | ||
val dependencyConfiguration: String? | ||
) |
12 changes: 12 additions & 0 deletions
12
...ugin/src/main/kotlin/com/facebook/react/model/ModelAutolinkingDependenciesPlatformJson.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.model | ||
|
||
data class ModelAutolinkingDependenciesPlatformJson( | ||
val android: ModelAutolinkingDependenciesPlatformAndroidJson? | ||
) |
10 changes: 10 additions & 0 deletions
10
...ive-gradle-plugin/src/main/kotlin/com/facebook/react/model/ModelAutolinkingProjectJson.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.model | ||
|
||
data class ModelAutolinkingProjectJson(val android: ModelAutolinkingAndroidProjectJson?) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...e-plugin/src/test/kotlin/com/facebook/react/model/ModelAutolinkingDependenciesJsonTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.model | ||
|
||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
class ModelAutolinkingDependenciesJsonTest { | ||
|
||
@Test | ||
fun nameCleansed_withoutScope() { | ||
assertEquals("name", ModelAutolinkingDependenciesJson("", "name", null).nameCleansed) | ||
assertEquals( | ||
"react_native", ModelAutolinkingDependenciesJson("", "react~native", null).nameCleansed) | ||
assertEquals( | ||
"react_native", ModelAutolinkingDependenciesJson("", "react*native", null).nameCleansed) | ||
assertEquals( | ||
"react_native", ModelAutolinkingDependenciesJson("", "react!native", null).nameCleansed) | ||
assertEquals( | ||
"react_native", ModelAutolinkingDependenciesJson("", "react'native", null).nameCleansed) | ||
assertEquals( | ||
"react_native", ModelAutolinkingDependenciesJson("", "react(native", null).nameCleansed) | ||
assertEquals( | ||
"react_native", ModelAutolinkingDependenciesJson("", "react)native", null).nameCleansed) | ||
assertEquals( | ||
"react_native", | ||
ModelAutolinkingDependenciesJson("", "react~*!'()native", null).nameCleansed) | ||
} | ||
|
||
@Test | ||
fun nameCleansed_withScope() { | ||
assertEquals( | ||
"react-native_package", | ||
ModelAutolinkingDependenciesJson("", "@react-native/package", null).nameCleansed) | ||
assertEquals( | ||
"this_is_a_more_complicated_example_of_weird_packages", | ||
ModelAutolinkingDependenciesJson( | ||
"", "@this*is~a(more)complicated/example!of~weird)packages", null) | ||
.nameCleansed) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters