Skip to content
Open
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
5 changes: 4 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ dist/
lib/
src/cblite-js
ios/
bable.config.js
bable.config.js
scripts/
plugin/
app.plugin.js
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,20 @@ This module currently uses the stable technologies defined by the legacy archite
This project is still a work in progress and is not officially supported by Couchbase. This is an open source project, to check the status of the project, navigate to the project's board on [GitHub - Project Status](https://github.com/orgs/Couchbase-Ecosystem/projects/2)

## Installation

The project has full documentation on how to set up and use the Native Module at [cbl-reactnative.dev](https://cbl-reactnative.dev) under the Start Here! -> Install section.

### Configure Edition

After installing the package, configure your edition:

```bash
# For Community Edition (default)
npx cbl-reactnative-configure CE

# For Enterprise Edition
npx cbl-reactnative-configure EE

## Contributing

See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
Expand All @@ -26,10 +38,11 @@ The project has full documentation of the API at [cbl-reactnative.dev](https://c

## 📢 Support Policy

We truly appreciate your interest in this project!
We truly appreciate your interest in this project!
This project is **community-maintained**, which means it's **not officially supported** by our support team.

If you need help, have found a bug, or want to contribute improvements, the best place to do that is right here — by [opening a GitHub issue](https://github.com/Couchbase-Ecosystem/cbl-reactnative/issues).
If you need help, have found a bug, or want to contribute improvements, the best place to do that is right here — by [opening a GitHub issue](https://github.com/Couchbase-Ecosystem/cbl-reactnative/issues).
Our support portal is unable to assist with requests related to this project, so we kindly ask that all inquiries stay within GitHub.

Your collaboration helps us all move forward together — thank you!
```

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The file ends with a dangling code block fence (```). This will likely cause markdown rendering issues and should be removed.

2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ dependencies {
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.json:json:20240303"
implementation "com.couchbase.lite:couchbase-lite-android-ee-ktx:3.2.1"
implementation "com.couchbase.lite:couchbase-lite-android-ktx:3.2.1"
implementation 'com.eclipsesource.j2v8:j2v8:6.2.1@aar'
}

5 changes: 4 additions & 1 deletion android/src/main/java/com/cblreactnative/DataAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import java.util.Date
import java.util.Locale
import java.util.TimeZone
import com.couchbase.lite.Collection as CBLCollection
import com.cblreactnative.CouchbaseReflectionHelper

object DataAdapter {

Expand Down Expand Up @@ -376,10 +377,12 @@ object DataAdapter {
target = endpoint,
continuous = continuous,
acceptParentDomainCookies = acceptParentDomainCookies,
acceptOnlySelfSignedServerCertificate = acceptSelfSignedCerts,
enableAutoPurge = autoPurgeEnabled,
type = replicatorType,
)

CouchbaseReflectionHelper.setAcceptOnlySelfSignedServerCertificate(configBuilder, acceptSelfSignedCerts)

val authenticatorMap = map.getMap("authenticator")
authenticatorMap?.let {
val authenticator = readableMapToAuthenticator(it)
Expand Down
1 change: 1 addition & 0 deletions app.plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./plugin/src/withCouchbaseLite');
5 changes: 5 additions & 0 deletions cbl-edition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"edition": "CE",
"version": "3.2.1",
"timestamp": "2024-01-01T00:00:00.000Z"
}
2 changes: 1 addition & 1 deletion cbl-reactnative.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/Couchbase-Ecosystem/cbl-reactnative", :tag => "#{s.version}" }

s.swift_version = '5.5'
s.dependency 'CouchbaseLite-Swift-Enterprise', '3.2.1'
s.dependency 'CouchbaseLite-Swift', '3.2.1'
s.source_files = "ios/**/*.{h,m,mm,swift}"

# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
Expand Down
4 changes: 3 additions & 1 deletion expo-example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ yarn-error.*
# The following patterns were generated by expo-cli

expo-env.d.ts
# @end expo-cli
# @end expo-cli
# Couchbase Lite configuration
cbl-edition.json
5 changes: 3 additions & 2 deletions expo-example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
"plugins": [
"expo-router",
"./cbl-reactnative-plugin.js",
"expo-font"
"expo-font",
"cbl-reactnative"
],
"experiments": {
"typedRoutes": true
}
}
}
}
5 changes: 4 additions & 1 deletion expo-example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ios/cbl-js-swift
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@
"type": "git",
"url": "git+https://github.com/Couchbase-Ecosystem/cbl-reactnative.git"
},
"bin": {
"cbl-reactnative-configure": "./scripts/configure-edition.js"
},
"scripts": {
"test": "jest",
"typecheck": "tsc --noEmit",
"lint": "eslint \"**/*.{js,ts,tsx}\"",
"clean": "del-cli android/build expo-example/android/build expo-example/android/app/build expo-example/ios/build lib",
"build": "bob build",
"release": "release-it"
"release": "release-it",
"configure:ce": "node scripts/configure-edition.js CE",
"configure:ee": "node scripts/configure-edition.js EE"
},
"main": "./lib/commonjs/index.js",
"source": "./src/index.tsx",
Expand All @@ -48,6 +53,10 @@
"android",
"ios",
"cpp",
"plugin",
"scripts",
"app.plugin.js",
"cbl-edition.json",
"*.podspec",
"!ios/build",
"!android/build",
Expand Down
119 changes: 119 additions & 0 deletions plugin/src/withCouchbaseLite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
const { withDangerousMod, withPlugins } = require('@expo/config-plugins');
const { withAppBuildGradle } = require('@expo/config-plugins');
const fs = require('fs');
const path = require('path');

const EDITIONS = {
CE: {
android: 'com.couchbase.lite:couchbase-lite-android-ktx',
ios: 'CouchbaseLite-Swift',
},
EE: {
android: 'com.couchbase.lite:couchbase-lite-android-ee-ktx',
ios: 'CouchbaseLite-Enterprise-Swift',
},
};

const VERSION = '3.2.1';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The Couchbase Lite version is hardcoded here as 3.2.1. This same version is also hardcoded in scripts/configure-edition.js (line 69). To improve maintainability and reduce the risk of inconsistencies when updating the dependency version, consider defining this version in a single, shared location.


function readEditionConfig(projectRoot) {
try {
const configPath = path.join(projectRoot, 'cbl-edition.json');
if (fs.existsSync(configPath)) {
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
return config.edition || 'CE';
}
} catch (error) {
console.log('No cbl-edition.json found, using default CE edition');
}
return 'CE';
}

const withCouchbaseLiteAndroid = (config, { edition }) => {
return withAppBuildGradle(config, (config) => {
const dependency = EDITIONS[edition].android;

config.modResults.contents = config.modResults.contents.replace(
/dependencies\s*{/,
`dependencies {
// Couchbase Lite Edition Override
configurations.all {
resolutionStrategy {
force "${dependency}:${VERSION}"
}
}
`
);

return config;
});
};

const withCouchbaseLiteIOS = (config, { edition }) => {
return withDangerousMod(config, [
'ios',
async (config) => {
const dependency = EDITIONS[edition].ios;
const podfilePath = path.join(
config.modRequest.platformProjectRoot,
'Podfile'
);

if (fs.existsSync(podfilePath)) {
let podfile = fs.readFileSync(podfilePath, 'utf8');

// Remove any existing Couchbase pod overrides
podfile = podfile.replace(
/\n\s*# Couchbase Lite Edition Override[\s\S]*?pod 'CouchbaseLite[^']*'[^\n]*\n/g,
''
);

// Add the correct pod
const podOverride = `\n # Couchbase Lite Edition Override\n pod '${dependency}', '${VERSION}', :modular_headers => true\n`;

// Add before use_react_native!
podfile = podfile.replace(/(use_react_native!)/, `${podOverride} $1`);

// Add EE source if needed
if (edition === 'EE') {
if (
!podfile.includes(
'https://github.com/couchbase/couchbase-lite-ios-ee.git'
)
) {
podfile = `source 'https://github.com/couchbase/couchbase-lite-ios-ee.git'\n${podfile}`;
}
}

fs.writeFileSync(podfilePath, podfile);
}

return config;
},
]);
};

function withCouchbaseLite(config, props = {}) {
// First try to read from props, then from config file
let edition = props.edition;

if (!edition) {
const projectRoot = config._internal?.projectRoot || process.cwd();
edition = readEditionConfig(projectRoot);
}

edition = edition?.toUpperCase() || 'CE';

if (!EDITIONS[edition]) {
throw new Error(
`Invalid Couchbase Lite edition: ${edition}. Use 'CE' or 'EE'.`
);
}

return withPlugins(config, [
[withCouchbaseLiteAndroid, { edition }],
[withCouchbaseLiteIOS, { edition }],
]);
}

module.exports = withCouchbaseLite;
Loading