@rock-js/plugin-brownfield-android 0.8.13

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.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # @rock-js/plugin-brownfield-android
2
+
3
+ Android brownfield integration plugin for Rock (Rock). This package is part of the Rock ecosystem and provides tools for integrating React Native into existing Android applications.
4
+
5
+ ## Documentation
6
+
7
+ For detailed documentation about Rock and its tools, visit [Rock Documentation](https://rockjs.dev)
@@ -0,0 +1 @@
1
+ export * from './lib/pluginBrownfieldAndroid.js';
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './lib/pluginBrownfieldAndroid.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { AndroidProjectConfig } from '@react-native-community/cli-types';
2
+ import type { PluginApi, PluginOutput } from '@rock-js/config';
3
+ export declare const pluginBrownfieldAndroid: (pluginConfig?: AndroidProjectConfig) => (api: PluginApi) => PluginOutput;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pluginBrownfieldAndroid.d.ts","sourceRoot":"","sources":["../../../src/lib/pluginBrownfieldAndroid.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAoB5D,eAAO,MAAM,uBAAuB,kBAClB,oBAAoB,WAC9B,SAAS,KAAG,YA4CjB,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { projectConfig } from '@react-native-community/cli-config-android';
2
+ import { packageAar, packageAarOptions, publishLocalAar, publishLocalAarOptions, } from '@rock-js/platform-android';
3
+ import { intro, RockError } from '@rock-js/tools';
4
+ const getAarConfig = (args, androidConfig) => {
5
+ const config = {
6
+ sourceDir: androidConfig.sourceDir,
7
+ moduleName: args.moduleName ?? '',
8
+ };
9
+ return config;
10
+ };
11
+ export const pluginBrownfieldAndroid = (pluginConfig) => (api) => {
12
+ const projectRoot = api.getProjectRoot();
13
+ api.registerCommand({
14
+ name: 'package:aar',
15
+ description: 'Produces an AAR file suitable for including React Native app in native projects.',
16
+ action: async (args) => {
17
+ intro('Creating an AAR file');
18
+ const androidConfig = projectConfig(projectRoot, pluginConfig);
19
+ if (androidConfig) {
20
+ const config = getAarConfig(args, androidConfig);
21
+ await packageAar(config, args);
22
+ }
23
+ else {
24
+ throw new RockError('Android project not found.');
25
+ }
26
+ },
27
+ options: packageAarOptions,
28
+ });
29
+ api.registerCommand({
30
+ name: 'publish-local:aar',
31
+ description: 'Publishes a AAR to local maven repo',
32
+ action: async (args) => {
33
+ intro('Publishing AAR');
34
+ const androidConfig = projectConfig(projectRoot, pluginConfig);
35
+ if (androidConfig) {
36
+ const config = getAarConfig(args, androidConfig);
37
+ await publishLocalAar(config);
38
+ }
39
+ else {
40
+ throw new RockError('Android project not found.');
41
+ }
42
+ },
43
+ options: publishLocalAarOptions,
44
+ });
45
+ return {
46
+ name: 'plugin-brownfield-android',
47
+ description: 'Rock plugin for brownfield Android.',
48
+ };
49
+ };
50
+ //# sourceMappingURL=pluginBrownfieldAndroid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pluginBrownfieldAndroid.js","sourceRoot":"","sources":["../../../src/lib/pluginBrownfieldAndroid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAG3E,OAAO,EACL,UAAU,EAEV,iBAAiB,EACjB,eAAe,EACf,sBAAsB,GACvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,SAAS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AAC,IAAI,EAAE,aAAa,CAAC,CAAC;gBACjD,MAAM,eAAe,CAAC,MAAM,CAAC,CAAC;YAChC,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,SAAS,CAAC,4BAA4B,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;QACD,OAAO,EAAE,sBAAsB;KAChC,CAAC,CAAC;IAEH,OAAO;QACL,IAAI,EAAE,2BAA2B;QACjC,WAAW,EAAE,qCAAqC;KACnD,CAAC;AACJ,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@rock-js/plugin-brownfield-android",
3
+ "version": "0.8.13",
4
+ "type": "module",
5
+ "types": "./dist/src/index.d.ts",
6
+ "exports": {
7
+ "types": "./dist/src/index.d.ts",
8
+ "default": "./dist/src/index.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "src",
13
+ "template"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsc -p tsconfig.lib.json",
17
+ "dev": "tsc -p tsconfig.lib.json --watch",
18
+ "publish:npm": "npm publish --access public",
19
+ "publish:verdaccio": "npm publish --registry http://localhost:4873 --userconfig ../../.npmrc"
20
+ },
21
+ "dependencies": {
22
+ "@rock-js/tools": "^0.8.13",
23
+ "@rock-js/platform-android": "^0.8.13",
24
+ "@react-native-community/cli-config-android": "^19.1.0",
25
+ "tslib": "^2.3.0"
26
+ },
27
+ "devDependencies": {
28
+ "@rock-js/config": "^0.8.13",
29
+ "@react-native-community/cli-types": "^19.1.0"
30
+ },
31
+ "publishConfig": {
32
+ "access": "restricted"
33
+ }
34
+ }
@@ -0,0 +1,19 @@
1
+ import { expect, test } from 'vitest';
2
+ import { pluginBrownfieldAndroid } from '../lib/pluginBrownfieldAndroid.js';
3
+
4
+ const pluginApi = {
5
+ registerCommand: vi.fn(),
6
+ getProjectRoot: vi.fn(),
7
+ getReactNativePath: vi.fn(),
8
+ getReactNativeVersion: vi.fn(),
9
+ getPlatforms: vi.fn(),
10
+ };
11
+
12
+ test('plugin is called with correct arguments and returns its name and description', () => {
13
+ const plugin = pluginBrownfieldAndroid()(pluginApi);
14
+
15
+ expect(plugin).toMatchObject({
16
+ name: 'plugin-brownfield-android',
17
+ description: 'Rock plugin for brownfield Android.',
18
+ });
19
+ });
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './lib/pluginBrownfieldAndroid.js';
@@ -0,0 +1,69 @@
1
+ import { projectConfig } from '@react-native-community/cli-config-android';
2
+ import type { AndroidProjectConfig } from '@react-native-community/cli-types';
3
+ import type { PluginApi, PluginOutput } from '@rock-js/config';
4
+ import {
5
+ packageAar,
6
+ type PackageAarFlags,
7
+ packageAarOptions,
8
+ publishLocalAar,
9
+ publishLocalAarOptions,
10
+ } from '@rock-js/platform-android';
11
+ import { intro, RockError } from '@rock-js/tools';
12
+
13
+ const getAarConfig = (
14
+ args: PackageAarFlags,
15
+ androidConfig: AndroidProjectConfig,
16
+ ) => {
17
+ const config = {
18
+ sourceDir: androidConfig.sourceDir,
19
+ moduleName: args.moduleName ?? '',
20
+ };
21
+ return config;
22
+ };
23
+ export const pluginBrownfieldAndroid =
24
+ (pluginConfig?: AndroidProjectConfig) =>
25
+ (api: PluginApi): PluginOutput => {
26
+ const projectRoot = api.getProjectRoot();
27
+
28
+ api.registerCommand({
29
+ name: 'package:aar',
30
+ description:
31
+ 'Produces an AAR file suitable for including React Native app in native projects.',
32
+ action: async (args: PackageAarFlags) => {
33
+ intro('Creating an AAR file');
34
+
35
+ const androidConfig = projectConfig(projectRoot, pluginConfig);
36
+
37
+ if (androidConfig) {
38
+ const config = getAarConfig(args, androidConfig);
39
+ await packageAar(config, args);
40
+ } else {
41
+ throw new RockError('Android project not found.');
42
+ }
43
+ },
44
+ options: packageAarOptions,
45
+ });
46
+
47
+ api.registerCommand({
48
+ name: 'publish-local:aar',
49
+ description: 'Publishes a AAR to local maven repo',
50
+ action: async (args: PackageAarFlags) => {
51
+ intro('Publishing AAR');
52
+
53
+ const androidConfig = projectConfig(projectRoot, pluginConfig);
54
+
55
+ if (androidConfig) {
56
+ const config = getAarConfig(args, androidConfig);
57
+ await publishLocalAar(config);
58
+ } else {
59
+ throw new RockError('Android project not found.');
60
+ }
61
+ },
62
+ options: publishLocalAarOptions,
63
+ });
64
+
65
+ return {
66
+ name: 'plugin-brownfield-android',
67
+ description: 'Rock plugin for brownfield Android.',
68
+ };
69
+ };
@@ -0,0 +1,22 @@
1
+ buildscript {
2
+ ext {
3
+ buildToolsVersion = "35.0.0"
4
+ minSdkVersion = 24
5
+ compileSdkVersion = 35
6
+ targetSdkVersion = 35
7
+ ndkVersion = "27.1.12297006"
8
+ kotlinVersion = "2.1.20"
9
+ }
10
+ repositories {
11
+ google()
12
+ mavenCentral()
13
+ }
14
+ dependencies {
15
+ classpath("com.android.tools.build:gradle")
16
+ classpath("com.facebook.react:react-native-gradle-plugin")
17
+ classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
18
+ classpath("com.callstack.react:brownfield-gradle-plugin:0.4.0")
19
+ }
20
+ }
21
+
22
+ apply plugin: "com.facebook.react.rootproject"
@@ -0,0 +1,96 @@
1
+ import groovy.json.JsonOutput
2
+ import groovy.json.JsonSlurper
3
+
4
+ plugins {
5
+ id("com.android.library")
6
+ id("org.jetbrains.kotlin.android")
7
+ id("com.callstack.react.brownfield")
8
+ `maven-publish`
9
+ id("com.facebook.react")
10
+ }
11
+
12
+ react {
13
+ autolinkLibrariesWithApp()
14
+ }
15
+
16
+ repositories {
17
+ mavenCentral()
18
+ }
19
+
20
+ android {
21
+ namespace = "com.helloworldreact"
22
+ compileSdk = 34
23
+
24
+ defaultConfig {
25
+ minSdk = 24
26
+
27
+ buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", properties["newArchEnabled"].toString())
28
+ buildConfigField("boolean", "IS_HERMES_ENABLED", properties["hermesEnabled"].toString())
29
+ }
30
+
31
+ publishing {
32
+ multipleVariants {
33
+ allVariants()
34
+ }
35
+ }
36
+ }
37
+
38
+ publishing {
39
+ publications {
40
+ create<MavenPublication>("mavenAar") {
41
+ groupId = "com.helloworldreact"
42
+ artifactId = "helloworld"
43
+ version = "0.0.1-local"
44
+ afterEvaluate {
45
+ from(components.getByName("default"))
46
+ }
47
+
48
+ pom {
49
+ withXml {
50
+ /**
51
+ * As a result of `from(components.getByName("default")` all of the project
52
+ * dependencies are added to `pom.xml` file. We do not need the react-native
53
+ * third party dependencies to be a part of it as we embed those dependencies.
54
+ */
55
+ val dependenciesNode = (asNode().get("dependencies") as groovy.util.NodeList).first() as groovy.util.Node
56
+ dependenciesNode.children()
57
+ .filterIsInstance<groovy.util.Node>()
58
+ .filter { (it.get("groupId") as groovy.util.NodeList).text() == rootProject.name }
59
+ .forEach { dependenciesNode.remove(it) }
60
+ }
61
+ }
62
+ }
63
+ }
64
+
65
+ repositories {
66
+ mavenLocal() // Publishes to the local Maven repository (~/.m2/repository)
67
+ }
68
+ }
69
+
70
+ dependencies {
71
+ api("com.facebook.react:react-android:0.80.1")
72
+ api("com.facebook.react:hermes-android:0.80.1")
73
+ }
74
+
75
+ val moduleBuildDir: Directory = layout.buildDirectory.get()
76
+
77
+ /**
78
+ * As a result of `from(components.getByName("default")` all of the project
79
+ * dependencies are added to `module.json` file. We do not need the react-native
80
+ * third party dependencies to be a part of it as we embed those dependencies.
81
+ */
82
+ tasks.register("removeDependenciesFromModuleFile") {
83
+ doLast {
84
+ file("$moduleBuildDir/publications/mavenAar/module.json").run {
85
+ val json = inputStream().use { JsonSlurper().parse(it) as Map<String, Any> }
86
+ (json["variants"] as? List<MutableMap<String, Any>>)?.forEach { variant ->
87
+ (variant["dependencies"] as? MutableList<Map<String, Any>>)?.removeAll { it["group"] == rootProject.name }
88
+ }
89
+ writer().use { it.write(JsonOutput.prettyPrint(JsonOutput.toJson(json))) }
90
+ }
91
+ }
92
+ }
93
+
94
+ tasks.named("generateMetadataFileForMavenAarPublication") {
95
+ finalizedBy("removeDependenciesFromModuleFile")
96
+ }
@@ -0,0 +1,16 @@
1
+ package com.helloworldreact
2
+
3
+ import android.app.Application
4
+ import com.callstack.reactnativebrownfield.OnJSBundleLoaded
5
+ import com.callstack.reactnativebrownfield.ReactNativeBrownfield
6
+ import com.facebook.react.PackageList
7
+ import com.facebook.react.ReactNativeApplicationEntryPoint.loadReactNative
8
+
9
+ object ReactNativeHostManager {
10
+ fun initialize(application: Application, onJSBundleLoaded: OnJSBundleLoaded? = null) {
11
+ loadReactNative(application)
12
+
13
+ val packageList = PackageList(application).packages
14
+ ReactNativeBrownfield.initialize(application, packageList, onJSBundleLoaded)
15
+ }
16
+ }
@@ -0,0 +1,7 @@
1
+ pluginManagement { includeBuild("../node_modules/@react-native/gradle-plugin") }
2
+ plugins { id("com.facebook.react.settings") }
3
+ extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand(['npx', 'rock', 'config', '-p', 'android']) }
4
+ rootProject.name = 'HelloWorld'
5
+ include ':app'
6
+ includeBuild('../node_modules/@react-native/gradle-plugin')
7
+ include(":helloworldreact")
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "rock-plugin-brownfield-android-template",
3
+ "scripts": {
4
+ "package:aar": "rock package:aar --variant Release --module-name helloworldreact",
5
+ "publish-local:aar": "pnpm package:aar && rock publish-local:aar --module-name helloworldreact"
6
+ },
7
+ "dependencies": {
8
+ "@callstack/react-native-brownfield": "^1.2.0"
9
+ },
10
+ "devDependencies": {
11
+ "@rock-js/plugin-brownfield-android": "^0.8.13"
12
+ }
13
+ }