react_native_util 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11ea13b794e259fd108a7ee0bde1fea6fdd26f1d2a2b8caf407eb4f3f84bad10
4
- data.tar.gz: 8d1b5bab6d808249ae166ccda1db6022f7733b9e62843099a070be54b13d008a
3
+ metadata.gz: bac5388f9ceda5e72b4a54c717f742c5a56c07f0a7b7489a9cac567469cfe728
4
+ data.tar.gz: aea447d8cf31bb2d9feb5b4eb42ec8d869071ced5036f722049fabd38f17b00b
5
5
  SHA512:
6
- metadata.gz: '0369e513d78c6a581fd53c5e95e7ce9f066f7d161371917442b548bb474c0ae7996622dec6ca92bc93b436ee075d01c7302fa8504e7deed8149f9ca1c5fc576a'
7
- data.tar.gz: 5775dbf8bf502d8d611f62106fb8289fbb5701ea266e365a924e5a4675d19dc5beed0a2d8ebf1bee889657a1dcf6a5b3d94b8dc74f16ab809f114cac4c6c69d8
6
+ metadata.gz: e3f3375ad84f084472f36eeac3ae9a6ce2a0fda11a88bb32055a45940c7c39919daea4c5056b75650c130e509f964751e3ae70aeac0b445ef886eefad8f6fc1f
7
+ data.tar.gz: 89fcadbf7b2e9db331dd7bab9e3d066a1e06b4c2bd9117560ba79b58c5b871a1a658bf6bbe7bcd5ff6f3d60330d23202e71a79d94b78caa76a8491334aef9179
data/README.md CHANGED
@@ -46,53 +46,72 @@ rn react_pod -h
46
46
 
47
47
  ## Try it out
48
48
 
49
- First set up a test app:
50
- ```bash
51
- react-native init TestApp
52
- cd TestApp
53
- yarn add react-native-webview
54
- react-native link react-native-webview
55
- git init .
56
- git add .
57
- git commit -m'Before conversion'
58
- ```
49
+ Convert examples/TestApp using Rake.
59
50
 
60
- Now do the conversion:
61
51
  ```bash
62
- rn react_pod
52
+ bundle check || bundle install
53
+ bundle exec rake react_pod
63
54
  git status
64
55
  ```
65
56
 
66
57
  _Typical command output:_
67
58
  ```
68
- 2019-05-11T12:25:14-07:00 react_native_util react_pod v0.2.0
69
- 2019-05-11T12:25:14-07:00 Installed from Homebrew
70
- 2019-05-11T12:25:14-07:00 Darwin 18.5.0 x86_64
71
- 2019-05-11T12:25:14-07:00 Ruby 2.3.7: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
72
- 2019-05-11T12:25:14-07:00 RubyGems 2.6.14: /usr/bin/gem
73
- 2019-05-11T12:25:14-07:00 react-native-cli: /usr/local/bin/react-native
74
- 2019-05-11T12:25:14-07:00 react-native-cli: 2.0.1
75
- 2019-05-11T12:25:14-07:00 react-native: 0.59.8
76
- 2019-05-11T12:25:14-07:00 yarn 1.16.0: /usr/local/bin/yarn
77
- 2019-05-11T12:25:15-07:00 cocoapods 1.6.1: /usr/local/bin/pod
78
- 2019-05-11T12:25:15-07:00 cocoapods-core: 1.6.1
79
- 2019-05-11T12:25:15-07:00 package.json:
80
- 2019-05-11T12:25:15-07:00 app name: "TestApp"
81
- 2019-05-11T12:25:15-07:00 Found Xcode project at ~/sandbox/TestApp/ios/TestApp.xcodeproj
82
- 2019-05-11T12:25:15-07:00 Installing NPM dependencies with yarn
83
- [✔] yarn success in 0.8 s
84
- 2019-05-11T12:25:16-07:00 Dependencies:
85
- 2019-05-11T12:25:16-07:00 react-native-webview
86
- 2019-05-11T12:25:16-07:00 Unlinking dependencies
87
- [✔] react-native unlink react-native-webview success in 0.6 s
88
- 2019-05-11T12:25:17-07:00 Removing Libraries from TestApp
89
- 2019-05-11T12:25:17-07:00 Removing Libraries from TestAppTests
90
- 2019-05-11T12:25:17-07:00 Removing Libraries group
91
- 2019-05-11T12:25:17-07:00 Generating ios/Podfile
92
- 2019-05-11T12:25:17-07:00 Linking dependencies
93
- [✔] react-native link react-native-webview success in 0.6 s
94
- 2019-05-11T12:25:17-07:00 Generating Pods project and ios/TestApp.xcworkspace
95
- [✔] pod install success in 10.5 s
96
- 2019-05-11T12:25:28-07:00 Conversion complete
97
- 2019-05-11T12:25:28-07:00 $ open ios/TestApp.xcworkspace
59
+ 2019-05-12T11:42:03-07:00 react_native_util react_pod v0.2.2
60
+ [✔] yarn install success in 10.9 s
61
+ 2019-05-12T11:42:14-07:00 Darwin 18.5.0 x86_64
62
+ 2019-05-12T11:42:14-07:00 Ruby 2.6.3: ~/.rvm/rubies/ruby-2.6.3/bin/ruby
63
+ 2019-05-12T11:42:14-07:00 RubyGems 3.0.3: ~/.rvm/rubies/ruby-2.6.3/bin/gem
64
+ 2019-05-12T11:42:14-07:00 Bundler 1.17.2: ~/.rvm/gems/ruby-2.6.3/bin/bundle
65
+ 2019-05-12T11:42:14-07:00 react-native-cli: /usr/local/bin/react-native
66
+ 2019-05-12T11:42:14-07:00 react-native-cli: 2.0.1
67
+ 2019-05-12T11:42:14-07:00 react-native: 0.59.8
68
+ 2019-05-12T11:42:15-07:00 yarn 1.16.0: /usr/local/bin/yarn
69
+ 2019-05-12T11:42:15-07:00 cocoapods 1.6.1: ~/.rvm/gems/ruby-2.6.3/bin/pod
70
+ 2019-05-12T11:42:15-07:00 cocoapods-core: 1.6.1
71
+ 2019-05-12T11:42:15-07:00 package.json:
72
+ 2019-05-12T11:42:15-07:00 app name: "TestApp"
73
+ 2019-05-12T11:42:15-07:00 Found Xcode project at ~/github/jdee/react_native_util/examples/TestApp/ios/TestApp.xcodeproj
74
+ 2019-05-12T11:42:15-07:00 Dependencies:
75
+ 2019-05-12T11:42:15-07:00 react-native-webview
76
+ 2019-05-12T11:42:15-07:00 Unlinking dependencies
77
+ [✔] react-native unlink react-native-webview success in 0.7 s
78
+ 2019-05-12T11:42:16-07:00 Removing Libraries from TestApp
79
+ 2019-05-12T11:42:16-07:00 Removing Libraries from TestAppTests
80
+ 2019-05-12T11:42:16-07:00 Removing Libraries group
81
+ 2019-05-12T11:42:16-07:00 Generating ios/Podfile
82
+ 2019-05-12T11:42:16-07:00 Linking dependencies
83
+ [✔] react-native link react-native-webview success in 0.5 s
84
+ 2019-05-12T11:42:17-07:00 Generating Pods project and ios/TestApp.xcworkspace
85
+ [✔] pod install success in 8.2 s
86
+ 2019-05-12T11:42:25-07:00 Conversion complete
87
+ 2019-05-12T11:42:25-07:00 $ open ios/TestApp.xcworkspace
88
+ ```
89
+
90
+ ## Rake task
91
+
92
+ Add to Rakefile:
93
+ ```Ruby
94
+ require 'react_native_util/rake/react_pod_task'
95
+ ReactNativeUtil::Rake::ReactPodTask.new
96
+ ```
97
+
98
+ Customize:
99
+ ```Ruby
100
+ require 'react_native_util/rake/react_pod_task'
101
+ ReactNativeUtil::Rake::ReactPodTask.new(
102
+ :react_pod, # task name
103
+ 'Convert project to use React pod', # description
104
+ chdir: '/path/to/rn/project', # path to project package.json
105
+ repo_update: true # optionally disable pod repo update
106
+ )
107
+ ```
108
+
109
+ ## Ruby script
110
+
111
+ ```Ruby
112
+ require 'react_native_util/converter'
113
+
114
+ Dir.chdir '/path/to/rn/project' do
115
+ ReactNativeUtil::Converter.new(repo_update: true).convert_to_react_pod!
116
+ end
98
117
  ```
@@ -1,6 +1,4 @@
1
- require 'cocoapods-core'
2
1
  require 'commander'
3
- require 'rubygems'
4
2
  require_relative 'converter'
5
3
  require_relative 'metadata'
6
4
 
@@ -24,7 +22,6 @@ module ReactNativeUtil
24
22
 
25
23
  c.action do |_args, opts|
26
24
  begin
27
- report_configuration
28
25
  converter = Converter.new repo_update: opts.repo_update
29
26
  converter.convert_to_react_pod!
30
27
  exit 0
@@ -41,47 +38,5 @@ module ReactNativeUtil
41
38
 
42
39
  run!
43
40
  end
44
-
45
- def report_configuration
46
- log "#{NAME} react_pod v#{VERSION}".bold
47
-
48
- log ' Installed from Homebrew' if ENV['REACT_NATIVE_UTIL_INSTALLED_FROM_HOMEBREW']
49
-
50
- log " #{`uname -msr`}"
51
-
52
- log " Ruby #{RUBY_VERSION}: #{RbConfig.ruby}"
53
- log " RubyGems #{Gem::VERSION}: #{`which gem`}"
54
- log " Bundler #{Bundler::VERSION}: #{`which bundle`}" if defined?(Bundler)
55
-
56
- log_command_path 'react-native', 'react-native-cli', include_version: false
57
- unless `which react-native`.empty?
58
- react_native_info = `react-native --version`
59
- react_native_info.split("\n").each { |l| log " #{l}" }
60
- end
61
-
62
- log_command_path 'yarn'
63
- log_command_path 'pod', 'cocoapods'
64
-
65
- log " cocoapods-core: #{Pod::CORE_VERSION}"
66
- rescue Errno::ENOENT
67
- # On Windows, e.g., which and uname may not work.
68
- log 'Conversion failed: macOS required.'.red.bold
69
- exit(-1)
70
- end
71
-
72
- def log_command_path(command, package = command, include_version: true)
73
- path = `which #{command}`
74
- if path.empty?
75
- log " #{package}: #{'not found'.red.bold}"
76
- return
77
- end
78
-
79
- if include_version
80
- version = `#{command} --version`.chomp
81
- log " #{package} #{version}: #{path}"
82
- else
83
- log " #{package}: #{path}"
84
- end
85
- end
86
41
  end
87
42
  end
@@ -1,5 +1,7 @@
1
+ require 'cocoapods-core'
1
2
  require 'erb'
2
3
  require 'json'
4
+ require 'rubygems'
3
5
  require 'tmpdir'
4
6
  require 'tty/platform'
5
7
  require 'xcodeproj'
@@ -57,11 +59,13 @@ module ReactNativeUtil
57
59
  # Convert project to use React pod
58
60
  # @raise ConversionError on failure
59
61
  def convert_to_react_pod!
60
- raise ConversionError, "macOS required." unless mac?
61
-
62
62
  # Make sure no uncommitted changes
63
63
  check_repo_status!
64
64
 
65
+ report_configuration!
66
+
67
+ raise ConversionError, "macOS required." unless mac?
68
+
65
69
  load_package_json!
66
70
  log 'package.json:'
67
71
  log " app name: #{app_name.inspect}"
@@ -83,10 +87,6 @@ module ReactNativeUtil
83
87
  exit 1
84
88
  end
85
89
 
86
- # Don't run yarn until we're sure we're proceeding.
87
- log 'Installing NPM dependencies with yarn'
88
- run_command_with_spinner! 'yarn', log: File.join(Dir.tmpdir, 'yarn.log')
89
-
90
90
  load_react_podspec!
91
91
 
92
92
  # 2. Detect native dependencies in Libraries group.
@@ -150,6 +150,60 @@ module ReactNativeUtil
150
150
  raise ConversionError, "Failed to parse package.json: #{e.message}"
151
151
  end
152
152
 
153
+ def install_npm_deps_if_needed!
154
+ raise ConversionError, 'package.json not found. Please run from the project root.' unless File.readable?('package.json')
155
+
156
+ execute 'yarn', 'check', '--integrity', log: nil, output: :close
157
+ execute 'yarn', 'check', '--verify-tree', log: nil, output: :close
158
+ rescue ExecutionError
159
+ # install deps if either check fails
160
+ run_command_with_spinner! 'yarn', 'install', log: File.join(Dir.tmpdir, 'yarn.log')
161
+ end
162
+
163
+ def report_configuration!
164
+ log "#{NAME} react_pod v#{VERSION}".bold
165
+
166
+ install_npm_deps_if_needed!
167
+
168
+ log ' Installed from Homebrew' if ENV['REACT_NATIVE_UTIL_INSTALLED_FROM_HOMEBREW']
169
+
170
+ log " #{`uname -msr`}"
171
+
172
+ log " Ruby #{RUBY_VERSION}: #{RbConfig.ruby}"
173
+ log " RubyGems #{Gem::VERSION}: #{`which gem`}"
174
+ log " Bundler #{Bundler::VERSION}: #{`which bundle`}" if defined?(Bundler)
175
+
176
+ log_command_path 'react-native', 'react-native-cli', include_version: false
177
+ unless `which react-native`.empty?
178
+ react_native_info = `react-native --version`
179
+ react_native_info.split("\n").each { |l| log " #{l}" }
180
+ end
181
+
182
+ log_command_path 'yarn'
183
+ log_command_path 'pod', 'cocoapods'
184
+
185
+ log " cocoapods-core: #{Pod::CORE_VERSION}"
186
+ rescue Errno::ENOENT
187
+ # On Windows, e.g., which and uname may not work.
188
+ log 'Conversion failed: macOS required.'.red.bold
189
+ exit(-1)
190
+ end
191
+
192
+ def log_command_path(command, package = command, include_version: true)
193
+ path = `which #{command}`
194
+ if path.empty?
195
+ log " #{package}: #{'not found'.red.bold}"
196
+ return
197
+ end
198
+
199
+ if include_version
200
+ version = `#{command} --version`.chomp
201
+ log " #{package} #{version}: #{path}"
202
+ else
203
+ log " #{package}: #{path}"
204
+ end
205
+ end
206
+
153
207
  # Load the project at @xcodeproj_path into @xcodeproj
154
208
  # @raise ConversionError on failure
155
209
  def load_xcodeproj!
@@ -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.2.1'
4
+ VERSION = '0.2.2'
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.'
@@ -0,0 +1,27 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+ require_relative '../converter'
4
+
5
+ module ReactNativeUtil
6
+ module Rake
7
+ # Rakefile:
8
+ # require 'react_native_util/rake/react_pod_task'
9
+ # ReactNativeUtil::Rake::ReactPodTask.new chdir: '/path/to/rn/app'
10
+ class ReactPodTask < ::Rake::TaskLib
11
+ include Util
12
+ def initialize(
13
+ name = :react_pod,
14
+ description = 'Convert project to use React pod',
15
+ chdir: '.',
16
+ repo_update: boolean_env_var?(:REACT_NATIVE_UTIL_REPO_UPDATE)
17
+ )
18
+ desc description
19
+ task name do
20
+ Dir.chdir chdir do
21
+ Converter.new(repo_update: repo_update).convert_to_react_pod!
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react_native_util
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Dee
@@ -229,6 +229,7 @@ files:
229
229
  - lib/react_native_util/core_ext/string.rb
230
230
  - lib/react_native_util/exceptions.rb
231
231
  - lib/react_native_util/metadata.rb
232
+ - lib/react_native_util/rake/react_pod_task.rb
232
233
  - lib/react_native_util/util.rb
233
234
  homepage: https://github.com/jdee/react_native_util
234
235
  licenses: