Skip to content

Commit

Permalink
Monorepo (#60)
Browse files Browse the repository at this point in the history
* monorepo draft

* Add @noble/hashes/utils as a dep in nr-app.

* configure pnpm node-linker

* add android and ios to gitignore so we stay in managed workflow

* remove production config because we're not using it

* don't add build files to repo

* ignore android app bundles

* add google maps api key

* add api keys

* ios build config answer about encryption use

* use default provider in expo go bc google is not supported

* only use google maps on android

* ignore ios builds

* update lock file

* remove unused google config

* remove superfluous comma

* readme and config

* update readme

* change readme

* update READMEs

---------

Co-authored-by: Callum Macdonald <[email protected]>
  • Loading branch information
shuesken and chmac authored Feb 11, 2025
1 parent 070e9b7 commit 4a5c35b
Show file tree
Hide file tree
Showing 69 changed files with 14,155 additions and 141 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@jsr:registry=https://npm.jsr.io
node-linker=hoisted
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ There are 3 parts to this code.
- `nr-common` - A module that is shared between the rest of the projects
- `nr-app` - An expo app
- `nr-server` - A deno application that is hosted by Trustroots
- `nr-push` - A Go application that handles push notifications for the app.

> [!IMPORTANT]
> Before starting development of either `nr-app` or `nr-server`, first setup the `nr-common` code as per `nr-common/README.md`.
Please refer to the READMEs in the respective subfolders for working on them.

## Roadmap

Expand Down
5 changes: 5 additions & 0 deletions nr-app/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
node_modules/
.expo/
android/
ios/
dist/
npm-debug.*
*.jks
Expand All @@ -9,6 +11,9 @@ npm-debug.*
*.mobileprovision
*.orig.*
web-build/
*.apk
*.aab
*.ipa

# macOS
.DS_Store
Expand Down
61 changes: 7 additions & 54 deletions nr-app/README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,12 @@
# Welcome to your Expo app 👋
# Nostroots mobile app.

This is an [Expo](https://expo.dev) project created with [`create-expo-app`](https://www.npmjs.com/package/create-expo-app).

## Get started
## Getting started
First, run `pnpm i`.

1. Install watchman (or equivalent on *nix)
The fastest way to get started is using Expo go:
In `nr-app`, run `pnpm run start` and choose Expo Go. You can try starting an emulator or simulator from here if you have it installed. Alternatively, install the Expo Go app on your mobile device and scan the QR code.

```bash
brew install watchman
```
If you want to use a development build, you can switch to that by pressing `s`. Open an emulator or simulator with this build using the commands available.

2. Use nvm to set the correct node version. Make sure you have the appropriate version of node installed (`nvm i`).

```bash
nvm use
```

3. Enable pnpm

```bash
corepack enable pnpm
```

4. Install dependencies

```bash
pnpm install
```

5. Start the app

```bash
pnpm start
```

(If you get a `too many open files` error, `rm -rf node_modules; npm install` will [fix](https://github.com/Trustroots/nostroots/issues/30) this, funny enough.)

### View the app

You cannot (currently) view the app in the web. The maps package is not supported on web. The easiest option is to install an app called Expo Go into your phone. Then you can scan the QR code that was output in the terminal from the `pnpm start` command and the app will load onto your phone.

This requires that your phone and computer are on the same network, and that your phone can load the app from your computer.

You can also install Android Studio or XCode and then load the app in a simulator. That is beyond the scope of this readme, but [the expo docs](https://docs.expo.dev/get-started/set-up-your-environment/) are a good place to start.

## Learn more

To learn more about developing your project with Expo, look at the following resources:

- [Expo documentation](https://docs.expo.dev/): Learn fundamentals, or go into advanced topics with our [guides](https://docs.expo.dev/guides).
- [Learn Expo tutorial](https://docs.expo.dev/tutorial/introduction/): Follow a step-by-step tutorial where you'll create a project that runs on Android, iOS, and the web.

## Join the community

Join our community of developers creating universal apps.

- [Expo on GitHub](https://github.com/expo/expo): View our open source platform and contribute.
- [Discord community](https://chat.expo.dev): Chat with Expo users and ask questions.
If you want to run a development build on your phone, you'll have to download the latest app and scan the QR code with it. For Android, you can use an existing build from https://expo.dev/accounts/nostroots/projects/nr-app/builds/ . For iOS, you'd have to register your device first using `eas devices` and then make a build.
22 changes: 18 additions & 4 deletions nr-app/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,25 @@
"backgroundColor": "#ffffff"
},
"ios": {
"supportsTablet": true
"supportsTablet": true,
"bundleIdentifier": "org.trustroots.nostroots",
"config": {
"googleMapsApiKey": "AIzaSyDw0KhR3qlPsireu68RvGXmh4nccIqnEQM"
},
"infoPlist": {
"ITSAppUsesNonExemptEncryption": false
}
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/images/adaptive-icon.png",
"backgroundColor": "#ffffff"
},
"package": "org.trustroots.nostroots",
"config": {
"googleMaps": {
"apiKey": "AIzaSyCr1ZxZlVQNI_u7FYfPkjgvZv79UeaPFYQ"
}
}
},
"web": {
Expand All @@ -40,7 +53,7 @@
"origin": false
},
"eas": {
"projectId": "0147b304-d2cd-4e24-a237-da8bd5f3e4f3"
"projectId": "a6c7b2e0-f036-44a3-b57c-d05b9d383c30"
}
},
"runtimeVersion": {
Expand All @@ -49,6 +62,7 @@
"newArchEnabled": true,
"updates": {
"url": "https://u.expo.dev/0147b304-d2cd-4e24-a237-da8bd5f3e4f3"
}
},
"owner": "nostroots"
}
}
}
19 changes: 3 additions & 16 deletions nr-app/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,10 @@ module.exports = function (api) {
presets: ["babel-preset-expo"],
plugins: [
[
"module-resolver",
"babel-plugin-root-import",
{
extensions: [
".ios.js",
".android.js",
".ios.jsx",
".android.jsx",
".js",
".jsx",
".json",
".ts",
".tsx",
],
root: ["."],
alias: {
"@common": "../nr-common",
},
rootPathPrefix: "@/",
rootPathSuffix: "src/",
},
],
],
Expand Down
19 changes: 19 additions & 0 deletions nr-app/eas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"cli": {
"version": ">= 14.2.0",
"appVersionSource": "remote"
},
"build": {
"development": {
"developmentClient": true,
"distribution": "internal"
},
"preview": {
"distribution": "internal"
},
"production": {}
},
"submit": {
"production": {}
}
}
22 changes: 0 additions & 22 deletions nr-app/eas_DISABLED.json

This file was deleted.

21 changes: 13 additions & 8 deletions nr-app/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
// Learn more https://docs.expo.io/guides/customizing-metro
// Learn more https://docs.expo.dev/guides/monorepos
const { getDefaultConfig } = require("expo/metro-config");
const path = require("path");

/** @type {import('expo/metro-config').MetroConfig} */
const config = getDefaultConfig(__dirname);
const projectRoot = __dirname;
const workspaceRoot = path.resolve(projectRoot, "..");

const extraConfig = {
watchFolders: [path.resolve(`${__dirname}/../nr-common/`)],
};
const config = getDefaultConfig(projectRoot);

const mergedConfig = { ...config, ...extraConfig };
// Since we are using pnpm, we have to setup the monorepo manually for Metro
// #1 - Watch all files in the monorepo
config.watchFolders = [workspaceRoot];
// #2 - Try resolving with project modules first, then workspace modules
config.resolver.nodeModulesPaths = [
path.resolve(projectRoot, "node_modules"),
path.resolve(workspaceRoot, "node_modules"),
];

module.exports = mergedConfig;
module.exports = config;
32 changes: 21 additions & 11 deletions nr-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"scripts": {
"start": "expo start",
"reset-project": "node ./scripts/reset-project.js",
"android": "expo start --android",
"ios": "expo start --ios",
"android": "expo run:android",
"ios": "expo run:ios",
"web": "expo start --web",
"test": "jest --watchAll",
"lint": "expo lint",
Expand All @@ -23,9 +23,11 @@
"@mobily/ts-belt": "^3.13.1",
"@react-navigation/native": "^7.0.3",
"@reduxjs/toolkit": "^2.2.7",
"@trustroots/nr-common": "workspace:*",
"expo": "~52.0.8",
"expo-constants": "~17.0.3",
"expo-crypto": "~14.0.1",
"expo-dev-client": "~5.0.7",
"expo-font": "~13.0.1",
"expo-linking": "~7.0.3",
"expo-router": "~4.0.7",
Expand All @@ -42,14 +44,14 @@
"open-location-code-typescript": "^1.5.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-native": "0.76.2",
"react-native": "0.76.5",
"react-native-gesture-handler": "~2.20.2",
"react-native-get-random-values": "^1.11.0",
"react-native-maps": "1.18.0",
"react-native-reanimated": "~3.16.1",
"react-native-root-toast": "^3.6.0",
"react-native-safe-area-context": "4.12.0",
"react-native-screens": "4.1.0",
"react-native-screens": "4.4.0",
"react-native-web": "~0.19.13",
"react-redux": "^9.1.2",
"reactotron-react-native": "^5.1.10",
Expand All @@ -58,6 +60,7 @@
"redux-saga-promise-actions": "^1.3.5",
"reselect": "^5.1.1",
"url-join": "^5.0.0",
"utils": "link:@noble/hashes/utils",
"zod": "^3.23.8"
},
"devDependencies": {
Expand All @@ -68,6 +71,7 @@
"@types/react": "~18.3.12",
"@types/react-test-renderer": "^18.0.7",
"babel-plugin-module-resolver": "^5.0.2",
"babel-plugin-root-import": "^6.6.0",
"eslint": "^8.57.0",
"eslint-config-expo": "^8.0.1",
"eslint-config-prettier": "^9.1.0",
Expand All @@ -79,11 +83,17 @@
"react-test-renderer": "18.2.0",
"typescript": "~5.3.3"
},
"pnpm": {
"overrides": {
"redux": "^5.0.1"
}
},
"private": true,
"packageManager": "[email protected]+sha512.e5a7e52a4183a02d5931057f7a0dbff9d5e9ce3161e33fa68ae392125b79282a8a8a470a51dfc8a0ed86221442eb2fb57019b0990ed24fab519bf0e1bc5ccfc4"
}
"packageManager": "[email protected]+sha512.e5a7e52a4183a02d5931057f7a0dbff9d5e9ce3161e33fa68ae392125b79282a8a8a470a51dfc8a0ed86221442eb2fb57019b0990ed24fab519bf0e1bc5ccfc4",
"expo": {
"doctor": {
"reactNativeDirectoryCheck": {
"listUnknownPackages": false,
"exclude": [
"expo-split-pane",
"react-native-maps"
]
}
}
}
}
2 changes: 1 addition & 1 deletion nr-app/src/__tests__/nr-common-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isPlusCode } from "@common/utils";
import { isPlusCode } from "@trustroots/nr-common";

const plusCodeTestData: [string, number, number, number, number, number][] = [
["7FG49Q00+", 6, 20.35, 2.75, 20.4, 2.8],
Expand Down
4 changes: 2 additions & 2 deletions nr-app/src/common/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Filter } from "nostr-tools";
import { MapLayer, NOSTROOTS_VALIDATION_PUBKEY } from "@common/constants";
import { isHexKey } from "@common/utils";
import { MapLayer, NOSTROOTS_VALIDATION_PUBKEY } from "@trustroots/nr-common";
import { isHexKey } from "@trustroots/nr-common";

// TODO - Move these into `nr-common` (they depend on nostr-tools)

Expand Down
2 changes: 1 addition & 1 deletion nr-app/src/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { publishNotePromiseAction } from "@/redux/actions/publish.actions";
import { useAppDispatch, useAppSelector } from "@/redux/hooks";
import { mapActions, mapSelectors } from "@/redux/slices/map.slice";
import { coordinatesToPlusCode } from "@/utils/map.utils";
import { MAP_LAYER_KEY, MAP_LAYERS, MapLayer } from "@common/constants";
import { MAP_LAYER_KEY, MAP_LAYERS, MapLayer } from "@trustroots/nr-common";
import React, { useMemo, useState } from "react";
import { Button, Modal, TextInput } from "react-native";
import Toast from "react-native-root-toast";
Expand Down
14 changes: 12 additions & 2 deletions nr-app/src/components/MapMarkers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ import {
} from "@/redux/slices/events.slice";
import { mapActions, mapSelectors } from "@/redux/slices/map.slice";
import { allPlusCodesForRegion } from "@/utils/map.utils";
import { MAP_LAYER_KEY, MAP_LAYERS } from "@common/constants";
import { MAP_LAYER_KEY, MAP_LAYERS } from "@trustroots/nr-common";
import { createSelector } from "@reduxjs/toolkit";
import { matchFilter } from "nostr-tools";
import { Fragment, useMemo } from "react";
import { StyleSheet } from "react-native";
import { Platform, StyleSheet } from "react-native";
import MapView, {
Details,
LongPressEvent,
Marker,
Region,
PROVIDER_GOOGLE,
PROVIDER_DEFAULT,
} from "react-native-maps";
import { MapNoteMarker } from "./MapNoteMarker";
import Constants, { ExecutionEnvironment } from "expo-constants";

const selectEventsForLayers = createSelector(
[eventsSelectors.selectAll, mapSelectors.selectEnabledLayerKeys],
Expand Down Expand Up @@ -74,6 +77,13 @@ export function MapMarkers() {
pitchEnabled={false}
onLongPress={handleMapLongPress}
onRegionChangeComplete={handleMapRegionChange}
// only use google maps on android dev and prod builds
provider={
Constants.executionEnvironment === ExecutionEnvironment.StoreClient ||
Platform.OS !== "android"
? PROVIDER_DEFAULT
: PROVIDER_GOOGLE
}
>
<Marker
coordinate={{ latitude: 52, longitude: 13 }}
Expand Down
Loading

0 comments on commit 4a5c35b

Please sign in to comment.