Class: ReactNativeUtil::CLI

Inherits:
Object
  • Object
show all
Includes:
Commander::Methods, Util
Defined in:
lib/react_native_util/cli.rb

Instance Method Summary collapse

Methods included from Util

#boolean_env_var?, #execute, #float_env_var, #have_command?, #log, #mac?, #platform, #run_command_with_spinner!, #validate_commands!

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/react_native_util/cli.rb', line 10

def run
  program :name, SUMMARY
  program :version, VERSION
  program :description, "[Work in progress] Converts a project created with <%= color 'react-native init', BOLD %> to use\nCocoaPods with the React pod from node_modules. <%= color '\#{NAME} react_pod -h', BOLD %>\nfor more information.\n"

  command :react_pod do |c|
    c.syntax = "#{NAME} react_pod [OPTIONS]"
    c.summary = 'Convert a React Native app to use the React pod from node_modules.'
    c.description = "[Work in progress] Converts a project created with <%= color 'react-native init', BOLD %> to use\nCocoaPods with the React pod from node_modules. This preserves compatibility\nwith <%= color 'react-native link', BOLD %>. A converted project will still start the Metro packager\nautomatically via a Run Script build phase in the Xcode project. This is an\nalternative to performing manual surgery on a project in Xcode.\n"

    c.option '--[no-]repo-update', 'Update the local podspec repo (default: update; env. var. REACT_NATIVE_UTIL_REPO_UPDATE)'

    c.action do |_args, opts|
      begin
        converter = Converter.new repo_update: opts.repo_update
        converter.convert_to_react_pod!
        exit 0
      rescue ExecutionError => e
        # Generic command failure.
        log e.message.red.bold
        exit(-1)
      rescue ConversionError => e
        log "Conversion failed: #{e.message}".red.bold
        exit(-1)
      end
    end
  end

  run!
end