Class: Project::ProjectManager

Inherits:
Object
  • Object
show all
Defined in:
lib/podfileDep/reference/project.rb

Class Method Summary collapse

Class Method Details

.add_local_yaml_ignoreObject

把local.yaml添加到忽略文件中



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/podfileDep/reference/project.rb', line 93

def self.add_local_yaml_ignore

  gitignore = ".gitignore"
  podfile_local_yaml = MyConstants::PODFILE_LOCAL_YAML

  contain = false
  gitignore_path= "#{Dir.pwd}/#{gitignore}"
  if File.exist?(gitignore_path)
    line_array = IO.readlines(gitignore_path)
    line_array.each do |line|
      line = line.gsub(" ", "").gsub("\n", "")
      if line == podfile_local_yaml
        contain = true
        break
      end
    end
  end

  unless contain
    File.open(gitignore_path, 'a+') { |file|
      file.write(podfile_local_yaml)
    }
  end
end

.add_yamlObject



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
# File 'lib/podfileDep/reference/project.rb', line 58

def self.add_yaml

  podfile_local_yaml = MyConstants::PODFILE_LOCAL_YAML
  podfile_module_yaml = MyConstants::PODFILE_MODULE_YAML
  podfile_third_party_yaml = MyConstants::PODFILE_THIRD_PARTY_YAML

  project_manager = XCProject::XcodeprojManager.share_manager
  pods_project = project_manager.get_pods_project

  did_add = []

  pods_project.main_group.children.each {|child|
    did_add << child.display_name
  }

  unless did_add.include?(podfile_local_yaml)
    path = "#{Dir.pwd}/#{podfile_local_yaml}"
    pods_project.new_file(path)
  end

  unless did_add.include?(podfile_module_yaml)
    path = "#{Dir.pwd}/#{podfile_module_yaml}"
    pods_project.new_file(path)
  end

  unless did_add.include?(podfile_third_party_yaml)
    path = "#{Dir.pwd}/#{podfile_third_party_yaml}"
    pods_project.new_file(path)
  end

  pods_project.sort(:groups_position => :below)
  pods_project.save
end

.yaml_referenceObject

将yaml文件加入引用



52
53
54
55
56
# File 'lib/podfileDep/reference/project.rb', line 52

def self.yaml_reference
  puts "yaml文件引用添加"
  self.add_yaml
  self.add_local_yaml_ignore
end

.yaml_resourceObject



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/podfileDep/reference/project.rb', line 6

def self.yaml_resource
  puts "yaml资源文件添加"
  project_manager = XCProject::XcodeprojManager.share_manager
  targets = project_manager.get_app_targets
  targets.each do |target_name|
    target_supporting = "Pods-#{target_name}"
    resource_shell = "Pods-#{target_name}-resources.sh"
    resource_shell_path = "#{Dir.pwd}/Pods/Target Support Files/#{target_supporting}/#{resource_shell}"
    self.yaml_resource_file(resource_shell_path)
  end
end

.yaml_resource_file(file_path) ⇒ Object



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
# File 'lib/podfileDep/reference/project.rb', line 18

def self.yaml_resource_file(file_path)
  unless File.exist?(file_path)
    return
  end

  # 读内容
  content = ""
  line_array = IO.readlines(file_path)
  line_array.each_with_index { |line, index|
    content += line
    next_line = index<line_array.size ? line_array[index+1] : ""
    if line.include?("if [[ \"$CONFIGURATION\"") and next_line.include?("install_resource")
      if File.exist?(MyConstants::PODFILE_LOCAL_YAML)
        content += "  install_resource \"${SRCROOT}/#{MyConstants::PODFILE_LOCAL_YAML}\"\n"
      end

      if File.exist?(MyConstants::PODFILE_MODULE_YAML)
        content += "  install_resource \"${SRCROOT}/#{MyConstants::PODFILE_MODULE_YAML}\"\n"
      end

      if File.exist?(MyConstants::PODFILE_THIRD_PARTY_YAML)
        content += "  install_resource \"${SRCROOT}/#{MyConstants::PODFILE_THIRD_PARTY_YAML}\"\n"
      end
    end
  }

  # 写文件
  File.open(file_path, 'w') { |file|
    file.write(content)
  }
end