Skip to content

Commit

Permalink
Extract CocoaPods Gutenberg logic in dedicated file
Browse files Browse the repository at this point in the history
We'll soon be modifying the Gutenberg setup. I thought it would be a
good occasion to extract that logic (make the change easy, then make the
easy change) to also achieve making the `Podfile` easier to read without
Gutenberg clutter.
  • Loading branch information
mokagio committed May 5, 2023
1 parent 22c7f92 commit 5515f8a
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 88 deletions.
95 changes: 95 additions & 0 deletions Gutenberg/cocoapods_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# frozen_string_literal: true

# Helpers and configurations for integrating Gutenberg in Jetpack and WordPress via CocoaPods.

TAG_MODE = { tag: 'v1.94.0' }.freeze
LOCAL_MODE = { path: '../../gutenberg-mobile' }.freeze
COMMIT_MODE = { commit: '' }.freeze

MODE = TAG_MODE

# 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
react-native-webview
RNSVG
react-native-slider
BVLinearGradient
react-native-get-random-values
react-native-blur
RNScreens
RNReanimated
RNGestureHandler
RNCMaskedView
RNCClipboard
RNFastImage
React-Codegen
React-bridging
].freeze

def gutenberg_pod(mode: MODE)
options = mode.dup

local_gutenberg = ENV.fetch('LOCAL_GUTENBERG', nil)
if local_gutenberg
options = { path: local_gutenberg.include?('/') ? local_gutenberg : LOCAL_MODE[:path] }
else
options[:git] = 'https://github.com/wordpress-mobile/gutenberg-mobile.git'
options[:submodules] = true
end

pod 'Gutenberg', options
pod 'RNTAztecView', options

gutenberg_dependencies(options: options)
end

def gutenberg_dependencies(options:)
if options[:path]
podspec_prefix = options[:path]
else
tag_or_commit = options[:tag] || options[:commit]
podspec_prefix = "https://raw.githubusercontent.com/wordpress-mobile/gutenberg-mobile/#{tag_or_commit}"
end

# FBReactNativeSpec needs special treatment because of react-native-codegen code generation
pod 'FBReactNativeSpec', podspec: "#{podspec_prefix}/third-party-podspecs/FBReactNativeSpec/FBReactNativeSpec.podspec.json"

DEPENDENCIES.each do |pod_name|
pod pod_name, podspec: "#{podspec_prefix}/third-party-podspecs/#{pod_name}.podspec.json"
end
end
91 changes: 4 additions & 87 deletions Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require_relative './Gutenberg/cocoapods_helper'

# For security reasons, please always keep the wordpress-mobile source first and the CDN second.
# For more info, see https://github.com/wordpress-mobile/cocoapods-specs#source-order-and-security-considerations
install! 'cocoapods', warn_for_multiple_pod_sources: false
Expand Down Expand Up @@ -77,7 +79,7 @@ end
def shared_test_pods
pod 'OHHTTPStubs/Swift', '~> 9.1.0'
pod 'OCMock', '~> 3.4.3'
gutenberg_pods
gutenberg_pod
end

def shared_with_extension_pods
Expand All @@ -90,91 +92,6 @@ def shared_style_pods
pod 'Gridicons', '~> 1.1.0'
end

def gutenberg_pods
gutenberg tag: 'v1.94.0'
end

def gutenberg(options)
options[:git] = 'https://github.com/wordpress-mobile/gutenberg-mobile.git'
options[:submodules] = true
local_gutenberg = ENV.fetch('LOCAL_GUTENBERG', nil)
if local_gutenberg
options = { path: local_gutenberg.include?('/') ? local_gutenberg : '../gutenberg-mobile' }
end
pod 'Gutenberg', options
pod 'RNTAztecView', options

gutenberg_dependencies options
end

def gutenberg_dependencies(options)
# 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
react-native-webview
RNSVG
react-native-slider
BVLinearGradient
react-native-get-random-values
react-native-blur
RNScreens
RNReanimated
RNGestureHandler
RNCMaskedView
RNCClipboard
RNFastImage
React-Codegen
React-bridging
]
if options[:path]
podspec_prefix = options[:path]
else
tag_or_commit = options[:tag] || options[:commit]
podspec_prefix = "https://raw.githubusercontent.com/wordpress-mobile/gutenberg-mobile/#{tag_or_commit}"
end

# FBReactNativeSpec needs special treatment because of react-native-codegen code generation
pod 'FBReactNativeSpec', podspec: "#{podspec_prefix}/third-party-podspecs/FBReactNativeSpec/FBReactNativeSpec.podspec.json"

dependencies.each do |pod_name|
pod pod_name, podspec: "#{podspec_prefix}/third-party-podspecs/#{pod_name}.podspec.json"
end
end

abstract_target 'Apps' do
project 'WordPress/WordPress.xcodeproj'

Expand All @@ -185,7 +102,7 @@ abstract_target 'Apps' do
## Gutenberg (React Native)
## =====================
##
gutenberg_pods
gutenberg_pod

## Third party libraries
## =====================
Expand Down
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,6 @@ SPEC CHECKSUMS:
ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba
ZIPFoundation: ae5b4b813d216d3bf0a148773267fff14bd51d37

PODFILE CHECKSUM: ab88bd849ac377484fd7f0c4b079701ce16de5a3
PODFILE CHECKSUM: 2c6431b034e07dc4772d2e3d30c413d965c41eac

COCOAPODS: 1.11.3

0 comments on commit 5515f8a

Please sign in to comment.