Skip to content

Commit

Permalink
Merge pull request #9 from morrowdigital/updates-example-sdk47
Browse files Browse the repository at this point in the history
[wip]: Updates example to use expo SDK 47
  • Loading branch information
Foosballfan authored Feb 10, 2023
2 parents 49b9233 + 6c37bed commit ae2a2bb
Show file tree
Hide file tree
Showing 9 changed files with 5,688 additions and 7,387 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,33 @@ Config plugin to auto configure `@nozbe/watermelondb`

## Install

> Tested against Expo SDK 43
> Tested against Expo SDK 47
```
yarn add @morrowdigital/watermelondb-expo-plugin
```

> Please make sure you also install **[expo-build-properties](https://docs.expo.dev/versions/latest/sdk/build-properties/)**
After installing this npm package, add the [config plugin](https://docs.expo.io/guides/config-plugins/) to the [`plugins`](https://docs.expo.io/versions/latest/config/app/#plugins) array of your `app.json` or `app.config.js`. Then rebuild your app as described in the ["Adding custom native code"](https://docs.expo.io/workflow/customizing/) guide.


## Example

In your app.json `plugins` array:

```json
{
"plugins": ["@morrowdigital/watermelondb-expo-plugin"]
"plugins": ["@morrowdigital/watermelondb-expo-plugin",
[
"expo-build-properties",
{
"android": {
"kotlinVersion": "1.6.10"
}
}
]
]
}
```
31 changes: 4 additions & 27 deletions build/withWatermelon.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,14 @@ const fs = fs_1.default.promises;
/**
* Platform: Android
* */
function setAppBuildGradle(config) {
return (0, config_plugins_1.withAppBuildGradle)(config, (config) => {
config.modResults.contents = replace(config.modResults.contents,
// @ts-ignore
/dependencies\s{/, `dependencies {
\timplementation project(':watermelondb')`);
return config;
});
}
function setAppSettingBuildGradle(config) {
return (0, config_plugins_1.withSettingsGradle)(config, (config) => {
config.modResults.contents = config.modResults.contents.replace(`include ':app'`, `
include ':watermelondb'
project(':watermelondb').projectDir =new File(rootProject.projectDir, '../node_modules/@nozbe/watermelondb/native/android')
include ':app'
`);
return config;
});
}
function setAndroidMainApplication(config) {
return (0, config_plugins_1.withDangerousMod)(config, [
"android",
async (config) => {
var _a, _b;
const root = config.modRequest.platformProjectRoot;
const filePath = `${root}/app/src/main/java/${(_b = (_a = config === null || config === void 0 ? void 0 : config.android) === null || _a === void 0 ? void 0 : _a.package) === null || _b === void 0 ? void 0 : _b.replace(/\./g, "/")}/MainApplication.java`;
const filePath = `${root}/app/src/main/java/${config?.android?.package?.replace(/\./g, "/")}/MainApplication.java`;
const contents = await fs.readFile(filePath, "utf-8");
let updated = (0, insertLinesHelper_1.insertLinesHelper)("import com.nozbe.watermelondb.WatermelonDBPackage;", "import java.util.List;", contents);
updated = (0, insertLinesHelper_1.insertLinesHelper)(" packages.add(new WatermelonDBPackage());", " // Packages that cannot be autolinked yet can be added manually here, for example:", updated);
await fs.writeFile(filePath, updated);
return config;
},
Expand Down Expand Up @@ -148,14 +126,13 @@ function replace(contents, match, replace) {
}
// @ts-ignore
exports.default = (config, options) => {
var _a;
config = setAppSettingBuildGradle(config);
config = setAppBuildGradle(config);
// config = setAppSettingBuildGradle(config);
// config = setAppBuildGradle(config);
config = setAndroidMainApplication(config);
config = setAppDelegate(config);
config = setWmelonBridgingHeader(config);
config = withCocoaPods(config);
if ((_a = options === null || options === void 0 ? void 0 : options.excludeSimulatorArchitectures) !== null && _a !== void 0 ? _a : true) {
if (options?.excludeSimulatorArchitectures ?? true) {
config = withExcludedSimulatorArchitectures(config);
}
return config;
Expand Down
16 changes: 11 additions & 5 deletions example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"assetBundlePatterns": ["**/*"],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "com.wmlDB.app"
Expand All @@ -31,7 +29,15 @@
"favicon": "./assets/favicon.png"
},
"plugins": [
"@morrowdigital/watermelondb-expo-plugin"
"../app.plugin",
[
"expo-build-properties",
{
"android": {
"kotlinVersion": "1.6.10"
}
}
]
]
}
}
}
Empty file added example/eas.json
Empty file.
37 changes: 20 additions & 17 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,29 @@
},
"dependencies": {
"@morrowdigital/watermelondb-expo-plugin": "^1.0.0-beta",
"@nozbe/watermelondb": "^0.24.0",
"expo": "~43.0.2",
"expo-splash-screen": "~0.13.5",
"expo-status-bar": "~1.1.0",
"expo-updates": "~0.10.13",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.3",
"react-native-gesture-handler": "~1.10.2",
"react-native-reanimated": "~2.2.0",
"react-native-safe-area-context": "3.3.2",
"react-native-screens": "~3.8.0",
"react-native-web": "0.17.1",
"@nozbe/watermelondb": "^0.25.5",
"expo": "~47.0.12",
"expo-build-properties": "~0.4.1",
"expo-splash-screen": "~0.17.5",
"expo-status-bar": "~1.4.2",
"expo-updates": "~0.15.6",
"react": "18.1.0",
"react-dom": "18.1.0",
"react-native": "0.70.5",
"react-native-gesture-handler": "~2.8.0",
"react-native-reanimated": "~2.12.0",
"react-native-safe-area-context": "4.4.1",
"react-native-screens": "~3.18.0",
"react-native-web": "~0.18.7",
"resolve-from": "^5.0.0"
},
"devDependencies": {
"@babel/core": "^7.12.9",
"@types/react": "~17.0.21",
"@types/react-native": "~0.64.12",
"typescript": "~4.3.5"
"@babel/core": "^7.19.3",
"@types/react": "~18.0.24",
"@types/react-native": "~0.70.6",
"jest-expo": "^47.0.0",
"react-test-renderer": "17.0.1",
"typescript": "^4.6.3"
},
"private": true,
"name": "wmlDB",
Expand Down
Loading

0 comments on commit ae2a2bb

Please sign in to comment.