|
1 |
| -[!CAUTION] |
2 |
| -This document was pre-generated and isn't up-to-date - but will be updated shortly. What I'm saying is following these instructions will not help you build the example app or project. |
3 |
| - |
4 | 1 | # Contributing
|
5 | 2 |
|
6 | 3 | Contributions are always welcome, no matter how large or small!
|
7 | 4 |
|
8 | 5 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. Before contributing, please read the [code of conduct](./CODE_OF_CONDUCT.md).
|
9 | 6 |
|
10 |
| -## Development workflow |
| 7 | +This guide provides instructions for contributing to this React Native - Native Module. |
11 | 8 |
|
12 |
| -This project is a monorepo managed using [Yarn workspaces](https://yarnpkg.com/features/workspaces). It contains the following packages: |
13 | 9 |
|
14 |
| -- The library package in the root directory. |
15 |
| -- An example app in the `expo-example/` directory. |
| 10 | +## Development Requirements |
| 11 | +- Javascript |
| 12 | + - [Node 20](https://formulae.brew.sh/formula/node@20) |
| 13 | + - LTS version is highly recommended |
| 14 | +- React Native |
| 15 | + - [React Native - Getting Started](https://reactnative.dev/docs/environment-setup) |
| 16 | + - You should note that while the library is a React Native - Native Module, React recommends all apps use Expo or another framework. The provided example app is an Expo based app, so you will need to have knowledge on React, React Native, and Expo |
| 17 | + - [Understanding on React Native - Native Module Development](https://reactnative.dev/docs/native-modules-intro) |
| 18 | + - [Expo Setup](https://docs.expo.dev/get-started/set-up-your-environment/?platform=ios&device=physical&mode=development-build&buildEnv=local) |
| 19 | + - The example app provided to test the Native Module is an expo based app, so you have to have your environment setup for expo |
| 20 | + - For expo setup on the link provided above, you must select `Development build` and turn off `Build with Expo Appplication Services (EAS)` for proper instructions |
| 21 | + - You should have a clear understanding of expo's [dev client environment](https://docs.expo.dev/guides/local-app-development/#local-builds-with-expo-dev-client). |
| 22 | +- IDEs |
| 23 | + - [Visual Studio Code](https://code.visualstudio.com/download) |
| 24 | + - [IntelliJ IDEA](https://www.jetbrains.com/idea/download/) |
| 25 | +- iOS Development |
| 26 | + - A modern Mac |
| 27 | + - [XCode 15](https://developer.apple.com/xcode/) or higher installed and working |
| 28 | + - [XCode Command Line Tools](https://developer.apple.com/download/more/) installed |
| 29 | + - [Simulators](https://developer.apple.com/documentation/safari-developer-tools/installing-xcode-and-simulators) downloaded and working |
| 30 | + - [Homebrew](https://brew.sh/) |
| 31 | + - [Cocopods](https://formulae.brew.sh/formula/cocoapods) |
16 | 32 |
|
17 |
| -To get started with the project, run `yarn` in the root directory to install the required dependencies for each package: |
| 33 | + - A valid Apple Developer account and certificates installed and working |
| 34 | +- Android Development |
| 35 | + - [Android Studio](https://developer.android.com/studio?gad_source=1&gclid=CjwKCAjwzN-vBhAkEiwAYiO7oALYfxbMYW_zkuYoacS9TX16aItdvLYe6GB7_j1QwvXBjFDRkawfUBoComcQAvD_BwE&gclsrc=aw.ds) installed and working |
| 36 | + - Android SDK 34 >= installed and working (with command line tools) |
| 37 | + - Java SDK v17 installed and working with Android Studio |
| 38 | + - An Android Emulator downloaded and working |
18 | 39 |
|
19 |
| -```sh |
20 |
| -yarn |
21 |
| -``` |
| 40 | +## Project Structure |
22 | 41 |
|
23 |
| -> Since the project relies on Yarn workspaces, you cannot use [`npm`](https://github.com/npm/cli) for development. |
| 42 | +The root directory of the repository contains the following files and directories: |
| 43 | +- `android`: This is the Native Module code for the Android platform. It is written in Kotlin. The cbl-js-kotlin folder is a Git submodule and has shared code between this project and other projects like cbl-ionic. |
| 44 | +- `expo-example`: This is the example application for testing changes to the Native Module. It is an Expo based app, and you can look at the `package.json` file to see the various commands available. Note: When the Native Module version is updated, the example app version should match. |
| 45 | +- `ios`: This is the Native Module code for the iOS platform. It is written in Objective-C and Swift. The `cbl-js-swift` folder is a Git submodule and has shared code between this project and other projects like cbl-ionic. |
| 46 | +- `src`: This is the Native Module source code in Typescript for the project. The `cblite-js` folder is a Git submodule and defines the entire API surface of the cblite-js library. This library is shared between all similar projects like cbl-ionic. `CblReactNativeEngine` is an implementation of the `cblite-js` library that is defined in the `ICoreEngine` interface in `cblite-js`. `CblReactNativeEngine` is the bridge between the Native Module and the `cblite-js` library. |
24 | 47 |
|
25 |
| -The [example app](/expo-example/) demonstrates usage of the library. You need to run it to test any changes you make. |
| 48 | +## Development Workflow |
26 | 49 |
|
27 |
| -It is configured to use the local version of the library, so any changes you make to the library's source code will be reflected in the example app. Changes to the library's JavaScript code will be reflected in the example app without a rebuild, but native code changes will require a rebuild of the example app. |
| 50 | +It's recommended that new APIs be defined in Typescript first to flush out the requirements for sending the data over the bridge, and then implemented in the Native Module. The Native Module should be tested in the example app to ensure that it works as expected. |
28 | 51 |
|
29 |
| -If you want to use Android Studio or XCode to edit the native code, you can open the `example/android` or `example/ios` directories respectively in those editors. To edit the Objective-C or Swift files, open `example/ios/CblReactnativeExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > cbl-reactnative`. |
| 52 | +Any breaking changes to the cblite-js library will require changes in other libraries like cbl-ionic, so it's important to remember that PRs that make changes to this library are less like to be approved without justification. |
30 | 53 |
|
31 |
| -To edit the Java or Kotlin files, open `example/android` in Android studio and find the source files at `cbl-reactnative` under `Android`. |
| 54 | +If you want to use Android Studio or XCode to edit the native code, you can open the `expo-example/android` or `expo-example/ios` directories respectively in those editors. To edit the Objective-C or Swift files, open `expo-example/ios/expoexample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > cbl-reactnative`. |
32 | 55 |
|
33 |
| -You can use various commands from the root directory to work with the project. |
| 56 | +To edit the Java or Kotlin files, open `expo-example/android` in Android studio and find the source files at `cbl-reactnative` under `Android`. |
34 | 57 |
|
35 |
| -To start the packager: |
36 |
| - |
37 |
| -```sh |
38 |
| -yarn example start |
39 |
| -``` |
| 58 | +**NOTE**: Until you do an initial build both directories might not have the files required to build the project. |
40 | 59 |
|
41 |
| -To run the example app on Android: |
| 60 | +## How to Build the Project |
42 | 61 |
|
| 62 | +Install the required packages |
43 | 63 | ```sh
|
44 |
| -yarn example android |
| 64 | +npm install |
45 | 65 | ```
|
46 | 66 |
|
47 |
| -To run the example app on iOS: |
48 |
| - |
| 67 | +To build the example app change to the expo-example folder: |
49 | 68 | ```sh
|
50 |
| -yarn example ios |
| 69 | +cd .. expo-example |
51 | 70 | ```
|
52 | 71 |
|
53 |
| -Make sure your code passes TypeScript and ESLint. Run the following to verify: |
54 |
| - |
| 72 | +Android: |
55 | 73 | ```sh
|
56 |
| -yarn typecheck |
57 |
| -yarn lint |
| 74 | +npm run android |
58 | 75 | ```
|
59 | 76 |
|
60 |
| -To fix formatting errors, run the following: |
| 77 | +iOS: |
61 | 78 |
|
62 | 79 | ```sh
|
63 |
| -yarn lint --fix |
| 80 | +npm run ios |
64 | 81 | ```
|
| 82 | +Expo cache can sometimes break things. Note when you make changes to Native Code you MUST do a new build to see the changes reflected as watchman doesn't watch Native Code changes, only changes to the local application. So ANY Native Module code changes to the iOS, Android, or typescript code will require a new build. |
65 | 83 |
|
66 |
| -Remember to add tests for your change if possible. Run the unit tests by: |
67 |
| - |
| 84 | +You can manually clear the cache by running: |
68 | 85 | ```sh
|
69 |
| -yarn test |
| 86 | +npm run prebuild:clean |
70 | 87 | ```
|
71 | 88 |
|
72 | 89 | ### Commit message convention
|
@@ -97,20 +114,28 @@ We use [release-it](https://github.com/release-it/release-it) to make it easier
|
97 | 114 | To publish new versions, run the following:
|
98 | 115 |
|
99 | 116 | ```sh
|
100 |
| -yarn release |
| 117 | +npm release |
101 | 118 | ```
|
102 | 119 |
|
103 | 120 | ### Scripts
|
104 | 121 |
|
105 |
| -The `package.json` file contains various scripts for common tasks: |
106 |
| - |
107 |
| -- `yarn`: setup project by installing dependencies. |
108 |
| -- `yarn typecheck`: type-check files with TypeScript. |
109 |
| -- `yarn lint`: lint files with ESLint. |
110 |
| -- `yarn test`: run unit tests with Jest. |
111 |
| -- `yarn example start`: start the Metro server for the example app. |
112 |
| -- `yarn example android`: run the example app on Android. |
113 |
| -- `yarn example ios`: run the example app on iOS. |
| 122 | +#### Native Module |
| 123 | +The root directory `package.json` file contains various scripts for common tasks: |
| 124 | + |
| 125 | +- `npm`: setup project by installing dependencies. |
| 126 | +- `npm typecheck`: type-check files with TypeScript. |
| 127 | +- `npm lint`: lint files with ESLint. |
| 128 | +- `npm clean`: clean the lib folder and the example app native ios and android build folders. |
| 129 | +- `npm build`: run a build using the React Native builder (bob) |
| 130 | +- |
| 131 | +#### Expo example app |
| 132 | +The `expo-example` directory `package.json` file contains various scripts for common tasks: |
| 133 | + |
| 134 | +- `prebuild`: setup project by installing dependencies along with the native dependencies. |
| 135 | +- `prebuild:clean`: cleans out all directories and cache first, then runs a prebuild |
| 136 | +- `start`: starts the expo server and provides the menu for running the app on various devices. |
| 137 | +- `android`: starts the expo server and runs the app on an android emulator or device. |
| 138 | +- `ios`: starts the expo server and runs the app on an iOS simulator or device. |
114 | 139 |
|
115 | 140 | ### Sending a pull request
|
116 | 141 |
|
|
0 commit comments