Module: CocoapodsCatalystSupport

Defined in:
lib/cocoapods-catalyst-support/utils.rb,
lib/cocoapods-catalyst-support/gem_version.rb,
lib/cocoapods-catalyst-support/os_platform.rb,
lib/cocoapods-catalyst-support/pod_dependency.rb,
lib/cocoapods-catalyst-support/command_helpers.rb,
lib/cocoapods-catalyst-support/catalyst_configuration.rb

Defined Under Namespace

Modules: TargetUtils Classes: CatalystConfiguration, OSPlatform, PodDependency, Podfile, ValidationError

Constant Summary collapse

VERSION =
"0.2.0"

Instance Method Summary collapse

Instance Method Details

#configure_podfileObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/cocoapods-catalyst-support/command_helpers.rb', line 51

def configure_podfile
  podfile = File.read('Podfile')

  unless podfile.include? "require 'cocoapods-catalyst-support'" 
    podfile = "require 'cocoapods-catalyst-support'\n\n" + podfile
  end

  config = ''
  unless podfile.match(/catalyst_configuration\s+do/)
    config += "\n# Configure your macCatalyst dependencies\n"
    config += "catalyst_configuration do\n"
    config += "\t# Uncomment the next line for a verbose output\n\t# verbose!\n\n"
    config += "\t# ios '<pod_name>' # This dependency will only be available for iOS\n"
    config += "\t# macos '<pod_name>' # This dependency will only be available for macOS\nend\n"
  end

  is_catalyst_configured = podfile.match(/post_install[\S\s]+installer[\S\s]configure_catalyst/)
  changed = !(is_catalyst_configured && config.empty?)
  unless podfile.match /post_install\s+do/
    podfile += config
    podfile += "\n# Configure your macCatalyst App\npost_install do |installer|\n\tinstaller.configure_catalyst\nend\n"
  else 
    configure_line = (podfile.include? 'configure_catalyst') ? "" : "\n\tinstaller.configure_catalyst\n"
    post_install_line = podfile.filter_lines do |line| line.include? 'post_install' end.first
    
    if config.empty? 
      new_post_install_line = post_install_line + configure_line
    else
      new_post_install_line = "#{config}\n\n" + post_install_line + configure_line
    end

    podfile.gsub! post_install_line, new_post_install_line
  end

  unless podfile.nil? 
    File.open('Podfile', "w") { |file| file << podfile }
  end

  if changed 
    puts 'Done! Checkout your Podfile to start configuring your macCatalyst dependencies'
  else
    puts 'It seems your Podfile is ready. Go ahead and start configuring your macCatalyst dependencies'
  end
end

#loggs(string) ⇒ Object



17
18
19
20
21
22
# File 'lib/cocoapods-catalyst-support/utils.rb', line 17

def loggs string
  if $verbose
    puts string
  end
  return
end

#validate_podfileObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/cocoapods-catalyst-support/command_helpers.rb', line 96

def validate_podfile
  podfile = File.read('Podfile')
  errors = []

  unless podfile.match(/require\s+[('|")]cocoapods-catalyst-support[('|")]/)
    errors << "- Are you missing `require cocoapods-catalyst-support` in your Podfile".red
  end

  unless podfile.match(/catalyst_configuration\s+do/)
    errors << "- Are you missing `require cocoapods-catalyst-support` in your Podfile".red
  end

  unless podfile.match(/post_install[\S\s]+installer[\S\s]configure_catalyst/)
    errors << "- Are you calling `configure_catalyst` from `post_install` phase?".red
  end

  pod_errors = podfile.validate
  unless pod_errors.empty?
    errors << "#{pod_errors.reduce('') do |acc, s| "#{acc}\n#{s}" end }"
  end

  unless errors.empty?
    raise ValidationError.new "Your catalyst configuration seems to have some errors:\n#{errors.join}"
  end

end