Skip to content

Commit

Permalink
New Example - PurchaseTester TypeScript (#320)
Browse files Browse the repository at this point in the history
* Initial commit of purchaseTester typescript example

* Made things a little prettier for offering detail

* Removed console log

* Typescript example using local RNPurchases pod

* Fix some things were states weren't updating

* Trying to fix CircleCI

* This is it

* name isn't a thing for the RN builds

* name also isn't a thing for iOS RN builds

* Add set attributes which isnt really working yet

* Fix broken test

* Fix broken test... again

* Ignore package-lock.json, try using rn/yarn_install on circleci, move RC init to app.tsx

* Trying to get yarn_install to run in the example directory

* Change yarn cache folder

* Try bringing in the yarn install from the orb for testing

* Try yarn cwd before calling rn/yarn_install

* That didn't work

* This should fix android

* This should fix macos symlink issue

* Reset cache to see if fix worked

* Lets start over on circleci

* Add path for yarn pod

* Experimenting

* This should do it

* --cwd doesnt work with yarn pods

* Need to warn install both examples

* Try with rn/yarn_install but copied over with path param

* Forgot to replace cache path

* Cleanup because things works :)

* Need to put path to ios directory

* Use conditional logic and use --cwd if not empty string

* Rename to use standard revenuecat tester package and bundle id

* Bump to react-native-community/[email protected]

* Rename isSetup to hasKeys

* Setup local testing for PurchaseTester Typescript (#326)

* This works so much better for local testing

* Updated comments to be more helpful

* Fixed typo

* Need to await the initial fetchData

* Rename storekit config file and add second target that does not use sk config file

Co-authored-by: Josh Holtz <[email protected]>
  • Loading branch information
joshdholtz and Josh Holtz authored Jan 13, 2022
1 parent cd69aa0 commit a90ea99
Show file tree
Hide file tree
Showing 73 changed files with 3,985 additions and 64 deletions.
86 changes: 31 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:
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 @@ -80,15 +46,25 @@ 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/yarn_install:
cache_folder: ~/.cache/yarn
- 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

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

# 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 @@

[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 hasKeys = () => {
return APIKeys.apple.length > 0 || APIKeys.google.length > 0;
}

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

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

return !hasKeys() ? (
<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>
);
};

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

0 comments on commit a90ea99

Please sign in to comment.