Class: BuildProject

Inherits:
Object show all
Defined in:
lib/cocoapods-podspec-binary/mbuild/mbuild_project.rb

Overview

Class prepare project

Instance Method Summary collapse

Constructor Details

#initializeBuildProject

Returns a new instance of BuildProject.



7
8
9
10
# File 'lib/cocoapods-podspec-binary/mbuild/mbuild_project.rb', line 7

def initialize
  @config_instance = MBuildConfig.instance
  @project_dir = File.join(MBuildConfig.instance.mbuild_dir, 'project')
end

Instance Method Details

#add_build_settingsObject



51
52
53
54
55
# File 'lib/cocoapods-podspec-binary/mbuild/mbuild_project.rb', line 51

def add_build_settings
  File.open('Podfile', 'a+') do |podfile|
    podfile.puts build_settings_code
  end
end

#build_settings_codeObject



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cocoapods-podspec-binary/mbuild/mbuild_project.rb', line 57

def build_settings_code
  <<~CODE
    post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
        end
      end
    end
  CODE
end

#generate_projectObject



24
25
26
27
28
29
# File 'lib/cocoapods-podspec-binary/mbuild/mbuild_project.rb', line 24

def generate_project
  config_instance = MBuildConfig.instance
  add_build_settings if config_instance.swift
  update_podfile
  project_install
end

#prepare_projectObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cocoapods-podspec-binary/mbuild/mbuild_project.rb', line 12

def prepare_project
  example_dir = @project_dir
  if File.directory?(example_dir)
    Git.open(example_dir).reset_hard
    Git.open(example_dir).pull
  else
    MBuildFileUtils.create_folder(@project_dir)
    example_url = 'ssh://[email protected]:56358/group-wp-sdk/binary-example-ios.git'
    Git.clone(example_url, example_dir)
  end
end

#project_installObject



43
44
45
46
47
48
49
# File 'lib/cocoapods-podspec-binary/mbuild/mbuild_project.rb', line 43

def project_install
  Dir.chdir(@project_dir) do
    update_argv = []
    update_command = Pod::Command::Update.new(CLAide::ARGV.new(update_argv))
    update_command.run
  end
end

#update_podfileObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cocoapods-podspec-binary/mbuild/mbuild_project.rb', line 31

def update_podfile
  podfile_path = File.join(@project_dir, 'Podfile')
  podfile_content = File.read(podfile_path)
  pod_name = @config_instance.pod_name
  pod_version = @config_instance.pod_version
  puts("name:#{pod_name} version:#{pod_version}")
  new_content = podfile_content.gsub('BINARY_NAME', pod_name).gsub('BINARY_VERSION', pod_version).gsub(
    'cocoapods-mdapbox', 'cocoapods-podspec-binary'
  )
  File.open(podfile_path, 'w') { |file| file.puts new_content }
end