Class: PodBuilder::Command::Init

Inherits:
Object
  • Object
show all
Defined in:
lib/pod_builder/command/init.rb

Class Method Summary collapse

Class Method Details

.call(options) ⇒ Object



6
7
8
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
# File 'lib/pod_builder/command/init.rb', line 6

def self.call(options)
  raise "\n\nAlready initialized\n".red if Configuration.exists
  raise "\n\nXcode workspace not found\n".red if PodBuilder::project_path.nil?
  
  options[:prebuild_path] ||= Configuration.base_path

  if File.expand_path(options[:prebuild_path]) != options[:prebuild_path] # if not absolute
    options[:prebuild_path] = File.expand_path(PodBuilder::project_path(options[:prebuild_path]))
  end

  FileUtils.mkdir_p(options[:prebuild_path])
  FileUtils.mkdir_p("#{options[:prebuild_path]}/.pod_builder")
  FileUtils.touch("#{options[:prebuild_path]}/.pod_builder/pod_builder")

  source_path_rel_path = "Sources"
  development_pods_config_rel_path = Configuration.dev_pods_configuration_filename

  git_ignores = ["Pods/",
                 "*.xcworkspace",
                 "*.xcodeproj",
                 "Podfile.lock",
                 source_path_rel_path,
                 development_pods_config_rel_path]
  
  File.write("#{options[:prebuild_path]}/.gitignore", git_ignores.join("\n"))

  project_podfile_path = PodBuilder::project_path("Podfile")
  prebuilt_podfile_path = File.join(options[:prebuild_path], "Podfile")
  FileUtils.cp(project_podfile_path, prebuilt_podfile_path)
  
  Podfile.add_install_block(prebuilt_podfile_path)
  Podfile.update_path_entires(prebuilt_podfile_path, false, PodBuilder::project_path(""))
  Podfile.update_project_entries(prebuilt_podfile_path, false, PodBuilder::project_path(""))

  Configuration.write

  update_gemfile

  puts "\n\nšŸŽ‰ done!\n".green
  return true
end

.trim_gemfile_line(line) ⇒ Object



74
75
76
# File 'lib/pod_builder/command/init.rb', line 74

def self.trim_gemfile_line(line)
  return line.gsub("\"", "'").gsub(" ", "")
end

.update_gemfileObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/pod_builder/command/init.rb', line 50

def self.update_gemfile
  gemfile_path = File.join(PodBuilder::home, "Gemfile")
  unless File.exist?(gemfile_path)
    FileUtils.touch(gemfile_path)
  end

  source_line = "source 'https://rubygems.org'"
  podbuilder_line = "gem 'pod-builder'"

  gemfile = File.read(gemfile_path)

  gemfile_lines = gemfile.split("\n")
  gemfile_lines.select! { |x| !trim_gemfile_line(x).include?(trim_gemfile_line(source_line)) }
  gemfile_lines.select! { |x| !trim_gemfile_line(x).include?(trim_gemfile_line(podbuilder_line)) }

  gemfile_lines.insert(0, source_line)
  gemfile_lines.push(podbuilder_line)
     
  File.write(gemfile_path, gemfile_lines.join("\n"))

  Dir.chdir(PodBuilder::home)
  system("bundle")
end