From f1c05f56e74432b1089749b1b3e2e958fe7442f9 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 3 Jul 2023 17:03:00 +1000 Subject: [PATCH] Update Gutenberg local setup to work with React Native 0.71.11 --- Gutenberg/cocoapods_helpers.rb | 77 +++++++++++++++++++--------------- Podfile | 2 + Podfile.lock | 2 +- 3 files changed, 46 insertions(+), 35 deletions(-) diff --git a/Gutenberg/cocoapods_helpers.rb b/Gutenberg/cocoapods_helpers.rb index 9057aa12cb88..e32333e5fb4a 100644 --- a/Gutenberg/cocoapods_helpers.rb +++ b/Gutenberg/cocoapods_helpers.rb @@ -6,40 +6,14 @@ DEFAULT_GUTENBERG_LOCATION = File.join(__dir__, '..', '..', 'gutenberg-mobile') +LOCAL_GUTENBERG_KEY = 'LOCAL_GUTENBERG' + # Note that the pods in this array might seem unused if you look for # `import` statements in this codebase. However, make sure to also check # whether they are used in the gutenberg-mobile and Gutenberg projects. # # See https://github.com/wordpress-mobile/gutenberg-mobile/issues/5025 DEPENDENCIES = %w[ - FBLazyVector - React - ReactCommon - RCTRequired - RCTTypeSafety - React-Core - React-CoreModules - React-RCTActionSheet - React-RCTAnimation - React-RCTBlob - React-RCTImage - React-RCTLinking - React-RCTNetwork - React-RCTSettings - React-RCTText - React-RCTVibration - React-callinvoker - React-cxxreact - React-jsinspector - React-jsi - React-jsiexecutor - React-logger - React-perflogger - React-runtimeexecutor - boost - Yoga - RCT-Folly - glog react-native-safe-area react-native-safe-area-context react-native-video @@ -55,21 +29,20 @@ RNCMaskedView RNCClipboard RNFastImage - React-Codegen - React-bridging + React-jsc ].freeze def gutenberg_pod(config: GUTENBERG_CONFIG) options = config - local_gutenberg_key = 'LOCAL_GUTENBERG' - local_gutenberg = ENV.fetch(local_gutenberg_key, nil) # We check local_gutenberg first because it should take precedence, being an override set by the user. - if local_gutenberg - options = { path: File.exist?(local_gutenberg) ? local_gutenberg : DEFAULT_GUTENBERG_LOCATION } + if should_use_local_gutenberg + options = { path: local_gutenberg_path } raise "Could not find Gutenberg pod at #{options[:path]}. You can configure the path using the #{local_gutenberg_key} environment variable." unless File.exist?(options[:path]) + puts "[Gutenberg] Installing pods using local Gutenberg version from #{local_gutenberg_path}" + pod 'Gutenberg', options pod 'RNTAztecView', options @@ -102,3 +75,39 @@ def gutenberg_dependencies(options:) pod pod_name, podspec: "#{podspec_prefix}/#{pod_name}.#{podspec_extension}" end end + +def gutenberg_post_install(installer:) + return unless should_use_local_gutenberg + + raise "[Gutenberg] Could not find local Gutenberg at given path #{local_gutenberg_path}" unless File.exist?(local_gutenberg_path) + + react_native_path = File.join(local_gutenberg_path, 'gutenberg', 'node_modules', 'react-native') + + raise "[Gutenberg] Could not find React Native at given path #{react_native_path}" unless File.exist?(react_native_path) + + require_relative File.join(react_native_path, 'scripts', 'react_native_pods') + + puts '[Gutenberg] Running Gunberg post install hook' + + react_native_post_install(installer, react_native_path) +end + +private + +def should_use_local_gutenberg + value = ENV.fetch(LOCAL_GUTENBERG_KEY, nil) + + return false if value.nil? + + value +end + +def local_gutenberg_path + local_gutenberg = ENV.fetch(LOCAL_GUTENBERG_KEY, nil) + + return nil if local_gutenberg.nil? + + return local_gutenberg if File.exist?(local_gutenberg) + + DEFAULT_GUTENBERG_LOCATION +end diff --git a/Podfile b/Podfile index e3bc85766801..8993bfd97bf2 100644 --- a/Podfile +++ b/Podfile @@ -340,6 +340,8 @@ pre_install do |installer| end post_install do |installer| + gutenberg_post_install(installer: installer) + project_root = File.dirname(__FILE__) ## Convert the 3rd-party license acknowledgements markdown into html for use in the app diff --git a/Podfile.lock b/Podfile.lock index e6b7cf5b02dc..344e1cbb268c 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -288,6 +288,6 @@ SPEC CHECKSUMS: ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba ZIPFoundation: ae5b4b813d216d3bf0a148773267fff14bd51d37 -PODFILE CHECKSUM: dd2923ba0655d06a0e85bdf9aa0d38304e8f087e +PODFILE CHECKSUM: e319af03b936262b0933a0c736855b627be12fe1 COCOAPODS: 1.12.1