Module: EMMProj

Defined in:
lib/emm/proj.rb

Class Method Summary collapse

Class Method Details

.create_proj(proj_name, output_dir, emm_pods_name, configs) ⇒ Object



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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/emm/proj.rb', line 39

def self.create_proj(proj_name, output_dir, emm_pods_name, configs)
	# create_temp_proj : 创建一个正式项目
	# proj_name : 项目名称
	# output_dir : 项目导出目录
	# emm_pods_name : EMM_Pods 文件夹的名称
	# configs : 项目配置
	proj_path = output_dir + "/" + proj_name + "/" + proj_name + ".xcodeproj"
	# 创建工程文件,并保存
	Xcodeproj::Project.new(proj_path).save
	# 打开创建的文件
	project = Xcodeproj::Project.open(proj_path)	
	# 创建@target,主要的参数 type: application :dynamic_library framework :static_library
	# name:@target名称
	# platform:平台 :ios或者:osx
	@target = project.new_target(:application, proj_name, :ios)

	# 创建一个分组,名称为proj_name,对应的路径为./proj_name
	group = project.new_group(proj_name)
	# 给分组添加文件引用
	group.new_reference("./" + proj_name + "/AppDelegate.h")
	@target.add_file_references(
		[group.new_reference("./" + proj_name + "/AppDelegate.m")]
	);
	group.new_reference("./" + proj_name + "/ViewController.h")
	@target.add_file_references(
		[group.new_reference("./" + proj_name + "/ViewController.m")]
	);

	# 在分组下创建一个名字为Supporting Files的子分组,并给该子分组添加main和info.plist文件引用
	supportGroup = group.new_group("Supporting Files")
	supportGroup.new_reference("./" + proj_name + "/Info.plist")
	@target.add_file_references(
		[supportGroup.new_reference("./" + proj_name + "/main.m")]
	);
	@target.add_resources(
		[supportGroup.new_reference("./" + proj_name + "/Base.lproj/LaunchScreen.storyboard"),
		supportGroup.new_reference("./" + proj_name + "/Base.lproj/Main.storyboard"),
		supportGroup.new_reference("./" + proj_name + "/Assets.xcassets")]
	);

	# 添加@target配置信息
	@target.build_configuration_list.set_setting("INFOPLIST_FILE", "$(SRCROOT)/" + proj_name + "/Info.plist")
	@target.build_configuration_list.set_setting("PRODUCT_BUNDLE_IDENTIFIER", configs["bundle_identifier"])
	@target.build_configuration_list.set_setting("IPHONEOS_DEPLOYMENT_TARGET", configs["deployment_target"])

	# 添加 EMM_Pods 文件夹到项目中
	@libs_dir = output_dir + "/" + proj_name + "/" + emm_pods_name
	@emm_pods_name = emm_pods_name
	
	traverse(File.dirname(@libs_dir), File.basename(@libs_dir), project.main_group)

	@target.build_configuration_list["Debug"].base_configuration_reference = project.reference_for_path(@libs_dir + "/EMM_Debug.xcconfig")
	@target.build_configuration_list["Release"].base_configuration_reference = project.reference_for_path(@libs_dir + "/EMM_Release.xcconfig")

	# 保存
	project.save
end

.create_temp_proj(proj_name, output_dir) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/emm/proj.rb', line 28

def self.create_temp_proj(proj_name, output_dir)
	# create_temp_proj : 创建一个临时项目
	# proj_name : 项目名称
	# output_dir : 项目导出目录
	proj_path = output_dir + "/" + proj_name + ".xcodeproj"
	Xcodeproj::Project.new(proj_path).save
	project = Xcodeproj::Project.open(proj_path)
	target = project.new_target(:application, proj_name, :ios)
	project.save
end

.traverse(dirname, basename, super_group) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/emm/proj.rb', line 7

def self.traverse(dirname, basename, super_group)			
	filepath = dirname + "/" + basename
	refpath = "./" + @emm_pods_name + filepath[@libs_dir.length, filepath.length - @libs_dir.length]

	if File.directory?(filepath)
		group = super_group.new_group(basename)
		Dir.foreach(filepath) do |filename|
			if filename != "." and filename != ".." and filename != ".DS_Store"
				traverse(filepath, filename, group)
			end	
		end
	else
		ref = super_group.new_reference(refpath)
		extname = File.extname(basename)
		if !([".xcconfig", ".a", ".h"].include?(extname))
			# 除去 [".a", ".xcconfig", ".h"] 文件外,都当做资源文件添加到 target 中
			@target.add_resources([ref])
		end
	end	
end