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

example app flow changes #51

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"android": "./scripts/installer.sh android",
"ios": "./scripts/installer.sh ios",
"lint": "eslint .",
"start": "react-native start",
"start": "./scripts/start-metro.sh",
"test": "jest"
},
"dependencies": {
Expand Down Expand Up @@ -36,4 +36,4 @@
"engines": {
"node": ">=18"
}
}
}
61 changes: 61 additions & 0 deletions example/scripts/installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

PLATFORM=${1:-}

# Function to fetch the version from the package.json using Node.js
get_package_version() {
node -p "require('../payment_sdk/package.json').version"
}

# Function to terminate Metro
terminate_metro() {
if pgrep -f "node.*metro" > /dev/null; then
echo "Terminating Metro server..."
pkill -f "node.*metro"
else
echo "Metro server is not running."
fi
}

# Uninstall the package from example
echo "Uninstalling @komoju/komoju-react-native from example"
npm uninstall @komoju/komoju-react-native

# Change directory to payment_sdk
echo "Changing directory to payment_sdk"
cd ../payment_sdk

# Build the package
echo "Building the package"
npm run build

# Get the version from package.json
PACKAGE_VERSION=$(get_package_version)
echo "Package version found: $PACKAGE_VERSION"

# Change directory back to example
echo "Changing directory back to example"
cd ../example

# Install the built package
echo "Installing the built package version $PACKAGE_VERSION"
npm i "../payment_sdk/komoju-komoju-react-native-${PACKAGE_VERSION}.tgz"

# Terminate Metro
terminate_metro

# Run platform-specific command if provided
case $PLATFORM in
android)
echo "Running on Android"
react-native run-android
;;
ios)
echo "Running on iOS"
react-native run-ios
;;
esac

echo "Installation and build process complete!"
20 changes: 20 additions & 0 deletions example/scripts/start-metro.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

# Function to terminate Metro
terminate_metro() {
if pgrep -f "node.*metro" > /dev/null; then
echo "Terminating Metro server..."
pkill -f "node.*metro"
else
echo "Metro server is not running."
fi
}

# Terminate any running Metro server
terminate_metro

# Start the Metro server with cache clean
echo "Starting Metro server with cache clean"
npx react-native start --reset-cache
19 changes: 13 additions & 6 deletions payment_sdk/scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ EOF
}

percentEncodeString() {
jq -rn --arg x "$1" '$x|@uri'
node -p "encodeURIComponent('$1')"
}

create_github_release() {
Expand Down Expand Up @@ -128,20 +128,27 @@ npm run build
echo "Bumping package.json $RELEASE_TYPE version and tagging commit"
npm version $RELEASE_TYPE

# Extract the new version from package.json
NEW_VERSION=$(node -p "require('./package.json').version")

# Update the version in ../example/package.json
echo "Updating version in ../example/package.json to $NEW_VERSION"
node -p "const fs = require('fs'); const path = '../example/package.json'; const pkg = JSON.parse(fs.readFileSync(path, 'utf8')); pkg.version = '$NEW_VERSION'; fs.writeFileSync(path, JSON.stringify(pkg, null, 2))"

echo "Publishing release to npm"
npm publish --access=public

echo "Pushing git commit and tag"
git add package.json ../example/package.json
git commit -m "Update package.json and example package.json to version $NEW_VERSION"
git push --follow-tags

# echo "Pushing git changes to main brach"
# git add package.json
# git commit -m "package.json"
# git push origin main
echo "Updating the main branch"
git push origin main

echo "Publish successful!"
echo ""

create_github_release

echo "Done!"
echo "Done!"
Loading