Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Example - PurchaseTester TypeScript #320

Merged
merged 37 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b5165d3
Initial commit of purchaseTester typescript example
Dec 15, 2021
7d74043
Made things a little prettier for offering detail
joshdholtz Dec 28, 2021
64df393
Removed console log
joshdholtz Dec 28, 2021
bfbf128
Typescript example using local RNPurchases pod
joshdholtz Dec 28, 2021
e29289a
Fix some things were states weren't updating
joshdholtz Dec 28, 2021
2d8685e
Trying to fix CircleCI
joshdholtz Dec 28, 2021
c3a1f54
This is it
joshdholtz Dec 28, 2021
cc86f42
name isn't a thing for the RN builds
joshdholtz Dec 28, 2021
e88abde
name also isn't a thing for iOS RN builds
joshdholtz Dec 28, 2021
b69a88a
Add set attributes which isnt really working yet
joshdholtz Dec 29, 2021
4e052af
Fix broken test
joshdholtz Dec 29, 2021
2239b1d
Fix broken test... again
joshdholtz Dec 29, 2021
42ef1b7
Ignore package-lock.json, try using rn/yarn_install on circleci, move…
joshdholtz Jan 3, 2022
1cd69fc
Trying to get yarn_install to run in the example directory
joshdholtz Jan 3, 2022
60735a0
Change yarn cache folder
joshdholtz Jan 3, 2022
f238ce8
Try bringing in the yarn install from the orb for testing
joshdholtz Jan 3, 2022
9f7b4d9
Try yarn cwd before calling rn/yarn_install
joshdholtz Jan 3, 2022
84226f7
That didn't work
joshdholtz Jan 3, 2022
f2505ba
This should fix android
joshdholtz Jan 3, 2022
13c11ad
This should fix macos symlink issue
joshdholtz Jan 3, 2022
2ac8df6
Reset cache to see if fix worked
joshdholtz Jan 3, 2022
ccd9151
Lets start over on circleci
joshdholtz Jan 3, 2022
23919bb
Add path for yarn pod
joshdholtz Jan 3, 2022
0549cf0
Experimenting
joshdholtz Jan 3, 2022
6264551
This should do it
joshdholtz Jan 3, 2022
92a68bf
--cwd doesnt work with yarn pods
joshdholtz Jan 3, 2022
e656e8d
Need to warn install both examples
joshdholtz Jan 3, 2022
4ad51cc
Try with rn/yarn_install but copied over with path param
joshdholtz Jan 3, 2022
03b5b48
Forgot to replace cache path
joshdholtz Jan 3, 2022
55e8ee2
Cleanup because things works :)
joshdholtz Jan 3, 2022
fb32dab
Need to put path to ios directory
joshdholtz Jan 3, 2022
d45adc2
Use conditional logic and use --cwd if not empty string
joshdholtz Jan 3, 2022
f9b5e97
Rename to use standard revenuecat tester package and bundle id
joshdholtz Jan 3, 2022
74810a5
Bump to react-native-community/[email protected]
joshdholtz Jan 4, 2022
422a4f2
Rename isSetup to hasKeys
joshdholtz Jan 5, 2022
8843578
Setup local testing for PurchaseTester Typescript (#326)
joshdholtz Jan 11, 2022
01e36e9
Rename storekit config file and add second target that does not use s…
joshdholtz Jan 11, 2022
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
84 changes: 29 additions & 55 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,7 @@
version: 2.1
orbs:
rn: react-native-community/react-native@6.0.1
rn: react-native-community/react-native@6.1.0
commands:
yarn_install_example:
steps:
- run:
command: >
mkdir -p ~/.tmp/checksumfiles

find . -type f -name 'package.json' -not -path "*node_modules*" -exec
cat {} + >> ~/.tmp/checksumfiles/package.json

find . -type f -name 'yarn.lock' -not -path "*node_modules*" -exec cat
{} + >> ~/.tmp/checksumfiles/yarn.lock
name: Create cache checksum file

# Commented out because something is up with the permissions of the cache folder in the machines.
# There's an open issue here: react-native-community/react-native-circleci-orb#66

# - restore_cache:
# keys:
# - >-
# yarn-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/package.json"
# }}-{{ checksum "~/.tmp/checksumfiles/yarn.lock" }}-{{
# .Environment.CACHE_VERSION }}
- run:
command: >-
yarn --cwd examples/purchaseTester && yarn install --non-interactive --cache-folder /tmp/yarn
name: Yarn Install
# - save_cache:
# key: >
# yarn-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/package.json"
# }}-{{ checksum "~/.tmp/checksumfiles/yarn.lock" }}-{{
# .Environment.CACHE_VERSION }}
# paths:
# - /tmp/yarn

install_pods:
steps:
- restore_cache:
keys:
- cache-pods-{{ checksum "examples/purchaseTester/ios/Podfile.lock" }}-{{ .Environment.CACHE_VERSION }}
- cache-pods-
- run:
command: yarn pods
name: Pod install
- save_cache:
paths:
- examples/purchaseTester/ios/Pods
key: cache-pods-{{ checksum "examples/purchaseTester/ios/Podfile.lock" }}-{{ .Environment.CACHE_VERSION }}

jobs:
analyse_js:
Copy link
Contributor

Choose a reason for hiding this comment

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

should we rename this now that it's not just js?

Copy link
Member Author

Choose a reason for hiding this comment

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

I started to rename this to just analyse but it then made it unclear what layer it was analyzing 🤔 Even though its not 100% correct and TypeScript is a superset of JavaScript, I think it feels less worse this way 😅

Copy link
Member

@aboedo aboedo Jan 7, 2022

Choose a reason for hiding this comment

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

how about analyze_ts_and_js or analyze_ts_js? I usually go overly explicit even if it becomes verbose

Expand All @@ -57,7 +10,15 @@ jobs:
node_version: '12'
steps:
- checkout
- yarn_install_example
- rn/yarn_install:
yarn_install_directory: examples/purchaseTester
cache_folder: ~/.cache/yarn
- rn/yarn_install:
yarn_install_directory: examples/purchaseTesterTypescript
cache_folder: ~/.cache/yarn
- run:
name: Yarn Install
command: yarn install --non-interactive --cache-folder /tmp/yarn
- run:
name: Tests
command: yarn test
Expand All @@ -68,9 +29,14 @@ jobs:
executor: rn/linux_android
steps:
- checkout
- yarn_install_example
- rn/yarn_install:
yarn_install_directory: examples/purchaseTester
cache_folder: ~/.cache/yarn
- rn/yarn_install:
yarn_install_directory: examples/purchaseTesterTypescript
cache_folder: ~/.cache/yarn
- rn/android_build:
project_path: examples/purchaseTester/android
project_path: examples/purchaseTesterTypescript/android
ios:
executor:
name: rn/macos
Expand All @@ -79,15 +45,23 @@ jobs:
- checkout
- rn/ios_simulator_start:
device: iPhone 11 Pro
- yarn_install_example
- install_pods
- rn/yarn_install:
yarn_install_directory: examples/purchaseTester
cache_folder: ~/.cache/yarn
- rn/yarn_install:
yarn_install_directory: examples/purchaseTesterTypescript
cache_folder: ~/.cache/yarn
- rn/pod_install:
pod_install_directory: examples/purchaseTester/ios
- rn/pod_install:
pod_install_directory: examples/purchaseTesterTypescript/ios
- rn/ios_build:
build_configuration: Release
device: iPhone 11 Pro
derived_data_path: ~/DerivedData
project_type: workspace
project_path: examples/purchaseTester/ios/ReactNativeSample.xcworkspace
scheme: ReactNativeSample
project_path: examples/purchaseTesterTypescript/ios/PurchaseTester.xcworkspace
scheme: PurchaseTester
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we need to build both apps. Running one takes already very long. I am all for just doing one, preferably the new one you just created. Also, I understand we want to keep both tester apps because one is JS and the other one is TS, but the JS one is so bad... maybe we could just simplify it even more than it is now and keep it as a barebones app where we can test the API. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah yeah, this takes super long 😱 I agree that running the typescript one probably makes the most sense. I think more issues could come out of that one than the javascript one.

maybe we could just simplify it even more than it is now and keep it as a barebones app where we can test the API. What do you think?

Are you referring to the javascript one? ☝️

Copy link
Member

Choose a reason for hiding this comment

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

@vegaro do you mean turning the javascript app into an API tester?


workflows:
test:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ node_modules/
npm-debug.log
yarn-error.log
**/yarn.lock
**/package-lock.json
Copy link
Contributor

Choose a reason for hiding this comment

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

🔥


# Xcode
#
Expand Down
8 changes: 4 additions & 4 deletions examples/purchaseTester/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ PODS:
- React-perflogger (= 0.64.3)
- RNGestureHandler (1.10.3):
- React-Core
- RNPurchases (4.4.1):
- RNPurchases (4.5.0):
- PurchasesHybridCommon (= 1.11.1)
- React-Core
- RNScreens (2.18.1):
Expand Down Expand Up @@ -473,7 +473,7 @@ SPEC CHECKSUMS:
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
DoubleConversion: cf9b38bf0b2d048436d9a82ad2abe1404f11e7de
FBLazyVector: c71c5917ec0ad2de41d5d06a5855f6d5eda06971
FBReactNativeSpec: a2b6216a2bf6c8d5ea8963a88fa38290bbbdc414
FBReactNativeSpec: 6a7ee9cb0839006f75cc5c23f6d5283dc6080c4d
Flipper: d3da1aa199aad94455ae725e9f3aa43f3ec17021
Flipper-DoubleConversion: 38631e41ef4f9b12861c67d17cb5518d06badc41
Flipper-Folly: 755929a4f851b2fb2c347d533a23f191b008554c
Expand Down Expand Up @@ -511,11 +511,11 @@ SPEC CHECKSUMS:
React-runtimeexecutor: 493d9abb8b23c3f84e19ae221eeba92cadcb70dc
ReactCommon: 8fea6422328e2fc093e25c9fac67adbcf0f04fb4
RNGestureHandler: a479ebd5ed4221a810967000735517df0d2db211
RNPurchases: ac0462ae7af5921b5f3e6578a542b24f207efcb4
RNPurchases: aa1b4dff749eb760c6de50f1d987aa45455e58a8
RNScreens: f7ad633b2e0190b77b6a7aab7f914fad6f198d8d
Yoga: e6ecf3fa25af9d4c87e94ad7d5d292eedef49749
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: ef0169631a326f7a668fc6ea8da5bdfe60d83f4c

COCOAPODS: 1.10.1
COCOAPODS: 1.11.2
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-ReactNativeSample/Pods-ReactNativeSample-frameworks.sh",
"${PODS_XCFRAMEWORKS_BUILD_DIR}/OpenSSL/OpenSSL.framework/OpenSSL",
"${PODS_XCFRAMEWORKS_BUILD_DIR}/OpenSSL-Universal/OpenSSL.framework/OpenSSL",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
Expand Down Expand Up @@ -384,7 +384,7 @@
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 ";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -438,7 +438,7 @@
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 ";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand Down
6 changes: 6 additions & 0 deletions examples/purchaseTesterTypescript/.buckconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

idk if this kinda file is common knowledge for RN developers (and maybe ignore me if so), but could we add a comment on what this does for us?

[android]
target = Google Inc.:Google APIs:23

[maven_repositories]
central = https://repo1.maven.org/maven2
3 changes: 3 additions & 0 deletions examples/purchaseTesterTypescript/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Windows files
[*.bat]
end_of_line = crlf
8 changes: 8 additions & 0 deletions examples/purchaseTesterTypescript/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
root: true,
extends: '@react-native-community',
rules: {
"no-shadow": "off",
"@typescript-eslint/no-shadow": ["error"],
},
};
3 changes: 3 additions & 0 deletions examples/purchaseTesterTypescript/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Windows files should use crlf line endings
# https://help.github.com/articles/dealing-with-line-endings/
*.bat text eol=crlf
60 changes: 60 additions & 0 deletions examples/purchaseTesterTypescript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml
*.hprof

# node.js
#
node_modules/
npm-debug.log
yarn-error.log

# BUCK
buck-out/
\.buckd/
*.keystore
!debug.keystore

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/

*/fastlane/report.xml
*/fastlane/Preview.html
*/fastlane/screenshots

# Bundle artifact
*.jsbundle

# CocoaPods
/ios/Pods/
7 changes: 7 additions & 0 deletions examples/purchaseTesterTypescript/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
bracketSpacing: false,
jsxBracketSameLine: true,
singleQuote: true,
trailingComma: 'all',
arrowParens: 'avoid',
};
1 change: 1 addition & 0 deletions examples/purchaseTesterTypescript/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
65 changes: 65 additions & 0 deletions examples/purchaseTesterTypescript/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* Generated with the TypeScript template
* https://github.com/react-native-community/react-native-template-typescript
*
* @format
*/

import React, { useEffect } from 'react';

import { Platform, Text } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';

import Purchases from 'react-native-purchases';

import HomeScreen from './app/screens/HomeScreen';
import CustomerInfoScreen from './app/screens/CustomerInfoScreen';
import OfferingDetailScreen from './app/screens/OfferingDetailScreen';

import APIKeys from './app/APIKeys';
import { SafeAreaView } from 'react-native-safe-area-context';

const Stack = createNativeStackNavigator();

const App = () => {
const isSetup = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is nitpicky, but could we rename to something like hasKeys? just since setup is now a little overloaded... isSetup could also mean whether Purchases is configured

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a much better name 😊 Love it!

return APIKeys.apple.length > 0 || APIKeys.google.length > 0;
}

useEffect(() => {
if (!isSetup()) { return }

Purchases.setDebugLogsEnabled(true);
if (Platform.OS == "android") {
Purchases.setup(APIKeys.google);
} else {
Purchases.setup(APIKeys.apple);
}
}, []);

return !isSetup() ? (
<SafeAreaView>
<Text style={{margin: 20, textAlign: 'center'}}>
Update RevenueCat API Keys in APIKeys.tsx
</Text>
</SafeAreaView>
) : (
<NavigationContainer>
<Stack.Navigator initialRouteName="Home">
<Stack.Screen
name="Home"
component={HomeScreen}
options={{ title: 'PurchaseTester' }}
/>
<Stack.Screen name="CustomerInfo" component={CustomerInfoScreen} />
<Stack.Screen name="OfferingDetail" component={OfferingDetailScreen} />
</Stack.Navigator>
</NavigationContainer>
Copy link
Contributor

Choose a reason for hiding this comment

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

i love this, we should definitely consider in the other platforms. of course well get a configuration error, but if you can't view debug logs you might not know

);
};

export default App;
14 changes: 14 additions & 0 deletions examples/purchaseTesterTypescript/__tests__/App-test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @format
*/

import 'react-native';
import React from 'react';
import App from '../App';

// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';

it('renders correctly', () => {
renderer.create(<App />);
});
Loading