Skip to content

Commit

Permalink
get dev build working!
Browse files Browse the repository at this point in the history
  • Loading branch information
bongolegend committed Jul 7, 2024
1 parent 17b53cf commit d8c1876
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ ios/

# EAS
credentials.json
build-*
build-*
config.json
11 changes: 11 additions & 0 deletions config.json.TEMPLATE
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"dev": {
"stacks_api_url": "http://localhost:8000"
},
"dev-device": {
"stacks_api_url": "<public url of your host machine, assuming the stacks api is running on 0.0.0.0>"
},
"prod": {
"stacks_api_url": ""
}
}
5 changes: 1 addition & 4 deletions eas.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
"build": {
"development": {
"developmentClient": true,
"distribution": "internal",
"env": {
"ENV": "dev-device"
}
"distribution": "internal"
},
"preview": {
"distribution": "internal"
Expand Down
15 changes: 4 additions & 11 deletions package-lock.json

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

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
"expo-notifications": "~0.28.9",
"expo-router": "^3.5.14",
"expo-status-bar": "~1.12.1",
"fs": "^0.0.1-security",
"js-yaml": "^4.1.0",
"react": "18.2.0",
"react-datepicker": "^7.2.0",
"react-dom": "18.2.0",
Expand Down
14 changes: 13 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,21 @@ Then I could finally run the build
```eas build -p ios --local --profile development```
The build errored
```Distribution certificate with fingerprint xxxxxxxxxxx hasn't been imported successfully```
So I downloaded my Apple Cert and added it to my keychain
So I downloaded my Apple Cert and added it to my keychain.
https://developer.apple.com/account/resources/certificates/list

I also added a credentials.json file to the project (gitignored) by executing this but idk if you need it.
```eas credentials```

But I still got the same error, so I installed this other universal cert and got past that error.
https://github.com/expo/eas-cli/issues/1331#issuecomment-1235603312


#### Note about ENV VARS
The dev build works in a weird way, in that even though it is running on device, it relies on a Metro server
running on my Mac. I thought that I needed to specify the EXPO_PUBLIC_ENV when building the dev build. But it turns out
that I must specify that when running the server. So start the server like this:

```EXPO_PUBLIC_ENV=dev-device npx expo start```

The prefix `EXPO_PUBLIC_` is required for all env vars.
7 changes: 2 additions & 5 deletions screens/InApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@ import Notifications from './Notifications';
import { Ionicons } from '@expo/vector-icons'; // Import Ionicons
import { useQuery } from '@tanstack/react-query'; // Import useQuery from React Query
import { fetchUnreadCommentCount } from '../services/api';
import registerForPushNotification from '../services/pushNotification';
import RegisterForPushNotification from '../services/pushNotification';

const Tab = createBottomTabNavigator();

const InApp: React.FC = () => {
const navigation = useNavigation();
const { user, isLoading } = useUser();

if (Platform.OS === 'ios' && user?.id) {
registerForPushNotification(user?.id);
}

const { data: unreadCount = 0 } = useQuery({
queryKey: ['unreadCommentCount'],
Expand All @@ -42,6 +38,7 @@ const InApp: React.FC = () => {
return (
<View style={styles.container}>
<HeaderBar />
{Platform.OS === 'ios' && user?.id && <RegisterForPushNotification userId={user?.id} />}
<Tab.Navigator
screenOptions={({ route }) => ({
headerShown: false,
Expand Down
12 changes: 10 additions & 2 deletions services/pushNotification.ts → services/pushNotification.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { useEffect, useRef } from 'react';
import { Platform } from 'react-native';
import { View, Platform } from 'react-native';
import * as Device from 'expo-device';
import * as Notifications from 'expo-notifications';
import Constants from 'expo-constants';
Expand Down Expand Up @@ -61,7 +62,11 @@ async function registerForPushNotificationsAsync() {
}
}

export default function registerForPushNotification(userId: string) {
interface RegisterForPushNotificationProps {
userId: string;
}

const RegisterForPushNotification: React.FC<RegisterForPushNotificationProps> = ({userId}) => {
const notificationListener = useRef<Notifications.Subscription>();
const responseListener = useRef<Notifications.Subscription>();

Expand All @@ -87,4 +92,7 @@ export default function registerForPushNotification(userId: string) {
Notifications.removeNotificationSubscription(responseListener.current);
};
}, []);
return (<View/>);
}

export default RegisterForPushNotification;
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"compilerOptions": {},
"compilerOptions": {
"resolveJsonModule": true,
"esModuleInterop": true
},
"extends": "expo/tsconfig.base"
}
9 changes: 4 additions & 5 deletions utils/config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import fs from 'fs';
import yaml from 'js-yaml';
import config from '../config.json';

interface Config {
[key: string]: any;
}

const getConfig = (env?: string): Config => {
if (!env) {
env = process.env.ENV || 'dev';
console.log("EXPO_PUBLIC_ENV: ", process.env.EXPO_PUBLIC_ENV);
env = process.env.EXPO_PUBLIC_ENV || 'dev';
console.log(`Using ${env} environment`);
}
const fileContents = fs.readFileSync('../config.yaml', 'utf8');
const config: Config = yaml.load(fileContents) as Config;
return config[env];
};

Expand Down

0 comments on commit d8c1876

Please sign in to comment.