Class: PodBuilder::Command::Init

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

Class Method Summary collapse

Class Method Details

.callObject



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
47
48
49
50
51
52
53
# File 'lib/pod_builder/command/init.rb', line 6

def self.call
  raise "\n\nAlready initialized\n".red if Configuration.exists

  xcworkspace = Dir.glob("*.xcworkspace")
  raise "\n\nNo xcworkspace found in current folder\n".red if xcworkspace.count == 0
  raise "\n\nToo many xcworkspaces found in current folder\n#{xcworkspace}\n".red if xcworkspace.count > 1

  Configuration.project_name = File.basename(xcworkspace.first, ".*")

  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")

  write_gitignore
  write_gitattributes

  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_content = File.read(prebuilt_podfile_path)

  podfile_content = Podfile.add_configuration_load_block(podfile_content)
  podfile_content = Podfile.add_install_block(podfile_content)
  podfile_content = Podfile.update_path_entries(podfile_content, Init.method(:podfile_path_transform))
  podfile_content = Podfile.update_project_entries(podfile_content, Init.method(:podfile_path_transform))
  podfile_content = Podfile.update_require_entries(podfile_content, Init.method(:podfile_path_transform))

  if podfile_content.include?("/node_modules/react-native/")
    podfile_content = Podfile.prepare_for_react_native(podfile_content)
    update_react_native_podspecs()
  end

  File.write(prebuilt_podfile_path, podfile_content)

  Configuration.write

  update_gemfile

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