From df8d577d7c6b28753a9d31e3b9f60fa1f3957abb Mon Sep 17 00:00:00 2001 From: Mark Murray Date: Sat, 7 Dec 2024 19:32:07 +0000 Subject: [PATCH 1/3] Autogenerate manifest from env, update intents --- .gitignore | 3 ++ ...ifest.xml => AndroidManifest.template.xml} | 14 ++++++++ sample/package.json | 2 +- sample/scripts/generate_manifest | 34 +++++++++++++++++++ sample/scripts/prestart | 5 +++ 5 files changed, 57 insertions(+), 1 deletion(-) rename sample/android/app/src/main/{AndroidManifest.xml => AndroidManifest.template.xml} (58%) create mode 100755 sample/scripts/generate_manifest create mode 100755 sample/scripts/prestart diff --git a/.gitignore b/.gitignore index 5fddb68..86e3ab4 100644 --- a/.gitignore +++ b/.gitignore @@ -103,3 +103,6 @@ sample/vendor !.yarn/releases !.yarn/sdks !.yarn/versions + +# Sample app +sample/**/AndroidManifest.xml diff --git a/sample/android/app/src/main/AndroidManifest.xml b/sample/android/app/src/main/AndroidManifest.template.xml similarity index 58% rename from sample/android/app/src/main/AndroidManifest.xml rename to sample/android/app/src/main/AndroidManifest.template.xml index f9fabb2..7e0fab1 100644 --- a/sample/android/app/src/main/AndroidManifest.xml +++ b/sample/android/app/src/main/AndroidManifest.template.xml @@ -1,6 +1,8 @@ + + + + + + + + + + + + + + diff --git a/sample/package.json b/sample/package.json index 603e87a..c60d3c4 100644 --- a/sample/package.json +++ b/sample/package.json @@ -11,7 +11,7 @@ "build:ios": "sh ./scripts/build_ios", "lint": "yarn typecheck && eslint .", "ios": "react-native run-ios --simulator 'iPhone 15 Pro'", - "start": "react-native start -- --simulator 'iPhone 15 Pro'", + "start": "./scripts/prestart && react-native start -- --simulator 'iPhone 15 Pro' --reset-cache", "typecheck": "tsc --noEmit", "test:ios": "sh ./scripts/test_ios", "test:android": "sh ./scripts/test_android" diff --git a/sample/scripts/generate_manifest b/sample/scripts/generate_manifest new file mode 100755 index 0000000..abd015b --- /dev/null +++ b/sample/scripts/generate_manifest @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +set -e + +DIR=android/app/src/main +MANIFEST=AndroidManifest.xml +TEMPLATE=AndroidManifest.template.xml + +# Ensure env exists +if [ ! -f .env ]; then + echo "sample/.env file not found!" >&2 + exit 1 +fi + +# Read env file +source .env + +# Ensure STOREFRONT_DOMAIN is set +if [ -z "$STOREFRONT_DOMAIN" ]; then + echo "Error: STOREFRONT_DOMAIN is missing from .env" >&2 + exit 1 +fi + +# Check if manifest already exists +if [ -f "$DIR/$MANIFEST" ]; then + echo "✅ \"$MANIFEST\" already exists. Skipping template replacement." + exit 0 +else + cp "$DIR/$TEMPLATE" "$DIR/$MANIFEST" || { echo "Failed to copy manifest template" >&2; exit 1; } + + # Replace STOREFRONT_DOMAIN value with the value from .env + sed -i '' "s|{STOREFRONT_DOMAIN}|$STOREFRONT_DOMAIN|g" "$DIR/$MANIFEST" || { echo "Failed to generate $MANIFEST from template" >&2; exit 1; } + echo "✅ Generated \"$DIR/$MANIFEST\"" +fi diff --git a/sample/scripts/prestart b/sample/scripts/prestart new file mode 100755 index 0000000..3af4983 --- /dev/null +++ b/sample/scripts/prestart @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -e + +./scripts/generate_manifest From f197b9441c2728413631b3cd55fa47d1438a40fd Mon Sep 17 00:00:00 2001 From: Mark Murray Date: Mon, 9 Dec 2024 10:13:48 +0000 Subject: [PATCH 2/3] Move manifest generation to build.gradle --- sample/android/app/build.gradle | 18 ++++++++++ .../app/src/main/AndroidManifest.template.xml | 2 +- sample/android/build.gradle | 8 +++++ sample/package.json | 2 +- sample/scripts/generate_manifest | 34 ------------------- sample/scripts/prestart | 5 --- 6 files changed, 28 insertions(+), 41 deletions(-) delete mode 100755 sample/scripts/generate_manifest delete mode 100755 sample/scripts/prestart diff --git a/sample/android/app/build.gradle b/sample/android/app/build.gradle index 3ba86a4..af6737a 100644 --- a/sample/android/app/build.gradle +++ b/sample/android/app/build.gradle @@ -146,3 +146,21 @@ apply from: file("../../node_modules/react-native-vector-icons/fonts.gradle") apply from: file("../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle" + +def properties = loadProperties() +def storefrontDomain = properties.getProperty("STOREFRONT_DOMAIN") + +if (!storefrontDomain) { + println("**** Please add a .env file with STOREFRONT_DOMAIN set *****") +} + +task generateAndroidManifestFromTemplate { + doLast { + def templateFile = file('src/main/AndroidManifest.template.xml') + def outputFile = file('src/main/AndroidManifest.xml') + def content = templateFile.getText('UTF-8').replace('{{STOREFRONT_DOMAIN}}', "$storefrontDomain") + outputFile.write(content, 'UTF-8') + } +} + +preBuild.dependsOn(generateAndroidManifestFromTemplate) diff --git a/sample/android/app/src/main/AndroidManifest.template.xml b/sample/android/app/src/main/AndroidManifest.template.xml index 7e0fab1..518b983 100644 --- a/sample/android/app/src/main/AndroidManifest.template.xml +++ b/sample/android/app/src/main/AndroidManifest.template.xml @@ -33,7 +33,7 @@ - + diff --git a/sample/android/build.gradle b/sample/android/build.gradle index 9b46843..9ace25d 100644 --- a/sample/android/build.gradle +++ b/sample/android/build.gradle @@ -20,4 +20,12 @@ buildscript { } } +def loadProperties() { + def props = new Properties() + file('../.env').withInputStream { + props.load(it) + } + return props +} + apply plugin: "com.facebook.react.rootproject" diff --git a/sample/package.json b/sample/package.json index c60d3c4..7291591 100644 --- a/sample/package.json +++ b/sample/package.json @@ -11,7 +11,7 @@ "build:ios": "sh ./scripts/build_ios", "lint": "yarn typecheck && eslint .", "ios": "react-native run-ios --simulator 'iPhone 15 Pro'", - "start": "./scripts/prestart && react-native start -- --simulator 'iPhone 15 Pro' --reset-cache", + "start": "react-native start -- --simulator 'iPhone 15 Pro' --reset-cache", "typecheck": "tsc --noEmit", "test:ios": "sh ./scripts/test_ios", "test:android": "sh ./scripts/test_android" diff --git a/sample/scripts/generate_manifest b/sample/scripts/generate_manifest deleted file mode 100755 index abd015b..0000000 --- a/sample/scripts/generate_manifest +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash - -set -e - -DIR=android/app/src/main -MANIFEST=AndroidManifest.xml -TEMPLATE=AndroidManifest.template.xml - -# Ensure env exists -if [ ! -f .env ]; then - echo "sample/.env file not found!" >&2 - exit 1 -fi - -# Read env file -source .env - -# Ensure STOREFRONT_DOMAIN is set -if [ -z "$STOREFRONT_DOMAIN" ]; then - echo "Error: STOREFRONT_DOMAIN is missing from .env" >&2 - exit 1 -fi - -# Check if manifest already exists -if [ -f "$DIR/$MANIFEST" ]; then - echo "✅ \"$MANIFEST\" already exists. Skipping template replacement." - exit 0 -else - cp "$DIR/$TEMPLATE" "$DIR/$MANIFEST" || { echo "Failed to copy manifest template" >&2; exit 1; } - - # Replace STOREFRONT_DOMAIN value with the value from .env - sed -i '' "s|{STOREFRONT_DOMAIN}|$STOREFRONT_DOMAIN|g" "$DIR/$MANIFEST" || { echo "Failed to generate $MANIFEST from template" >&2; exit 1; } - echo "✅ Generated \"$DIR/$MANIFEST\"" -fi diff --git a/sample/scripts/prestart b/sample/scripts/prestart deleted file mode 100755 index 3af4983..0000000 --- a/sample/scripts/prestart +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -set -e - -./scripts/generate_manifest From 58f1b16d79726be609775155285544ec4274d4ef Mon Sep 17 00:00:00 2001 From: Mark Murray Date: Mon, 9 Dec 2024 10:26:40 +0000 Subject: [PATCH 3/3] Generate fake env for CI --- .github/workflows/ci.yml | 1 + sample/src/App.tsx | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ffb630..255c0e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,6 +87,7 @@ jobs: - name: Run Android tests run: | + echo "STOREFRONT_DOMAIN=\"myshopify.com\"" > sample/.env yarn module build yarn sample test:android --no-daemon diff --git a/sample/src/App.tsx b/sample/src/App.tsx index 5f4044c..d46819b 100644 --- a/sample/src/App.tsx +++ b/sample/src/App.tsx @@ -142,7 +142,6 @@ const useInitialURL = (): {url: string | null} => { }; }; -// This code is meant as example only. class StorefrontURL { readonly url: string;