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?, #elapsed_from, #execute, #float_env_var, #have_command?, #log, #mac?, #platform, #run_command_with_spinner!, #validate_commands!

Instance Method Details

#runObject



9
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/react_native_util/cli.rb', line 9

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]\n    rn react_pod [OPTIONS]"
    c.summary = 'Convert a React Native app to use the React pod from node_modules.'
    c.description = "Converts a React Native Xcode project to use the React pod from node_modules\ninstead of the projects in the Libraries group. This makes it easier to manage\nnative dependencies while preserving compatibility with <%= color 'react-native link', BOLD %>.\nThe command looks for your app's package.json in the current directory and\nexpects your Xcode project to be located under the ios subdirectory and have\nthe name specified for your app in package.json. If a Podfile is found in the\nios subdirectory, the conversion will fail.\n\nThe React.xcodeproj in the Libraries group of a project created by\n<%= color 'react-native init', BOLD %> automatically starts the Metro packager via a Run Script\nbuild phase. When the react_pod command removes the Libraries group from your\napp project, it adds an equivalent build phase to your app project so that the\npackager will automatically be started when necessary by Xcode.\n\nUse the <%= color '-u', BOLD %> or <%= color '--update', BOLD %> option to update the packager script after\nupdating React Native, in case the packager script on the React.xcodeproj changes\nafter it's removed from your project.\n"

    c.option '-u', '--update', 'Update a previously converted project (default: convert)'
    c.option '--[no-]repo-update', 'Update the local podspec repo (default: update; env. var. REACT_NATIVE_UTIL_REPO_UPDATE)'

    c.examples = {
      'Convert an app project' => 'rn react_pod',
      'Convert an app project without updating the podspec repo' => 'rn react_pod --no-repo-update',
      'Update a converted project' => 'rn react_pod -u'
    }

    c.action do |_args, opts|
      begin
        converter = Converter.new repo_update: opts.repo_update
        if opts.update
          converter.update_project!
        else
          converter.convert_to_react_pod!
        end
        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