Module: EMM

Defined in:
lib/emm.rb

Class Method Summary collapse

Class Method Details

.create_emm_project(config_file, export_dir) ⇒ Object



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
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/emm.rb', line 9

def self.create_emm_project(config_file, export_dir)
   	
	# config_file : 配置文件.json
	# export_dir  : 项目导出目录			

	config_path = Pathname.new(config_file).realpath.to_s	# 配置文件绝对路径
	export_path = Pathname.new(export_dir).realpath.to_s	# 导出项目的绝对路径
	root_path = Pathname.new(File.dirname(__FILE__) + "/emm").realpath.to_s	# 源代码根目录

	temp_proj_name = "EMM_Temp_Proj"			# 临时项目名称,用于生成 pod 项目
	temp_proj_path = "/tmp/" + temp_proj_name	# 临时项目路劲

	# 删除临时项目文件夹(如果存在)
	FileUtils.remove_dir(temp_proj_path, true)

	# 读取配置文件
	json_file = File.open(config_path)
	configs_string = json_file.read
	configs = JSON.parse(configs_string)	# 配置信息
	proj_name = configs["project_name"]		# 项目名称

	emm_pods_name = "EMM_Pods"												# EMM 目录名
	emm_pods_path = export_path + "/" + proj_name + "/" + emm_pods_name		# EMM 路径

	# 创建一个临时 proj
	EMMProj.create_temp_proj(temp_proj_name, temp_proj_path)

	# 通过 json 配置文件,创建一个 podfile
	EMMFiles.create_podfile(configs, temp_proj_path, temp_proj_name)

	# 通过 shell 脚本生成 pod 项目,最终生成所需的 .a、.h 和 资源文件
	cmd = "sh " + root_path + "/pods_build.sh " + temp_proj_path + " " + emm_pods_path
	system(cmd)

	# 从 pods 中拷贝出资源文件
	EMMFiles.copy_resources(temp_proj_path + "/Pods", temp_proj_name, emm_pods_path + "/Resources")

	# 提取 pods 中的 xcconfig,创建自己的xcconfig
	xcconfig_source = temp_proj_path + "/Pods/Target\ Support\ Files/Pods-" + temp_proj_name + "/Pods-" + temp_proj_name + ".debug.xcconfig"
	xcconfig_export = emm_pods_path + "/EMM_Debug.xcconfig"
	EMMFiles.copy_xcconfig(xcconfig_source, xcconfig_export)
	xcconfig_source = temp_proj_path + "/Pods/Target\ Support\ Files/Pods-" + temp_proj_name + "/Pods-" + temp_proj_name + ".release.xcconfig"
	xcconfig_export = emm_pods_path + "/EMM_Release.xcconfig"
	EMMFiles.copy_xcconfig(xcconfig_source, xcconfig_export)

	# 从 Template 中拷贝 Project 的一些基本文件
	FileUtils.cp_r(root_path + "/Template/", export_path + "/" + proj_name + "/" + proj_name)

	# 创建最终输出的 Proj
	EMMProj.create_proj(proj_name, export_path, emm_pods_name, configs)

	# 拷贝 podfile 到输出的 proj 中
	FileUtils.cp(temp_proj_path + "/Podfile", export_path + "/" + proj_name + "/.Podfile")
	# 删除临时项目文件夹
	FileUtils.remove_dir(temp_proj_path, true)
end