react_native_util 0.1.3 → 0.2.0

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: 44ea8dd51fe614a4e2783d13f25c4d9b3a07fe363817b0beae8e625419c5bfa2
4
- data.tar.gz: 9cda19321bfb85e2ef98a45ec0c0837d72f54da09e4e9a85d094a1d6a6d19a4e
3
+ metadata.gz: ee275507e4938a754820b5f6f57ad9ea84c7a3776994678014466610ceed3eb8
4
+ data.tar.gz: 18b76367f8df90fd0cf53616e36f4935b88d2abc50dcb360e824517c28ec228c
5
5
  SHA512:
6
- metadata.gz: 37d07a4d245c1eba1d5a359b254aee5f7c62c69b3c19884d3481d4c8546e1c34f293e89c68248ae91b087ce2c2ac74c0e136ebedbdb25cf4e43ed7a1843310bb
7
- data.tar.gz: 165f4085612334cb8d1d89c1be685ededdac5f64ba176933d420b38a4ffe9a8475aaec18e690e2b3fdd2c2c201ea681de0dd640aac621a276c16276fa62cfe64
6
+ metadata.gz: f99663e838c47561e06e62ce2ad252461ad8e9d7ab99c3e416542bee174dd39205feb89c71cac49dfb0899dfc2e519593d99c595cee1afb73f00619e3edfb099
7
+ data.tar.gz: 498a37155945ca93d42c8de8dab9f7c77aea8eeec275b84e7e7bb1f92acc2bf980b0d4a34cdfb2a059a794c6b4820ec56e7f9d36b41e4de0e3b30640ee772ec2
data/README.md CHANGED
@@ -62,3 +62,37 @@ Now do the conversion:
62
62
  rn react_pod
63
63
  git status
64
64
  ```
65
+
66
+ _Typical command output:_
67
+ ```
68
+ 2019-05-11T12:06:17-07:00 react_native_util react_pod v0.2.0
69
+ 2019-05-11T12:06:17-07:00 Darwin 18.5.0 x86_64
70
+ 2019-05-11T12:06:17-07:00 Ruby 2.6.3: ~/.rvm/rubies/ruby-2.6.3/bin/ruby
71
+ 2019-05-11T12:06:17-07:00 RubyGems 3.0.3: ~/.rvm/rubies/ruby-2.6.3/bin/gem
72
+ 2019-05-11T12:06:17-07:00 Bundler 2.0.1: ~/.rvm/gems/ruby-2.6.3/bin/bundle
73
+ 2019-05-11T12:06:17-07:00 react-native-cli: /usr/local/bin/react-native
74
+ 2019-05-11T12:06:17-07:00 react-native-cli: 2.0.1
75
+ 2019-05-11T12:06:17-07:00 react-native: 0.59.8
76
+ 2019-05-11T12:06:18-07:00 yarn 1.16.0: /usr/local/bin/yarn
77
+ 2019-05-11T12:06:18-07:00 cocoapods 1.6.1: ~/.rvm/gems/ruby-2.6.3/bin/pod
78
+ 2019-05-11T12:06:18-07:00 cocoapods-core: 1.6.1
79
+ 2019-05-11T12:06:18-07:00 package.json:
80
+ 2019-05-11T12:06:18-07:00 app name: "TestApp"
81
+ 2019-05-11T12:06:18-07:00 Found Xcode project at ~/sandbox/TestApp/ios/TestApp.xcodeproj
82
+ 2019-05-11T12:06:18-07:00 Installing NPM dependencies with yarn
83
+ [✔] yarn success in 0.8 s
84
+ 2019-05-11T12:06:19-07:00 Dependencies:
85
+ 2019-05-11T12:06:19-07:00 react-native-webview
86
+ 2019-05-11T12:06:19-07:00 Unlinking dependencies
87
+ [✔] react-native unlink react-native-webview success in 0.5 s
88
+ 2019-05-11T12:06:20-07:00 Removing Libraries from TestApp
89
+ 2019-05-11T12:06:20-07:00 Removing Libraries from TestAppTests
90
+ 2019-05-11T12:06:20-07:00 Removing Libraries group
91
+ 2019-05-11T12:06:20-07:00 Generating ios/Podfile
92
+ 2019-05-11T12:06:20-07:00 Linking dependencies
93
+ [✔] react-native link react-native-webview success in 0.5 s
94
+ 2019-05-11T12:06:20-07:00 Generating Pods project and ios/TestApp.xcworkspace
95
+ [✔] pod install success in 7.4 s
96
+ 2019-05-11T12:06:28-07:00 Conversion complete ✅
97
+ 2019-05-11T12:06:28-07:00 $ open ios/TestApp.xcworkspace
98
+ ```
@@ -1,4 +1,6 @@
1
+ require 'cocoapods-core'
1
2
  require 'commander'
3
+ require 'rubygems'
2
4
  require_relative 'converter'
3
5
  require_relative 'metadata'
4
6
 
@@ -22,15 +24,64 @@ module ReactNativeUtil
22
24
 
23
25
  c.action do |_args, opts|
24
26
  begin
27
+ report_configuration
25
28
  converter = Converter.new repo_update: opts.repo_update
26
29
  converter.convert_to_react_pod!
30
+ exit 0
31
+ rescue ExecutionError => e
32
+ # Generic command failure.
33
+ log e.message.red.bold
34
+ exit(-1)
27
35
  rescue ConversionError => e
28
- log "Conversion failed: #{e.message}"
36
+ log "Conversion failed: #{e.message}".red.bold
37
+ exit(-1)
29
38
  end
30
39
  end
31
40
  end
32
41
 
33
42
  run!
34
43
  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
35
86
  end
36
87
  end
@@ -1,5 +1,6 @@
1
1
  require 'erb'
2
2
  require 'json'
3
+ require 'tmpdir'
3
4
  require 'tty/platform'
4
5
  require 'xcodeproj'
5
6
  require_relative 'util'
@@ -75,9 +76,16 @@ module ReactNativeUtil
75
76
  exit 0
76
77
  end
77
78
 
78
- # Don't run yarn until we're sure we're proceeding,
79
+ if File.exist? podfile_path
80
+ log "Podfile already present at #{File.expand_path podfile_path}.".red.bold
81
+ log "A future release of #{NAME} may support integration with an existing Podfile."
82
+ log 'This release can only convert apps that do not currently use a Podfile.'
83
+ exit 1
84
+ end
85
+
86
+ # Don't run yarn until we're sure we're proceeding.
79
87
  log 'Installing NPM dependencies with yarn'
80
- execute 'yarn'
88
+ run_command_with_spinner! 'yarn', log: File.join(Dir.tmpdir, 'yarn.log')
81
89
 
82
90
  # Unused, but should be there and parseable
83
91
  load_react_podspec!
@@ -90,8 +98,9 @@ module ReactNativeUtil
90
98
  deps_to_add = dependencies
91
99
 
92
100
  # 3. Run react-native unlink for each one.
101
+ log 'Unlinking dependencies'
93
102
  dependencies.each do |dep|
94
- execute 'react-native', 'unlink', dep
103
+ run_command_with_spinner! 'react-native', 'unlink', dep, log: File.join(Dir.tmpdir, "react-native-unlink-#{dep}.log")
95
104
  end
96
105
 
97
106
  # reload after react-native unlink
@@ -113,14 +122,18 @@ module ReactNativeUtil
113
122
  generate_podfile!
114
123
 
115
124
  # 6. Run react-native link for each dependency.
125
+ log 'Linking dependencies'
116
126
  deps_to_add.each do |dep|
117
- execute 'react-native', 'link', dep
127
+ run_command_with_spinner! 'react-native', 'link', dep, log: File.join(Dir.tmpdir, "react-native-link-#{dep}.log")
118
128
  end
119
129
 
120
130
  # 7. pod install
121
- command = %w[pod install --silent]
131
+ log "Generating Pods project and ios/#{app_name}.xcworkspace"
132
+ command = %w[pod install]
122
133
  command << '--repo-update' if options[:repo_update]
123
- execute(*command, chdir: 'ios')
134
+ run_command_with_spinner!(*command, chdir: 'ios', log: File.join(Dir.tmpdir, 'pod-install.log'))
135
+
136
+ log 'Conversion complete ✅'
124
137
 
125
138
  # 8. SCM/git (add, commit - optional)
126
139
 
@@ -253,10 +266,15 @@ module ReactNativeUtil
253
266
  raise ConversionError, "Target #{app_name} is not an application target." unless app_target.product_type == 'com.apple.product-type.application'
254
267
  end
255
268
 
269
+ def podfile_path
270
+ 'ios/Podfile'
271
+ end
272
+
256
273
  # Generate a Podfile from a template.
257
274
  def generate_podfile!
275
+ log "Generating #{podfile_path}"
258
276
  podfile_contents = ERB.new(File.read(PODFILE_TEMPLATE_PATH)).result binding
259
- File.open 'ios/Podfile', 'w' do |file|
277
+ File.open podfile_path, 'w' do |file|
260
278
  file.write podfile_contents
261
279
  end
262
280
  end
@@ -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.3'
4
+ VERSION = '0.2.0'
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.'
@@ -1,4 +1,5 @@
1
1
  require 'colored'
2
+ require 'tty/spinner'
2
3
  require_relative 'core_ext/io'
3
4
  require_relative 'core_ext/regexp'
4
5
  require_relative 'exceptions'
@@ -6,8 +7,27 @@ require_relative 'exceptions'
6
7
  module ReactNativeUtil
7
8
  # Module with utility methods
8
9
  module Util
9
- # [TTY::Platform] Object with platform information
10
- attr_reader :platform
10
+ # Executes a command with no output to the terminal. A spinner is displayed
11
+ # instead. Output may be directed to a file.
12
+ # @param command Variadic command to be executed
13
+ # @param log [String, Symbol, nil] Output for command (path, IO or a symbol such as :close)
14
+ # @param chdir [String, nil] Directory in which to execute the command
15
+ # @raise ExecutionError on failure
16
+ def run_command_with_spinner!(*command, log: nil, chdir: nil)
17
+ STDOUT.flush
18
+ STDERR.flush
19
+ spinner = TTY::Spinner.new "[:spinner] #{command.shelljoin}", format: :flip
20
+ spinner.auto_spin
21
+ start_time = Time.now
22
+ execute(*command, log: nil, output: log, chdir: chdir)
23
+ elapsed = Time.now - start_time
24
+ spinner.success "success in #{format('%.1f', elapsed)} s"
25
+ rescue ExecutionError
26
+ elapsed = Time.now - start_time
27
+ spinner.error "failure in #{format('%.1f', elapsed)} s"
28
+ STDOUT.log "See #{log} for details." if log && log.kind_of?(String)
29
+ raise
30
+ end
11
31
 
12
32
  # Execute the specified command. If output is non-nil, generate a log
13
33
  # at that location. Main log (open) is log.
@@ -24,7 +44,7 @@ module ReactNativeUtil
24
44
  options = chdir.nil? ? {} : { chdir: chdir }
25
45
  system(*command, options.merge(%i[err out] => output))
26
46
 
27
- raise ExecutionError unless $?.success?
47
+ raise ExecutionError, "#{command.shelljoin}: #{$?}" unless $?.success?
28
48
 
29
49
  nil
30
50
  end
@@ -53,12 +73,16 @@ module ReactNativeUtil
53
73
  value.to_f
54
74
  end
55
75
 
76
+ # [TTY::Platform] Object with platform information
77
+ def platform
78
+ @platform ||= TTY::Platform.new
79
+ end
80
+
56
81
  # Convenience method to determine if running on a Mac.
57
82
  # @return true if running on a Mac
58
83
  # @return false otherwise
59
84
  def mac?
60
- @platform ||= TTY::Platform.new
61
- @platform.mac?
85
+ platform.mac?
62
86
  end
63
87
 
64
88
  # Wrapper for STDOUT.log
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.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Dee
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: tty-spinner
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement