react_native_util 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58961157dd9ea8d01ec449637c1176395346c7642fe46d0fc28b47a957fde4ea
4
- data.tar.gz: 6a20fb2a70fa264e561f2b69314e8b4a2d88c48144583919010cf5b321234b75
3
+ metadata.gz: 44ea8dd51fe614a4e2783d13f25c4d9b3a07fe363817b0beae8e625419c5bfa2
4
+ data.tar.gz: 9cda19321bfb85e2ef98a45ec0c0837d72f54da09e4e9a85d094a1d6a6d19a4e
5
5
  SHA512:
6
- metadata.gz: 3f6c62f22d58fe55fccb9b763b5bc0dbfa369ab52af53fcb65d3688c7e4a4b858481aeb1b7fcca25ea16e72d49fdeacdc520fba005fb8229dd800b88017c6e31
7
- data.tar.gz: 92b345621ac4e5d59eef6cb454cb4b3343965942ed353a1b3a1da6e04754e2b9c4fc5ab8a1399b8c6268eecc0dc38b71d1bc415a88001fc2abb812b77aa6f4f4
6
+ metadata.gz: 37d07a4d245c1eba1d5a359b254aee5f7c62c69b3c19884d3481d4c8546e1c34f293e89c68248ae91b087ce2c2ac74c0e136ebedbdb25cf4e43ed7a1843310bb
7
+ data.tar.gz: 165f4085612334cb8d1d89c1be685ededdac5f64ba176933d420b38a4ffe9a8475aaec18e690e2b3fdd2c2c201ea681de0dd640aac621a276c16276fa62cfe64
data/README.md CHANGED
@@ -14,7 +14,7 @@ Community utility CLI for React Native projects.
14
14
  _macOS required_
15
15
 
16
16
  ```bash
17
- brew install yarn
17
+ brew install yarn # Not necessary if installing from Homebrew tap
18
18
  npm install -g react-native-cli
19
19
  ```
20
20
 
@@ -27,8 +27,7 @@ npm install -g react-native-cli
27
27
  ## Install from Homebrew tap
28
28
 
29
29
  ```bash
30
- brew tap jdee/tap
31
- brew install react_native_util
30
+ brew install jdee/tap/react_native_util
32
31
  ```
33
32
 
34
33
  ## Gemfile
@@ -7,17 +7,7 @@ target '<%= app_name %>' do
7
7
  Core
8
8
  CxxBridge
9
9
  DevSupport
10
- RCTActionSheet
11
- RCTAnimation
12
- RCTBlob
13
- RCTGeolocation
14
- RCTImage
15
- RCTLinkingIOS
16
- RCTNetwork
17
- RCTSettings
18
- RCTText
19
- RCTVibration
20
- RCTWebSocket
10
+ <%= @subspecs_from_libraries.join("\n ") %>
21
11
  ]
22
12
  pod 'yoga', path: '../node_modules/react-native/ReactCommon/yoga'
23
13
  pod 'Folly', podspec: '../node_modules/react-native/third-party-podspecs/Folly.podspec'
@@ -9,17 +9,21 @@ module ReactNativeUtil
9
9
  class Converter
10
10
  include Util
11
11
 
12
- # [Array<String>] Default contents of Libraries group
12
+ # [Array<String>] Xcode projects from react-native that may be in the Libraries group
13
13
  DEFAULT_DEPENDENCIES = %w[
14
- RCTAnimation
14
+ ART
15
15
  React
16
16
  RCTActionSheet
17
+ RCTAnimation
17
18
  RCTBlob
19
+ RCTCameraRoll
18
20
  RCTGeolocation
19
21
  RCTImage
20
22
  RCTLinking
21
23
  RCTNetwork
24
+ RCTPushNotification
22
25
  RCTSettings
26
+ RCTTest
23
27
  RCTText
24
28
  RCTVibration
25
29
  RCTWebSocket
@@ -38,6 +42,7 @@ module ReactNativeUtil
38
42
  attr_reader :xcodeproj
39
43
 
40
44
  attr_reader :options
45
+ attr_reader :react_podspec
41
46
 
42
47
  def initialize(repo_update: nil)
43
48
  @options = {}
@@ -60,11 +65,8 @@ module ReactNativeUtil
60
65
  log 'package.json:'
61
66
  log " app name: #{app_name.inspect}"
62
67
 
63
- log 'Installing NPM dependencies with yarn'
64
- execute 'yarn'
65
-
66
68
  # 1. Detect project. TODO: Add an option to override.
67
- @xcodeproj_path = File.expand_path "ios/#{package_json['name']}.xcodeproj"
69
+ @xcodeproj_path = File.expand_path "ios/#{app_name}.xcodeproj"
68
70
  load_xcodeproj!
69
71
  log "Found Xcode project at #{xcodeproj_path}"
70
72
 
@@ -73,6 +75,13 @@ module ReactNativeUtil
73
75
  exit 0
74
76
  end
75
77
 
78
+ # Don't run yarn until we're sure we're proceeding,
79
+ log 'Installing NPM dependencies with yarn'
80
+ execute 'yarn'
81
+
82
+ # Unused, but should be there and parseable
83
+ load_react_podspec!
84
+
76
85
  # 2. Detect native dependencies in Libraries group.
77
86
  log 'Dependencies:'
78
87
  dependencies.each { |d| log " #{d}" }
@@ -88,17 +97,19 @@ module ReactNativeUtil
88
97
  # reload after react-native unlink
89
98
  load_xcodeproj!
90
99
 
91
- # 4a. TODO: Add Start Packager script
100
+ # 4a. Add Start Packager script
92
101
  validate_app_target!
93
102
  add_packager_script
94
103
 
104
+ # Make a note of pod subspecs to replace Libraries group
105
+ load_subspecs_from_libraries
106
+
95
107
  # 4b. Remove Libraries group from Xcode project.
96
108
  remove_libraries_group_from_project!
97
109
 
98
110
  xcodeproj.save
99
111
 
100
112
  # 5. Generate boilerplate Podfile.
101
- # TODO: Determine appropriate subspecs from contents of Libraries group
102
113
  generate_podfile!
103
114
 
104
115
  # 6. Run react-native link for each dependency.
@@ -138,6 +149,17 @@ module ReactNativeUtil
138
149
  raise ConversionError, "Failed to load #{xcodeproj_path}: #{e.message}"
139
150
  end
140
151
 
152
+ def load_react_podspec!
153
+ podspec_dir = 'node_modules/react-native'
154
+ podspec_contents = File.read "#{podspec_dir}/React.podspec"
155
+ podspec_contents.gsub!(/__dir__/, podspec_dir.inspect)
156
+
157
+ require 'cocoapods-core'
158
+ # rubocop: disable Security/Eval
159
+ @react_podspec = eval(podspec_contents)
160
+ # rubocop: enable Security/Eval
161
+ end
162
+
141
163
  # A representation of the Libraries group (if any) from the Xcode project.
142
164
  # @return the Libraries group
143
165
  def libraries_group
@@ -189,12 +211,27 @@ module ReactNativeUtil
189
211
  paths.map { |p| File.expand_path p, File.join(Dir.pwd, 'ios') }
190
212
  end
191
213
 
214
+ def library_roots
215
+ libraries_group.children.map do |library|
216
+ File.basename(library.path).sub(/\.xcodeproj$/, '')
217
+ end
218
+ end
219
+
192
220
  # All static libraries from the Libraries group
193
221
  # @return [Array<String>] an array of filenames
194
222
  def static_libs
195
- libraries_group.children.map do |library|
196
- root = File.basename(library.path).sub(/\.xcodeproj$/, '')
197
- "lib#{root}.a"
223
+ library_roots.map { |root| "lib#{root}.a" }
224
+ end
225
+
226
+ def load_subspecs_from_libraries
227
+ roots = library_roots - %w[React]
228
+ @subspecs_from_libraries = roots.select { |r| DEFAULT_DEPENDENCIES.include?(r) }.map do |root|
229
+ case root
230
+ when 'RCTLinking'
231
+ 'RCTLinkingIOS'
232
+ else
233
+ root
234
+ end
198
235
  end
199
236
  end
200
237
 
@@ -242,17 +279,38 @@ module ReactNativeUtil
242
279
  raise ConversionError, 'Uncommitted changes in repo. Please commit or stash before continuing.'
243
280
  end
244
281
 
282
+ # Adds the Start Packager script from the React.xcodeproj under node_modules
283
+ # to the main application target before deleting React.xcodeproj from the
284
+ # Libraries group. Adjusts paths in the script to account for the different
285
+ # project location. If React.xcodeproj cannot be opened, or if the relevant
286
+ # build phase is not found, a warning is logged, and this step is skipped.
287
+ #
288
+ # TODO: The build phase is added after all other build phases. Ideally it
289
+ # can be moved to the beginning. The packager is independent of the Xcode
290
+ # build process. It may be started at any time. Starting it early is an
291
+ # optimization that allows it to load while the build is in progress.
292
+ # Currently it's possible to simply drag the build phase in Xcode to a
293
+ # higher position after running the react_pod command.
245
294
  def add_packager_script
246
- script = packager_script
247
- return unless script
295
+ old_packager_phase = packager_phase_from_react_project
296
+ unless old_packager_phase
297
+ log 'Could not find packager build phase in React.xcodeproj. Skipping.'.yellow
298
+ return
299
+ end
248
300
 
301
+ # location of project is different relative to packager script
302
+ script = old_packager_phase.shell_script.gsub(%r{../scripts}, '../node_modules/react-native/scripts')
303
+
304
+ # target can't be nil. Already validated earlier by #validate_app_target!
249
305
  target = xcodeproj.targets.find { |t| t.name == app_name }
250
- phase = target.new_shell_script_build_phase 'Start Packager'
306
+ phase = target.new_shell_script_build_phase old_packager_phase.name
251
307
  phase.shell_script = script
252
-
253
- # TODO: Move this build phase to the top of the list before the pod install.
254
308
  end
255
309
 
310
+ # Returns a Project object with the contents of the React.xcodeproj project
311
+ # from node_modules.
312
+ # @return [Xcodeproj::Project] a Project object with the contents of React.xcodeproj from node_modules
313
+ # @raise Xcodeproj::PlainInformative in case of most failures
256
314
  def react_project!
257
315
  return @react_project if @react_project
258
316
 
@@ -260,8 +318,12 @@ module ReactNativeUtil
260
318
  @react_project = Xcodeproj::Project.open path
261
319
  end
262
320
 
263
- def packager_script
264
- react_project!.targets.first.build_phases.find { |p| p.name =~ /packager/i }.shell_script.gsub(%r{../scripts}, '../node_modules/react-native/scripts')
321
+ # Returns the original Start Packager build phase from the React.xcodeproj
322
+ # under node_modules. This contains the original script.
323
+ # @return the packager build phase if found
324
+ # @return nil if not found or React.xcodeproj cannot be opened
325
+ def packager_phase_from_react_project
326
+ react_project!.targets.first.build_phases.find { |p| p.name =~ /packager/i }
265
327
  rescue Errno::ENOENT
266
328
  log 'Could not open React.xcodeproj. File not found.'
267
329
  nil
@@ -1,7 +1,7 @@
1
1
  # Conversion tools for React Native projects
2
2
  module ReactNativeUtil
3
3
  NAME = 'react_native_util'
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  SUMMARY = 'Community utility CLI for React Native projects'
6
6
  DESCRIPTION = 'Automatically modifies a project created with react-native ' \
7
7
  'init to use the React pod from node_modules.'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react_native_util
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Dee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-10 00:00:00.000000000 Z
11
+ date: 2019-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocoapods