Module: EMMFiles

Defined in:
lib/emm/files.rb

Class Method Summary collapse

Class Method Details

.copy_resources(pods_dir, pods_proj_name, export_dir) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/emm/files.rb', line 37

def self.copy_resources(pods_dir, pods_proj_name, export_dir)
  # 从 pod 的 XXX_Proj-resources.sh 脚本文件中提取出资源文件的路径,并将资源文件拷贝到导出目录下
  # source_path: Pods 文件夹路径
  # export_dir: 资源文件导出目录
  start_string = 'if [[ "$CONFIGURATION" == "Release" ]]; then'
  end_string = 'fi'
  writing = false
  # 读取 Cocoapods 提供的 copy resources 的脚本文件
  IO.foreach(pods_dir + "/Target Support Files/Pods-" + pods_proj_name + "/Pods-" + pods_proj_name + "-resources.sh") do |line| 
    if line.start_with?(start_string)
      writing = true
      next
    end
    if writing
      if line.start_with?(end_string)      
        break
      end
      line = line.match("\".+\"")[0]
      line = line.gsub("\"", "")
      src = pods_dir + "/" + line
      dst = export_dir + "/" + line    
      FileUtils.mkdir_p(File.dirname(dst))     
       if File.directory?(src)
         FileUtils.cp_r(src, File.dirname(dst))
       else
         FileUtils.cp(src, dst)  
      end
    end 
  end
end

.copy_xcconfig(source_path, export_path) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/emm/files.rb', line 22

def self.copy_xcconfig(source_path, export_path)
  # 从 pod 的 xcconfig 中提取出所需内容,生成项目所需的 xcconfig
  # sourcePath : Cocoapods 生成的 xcconfig 文件
  # outputPath : 导出的 xcconfig 文件
  output_file = File.new(export_path, "w+")
  IO.foreach(source_path) do |line| 
    if line.start_with?("OTHER_LDFLAGS")
      output_file.syswrite(line)
    end
  end
  output_file.syswrite("HEADER_SEARCH_PATHS = $(inherited) ${SRCROOT}/EMM_Pods/Headers/**\n")
  output_file.syswrite("LIBRARY_SEARCH_PATHS = $(inherited) ${SRCROOT}/EMM_Pods/Libraries")
  output_file.close
end

.create_podfile(configs, output_dir, proj_name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/emm/files.rb', line 6

def self.create_podfile(configs, output_dir, proj_name) 
  # create_podfile : 通过 json 配置文件,创建一个 podfile
  # configs : 项目配置
  # output_dir : Podfile 文件导出目录
  podfile = File.new(output_dir + "/Podfile", "w+")
  podfile.syswrite("source 'https://github.com/CocoaPods/Specs.git'\n")
  podfile.syswrite("source '" + configs["private_repo"] + "'\n")
  podfile.syswrite("platform :ios, ‘" + configs["deployment_target"] + "’\n")
  podfile.syswrite("target '" + proj_name + "' do\n")
  for pod in configs["pods"]
    podfile.syswrite(pod + "\n")  
  end
  podfile.syswrite("end")
  podfile.close
end