From 1c073b7b38b8cdbfbc3bbb76fa1134f372503315 Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Thu, 19 Mar 2020 18:42:09 +0100 Subject: [PATCH] iOS: Install resources from app manifest (#22) --- example/Example-dev.podspec | 20 -------------------- example/Podfile | 4 ---- example/Podfile.lock | 13 ++++++------- example/app.json | 6 +++++- test_app.rb | 30 ++++++++++++++++++++++++++++++ 5 files changed, 41 insertions(+), 32 deletions(-) delete mode 100644 example/Example-dev.podspec diff --git a/example/Example-dev.podspec b/example/Example-dev.podspec deleted file mode 100644 index e9f6b800..00000000 --- a/example/Example-dev.podspec +++ /dev/null @@ -1,20 +0,0 @@ -require 'json' - -package = JSON.parse(File.read(File.join('..', 'package.json'))) - -Pod::Spec.new do |s| - s.name = 'Example-dev' - s.version = package['version'] - s.author = { package['author']['name'] => package['author']['email'] } - s.license = package['license'] - s.homepage = package['homepage'] - s.source = { :git => package['repository']['url'] } - s.summary = 'Assets for Example app' - - s.ios.deployment_target = '12.0' - - s.dependency 'React' - - s.resources = ['dist/assets', 'dist/main.jsbundle'] - s.preserve_paths = 'dist/*' -end diff --git a/example/Podfile b/example/Podfile index d3436f6b..ee724727 100644 --- a/example/Podfile +++ b/example/Podfile @@ -3,10 +3,6 @@ require_relative 'node_modules/react-native-test-app/test_app.rb' workspace 'Example.xcworkspace' use_test_app!(__dir__) do |target| - target.app do - pod 'Example-dev', :path => '.' - end - target.tests do pod 'Example-Tests', :path => '.' end diff --git a/example/Podfile.lock b/example/Podfile.lock index b15a66af..470b6dc2 100644 --- a/example/Podfile.lock +++ b/example/Podfile.lock @@ -1,8 +1,6 @@ PODS: - boost-for-react-native (1.63.0) - DoubleConversion (1.1.6) - - Example-dev (0.0.4): - - React - Example-Tests (0.0.4): - React - Folly (2018.10.22.00): @@ -85,12 +83,12 @@ PODS: - React-RCTWebSocket (0.60.6): - React-Core (= 0.60.6) - ReactTestApp-DevSupport (0.0.4) + - ReactTestApp-Resources (1.0.0-dev) - SwiftLint (0.39.1) - yoga (0.60.6.React) DEPENDENCIES: - DoubleConversion (from `node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`) - - Example-dev (from `.`) - Example-Tests (from `.`) - Folly (from `node_modules/react-native/third-party-podspecs/Folly.podspec`) - glog (from `node_modules/react-native/third-party-podspecs/glog.podspec`) @@ -113,6 +111,7 @@ DEPENDENCIES: - React-RCTVibration (from `node_modules/react-native/Libraries/Vibration`) - React-RCTWebSocket (from `node_modules/react-native/Libraries/WebSocket`) - ReactTestApp-DevSupport (from `./..`) + - ReactTestApp-Resources (from `.`) - SwiftLint - yoga (from `node_modules/react-native/ReactCommon/yoga`) @@ -125,8 +124,6 @@ SPEC REPOS: EXTERNAL SOURCES: DoubleConversion: :podspec: node_modules/react-native/third-party-podspecs/DoubleConversion.podspec - Example-dev: - :path: "." Example-Tests: :path: "." Folly: @@ -169,13 +166,14 @@ EXTERNAL SOURCES: :path: node_modules/react-native/Libraries/WebSocket ReactTestApp-DevSupport: :path: "./.." + ReactTestApp-Resources: + :path: "." yoga: :path: node_modules/react-native/ReactCommon/yoga SPEC CHECKSUMS: boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c DoubleConversion: 5805e889d232975c086db112ece9ed034df7a0b2 - Example-dev: 671a30b61ca00c75363c12b33c3e02a76f0ce7cc Example-Tests: 25caeb33c2a613595303e520bb87825315f2cad1 Folly: 30e7936e1c45c08d884aa59369ed951a8e68cf51 glog: 1f3da668190260b06b429bb211bfbee5cd790c28 @@ -198,9 +196,10 @@ SPEC CHECKSUMS: React-RCTVibration: 7655d72dfb919dd6d8e135ca108a5a2bd9fcd7b4 React-RCTWebSocket: 7cd2c8d0f8ddd680dc76404defba7ab1f56b83af ReactTestApp-DevSupport: 92a89c66c797f342e631955e4f3c67e0ae1d2690 + ReactTestApp-Resources: 18abf3923397be7cd4eb2e247e954dcbf5b687e6 SwiftLint: 55e96a4a4d537d4a3156859fc1c54bd24851a046 yoga: 5079887aa3e4c62142d6bcee493022643ee4d730 -PODFILE CHECKSUM: 85a755427665fbfcea1470614e0c2fc5f1d45553 +PODFILE CHECKSUM: 0aa832921b7f3f2eb406b9c1dd66a2089b899e07 COCOAPODS: 1.8.4 diff --git a/example/app.json b/example/app.json index 12b65cd5..3e5daf12 100644 --- a/example/app.json +++ b/example/app.json @@ -5,5 +5,9 @@ "Example": { "displayName": "App" } - } + }, + "resources": [ + "dist/assets", + "dist/main.jsbundle" + ] } diff --git a/test_app.rb b/test_app.rb index 3beeffed..212a5fc9 100644 --- a/test_app.rb +++ b/test_app.rb @@ -15,6 +15,32 @@ def resolve_module(request) Pod::Executable.execute_command('node', ['-e', script], true).strip end +def resources_pod(package_root, current_dir = package_root) + return if File.expand_path(current_dir) == '/' + + app_manifest = File.join(current_dir, 'app.json') + return resources_pod(package_root, File.join(current_dir, '..')) if !File.exist?(app_manifest) + + resources = JSON.parse(File.read(app_manifest))['resources'] + return if !resources.instance_of? Array or resources.empty? + + spec = { + 'name' => 'ReactTestApp-Resources', + 'version' => '1.0.0-dev', + 'summary' => 'Resources for ReactTestApp', + 'homepage' => 'https://github.com/microsoft/react-native-test-app', + 'license' => 'Unlicense', + 'authors' => '@microsoft/react-native-test-app', + 'source' => { 'git' => 'https://github.com/microsoft/react-native-test-app.git' }, + 'resources' => resources + } + + podspec_path = File.join(current_dir, 'ReactTestApp-Resources.podspec.json') + File.write(podspec_path, spec.to_json()) + at_exit { File.delete(podspec_path) } + Pathname.new(current_dir).relative_path_from(package_root).to_s() +end + def use_test_app!(package_root) platform :ios, '12.0' @@ -82,6 +108,10 @@ def use_test_app!(package_root) pod 'glog', :podspec => "#{react_native}/third-party-podspecs/glog.podspec" pod 'Folly', :podspec => "#{react_native}/third-party-podspecs/Folly.podspec" + if resources_pod_path = resources_pod(package_root) + pod 'ReactTestApp-Resources', :path => resources_pod_path + end + yield ReactTestAppTargets.new(self) if block_given? use_native_modules! '.'