emm 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- metadata +1 -5
- data/lib/emm/files.rb +0 -67
- data/lib/emm/proj.rb +0 -96
- data/lib/emm/version.rb +0 -3
- data/lib/emm.rb +0 -66
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73cd5d862587824c35a76a272dff4f06674a4bc5
|
4
|
+
data.tar.gz: 70bd02ccf5486c3374e24bad433aa995bad7e753
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43ce0d40833330da1e9475f97b57080ef204a1d2066e8ed3f76df8f3b75dd387bee5567a4f716abd46a7e9380bb157ab95dc0f88742ff29f586e8c13a5632b5a
|
7
|
+
data.tar.gz: 3a75d0c5e0c91e17e41d6ba3d5ca88cfb11c217cd61fe844d414323d331dbb057b7756bc680b3fcf1a0d9fc85064577e4ca90d7ba8ee06345d6ae5c2281a574e
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- chenqmg
|
@@ -35,10 +35,6 @@ files:
|
|
35
35
|
- LICENSE.txt
|
36
36
|
- README.md
|
37
37
|
- bin/emm
|
38
|
-
- lib/emm.rb
|
39
|
-
- lib/emm/files.rb
|
40
|
-
- lib/emm/proj.rb
|
41
|
-
- lib/emm/version.rb
|
42
38
|
homepage: http://rubygems.org/gems/emm
|
43
39
|
licenses:
|
44
40
|
- MIT
|
data/lib/emm/files.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
module EMMFiles
|
5
|
-
|
6
|
-
def self.create_podfile(configs, output_dir, proj_name)
|
7
|
-
# create_podfile : 通过 json 配置文件,创建一个 podfile
|
8
|
-
# configs : 项目配置
|
9
|
-
# output_dir : Podfile 文件导出目录
|
10
|
-
podfile = File.new(output_dir + "/Podfile", "w+")
|
11
|
-
podfile.syswrite("source 'https://github.com/CocoaPods/Specs.git'\n")
|
12
|
-
podfile.syswrite("source '" + configs["private_repo"] + "'\n")
|
13
|
-
podfile.syswrite("platform :ios, ‘" + configs["deployment_target"] + "’\n")
|
14
|
-
podfile.syswrite("target '" + proj_name + "' do\n")
|
15
|
-
for pod in configs["pods"]
|
16
|
-
podfile.syswrite(pod + "\n")
|
17
|
-
end
|
18
|
-
podfile.syswrite("end")
|
19
|
-
podfile.close
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.copy_xcconfig(source_path, export_path)
|
23
|
-
# 从 pod 的 xcconfig 中提取出所需内容,生成项目所需的 xcconfig
|
24
|
-
# sourcePath : Cocoapods 生成的 xcconfig 文件
|
25
|
-
# outputPath : 导出的 xcconfig 文件
|
26
|
-
output_file = File.new(export_path, "w+")
|
27
|
-
IO.foreach(source_path) do |line|
|
28
|
-
if line.start_with?("OTHER_LDFLAGS")
|
29
|
-
output_file.syswrite(line)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
output_file.syswrite("HEADER_SEARCH_PATHS = $(inherited) ${SRCROOT}/EMM_Pods/Headers/**\n")
|
33
|
-
output_file.syswrite("LIBRARY_SEARCH_PATHS = $(inherited) ${SRCROOT}/EMM_Pods/Libraries")
|
34
|
-
output_file.close
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.copy_resources(pods_dir, pods_proj_name, export_dir)
|
38
|
-
# 从 pod 的 XXX_Proj-resources.sh 脚本文件中提取出资源文件的路径,并将资源文件拷贝到导出目录下
|
39
|
-
# source_path: Pods 文件夹路径
|
40
|
-
# export_dir: 资源文件导出目录
|
41
|
-
start_string = 'if [[ "$CONFIGURATION" == "Release" ]]; then'
|
42
|
-
end_string = 'fi'
|
43
|
-
writing = false
|
44
|
-
# 读取 Cocoapods 提供的 copy resources 的脚本文件
|
45
|
-
IO.foreach(pods_dir + "/Target Support Files/Pods-" + pods_proj_name + "/Pods-" + pods_proj_name + "-resources.sh") do |line|
|
46
|
-
if line.start_with?(start_string)
|
47
|
-
writing = true
|
48
|
-
next
|
49
|
-
end
|
50
|
-
if writing
|
51
|
-
if line.start_with?(end_string)
|
52
|
-
break
|
53
|
-
end
|
54
|
-
line = line.match("\".+\"")[0]
|
55
|
-
line = line.gsub("\"", "")
|
56
|
-
src = pods_dir + "/" + line
|
57
|
-
dst = export_dir + "/" + line
|
58
|
-
FileUtils.mkdir_p(File.dirname(dst))
|
59
|
-
if File.directory?(src)
|
60
|
-
FileUtils.cp_r(src, File.dirname(dst))
|
61
|
-
else
|
62
|
-
FileUtils.cp(src, dst)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
data/lib/emm/proj.rb
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
require "xcodeproj"
|
2
|
-
require "find"
|
3
|
-
require 'fileutils'
|
4
|
-
|
5
|
-
module EMMProj
|
6
|
-
|
7
|
-
def self.traverse(dirname, basename, super_group)
|
8
|
-
filepath = dirname + "/" + basename
|
9
|
-
refpath = "./" + @emm_pods_name + filepath[@libs_dir.length, filepath.length - @libs_dir.length]
|
10
|
-
|
11
|
-
if File.directory?(filepath)
|
12
|
-
group = super_group.new_group(basename)
|
13
|
-
Dir.foreach(filepath) do |filename|
|
14
|
-
if filename != "." and filename != ".." and filename != ".DS_Store"
|
15
|
-
traverse(filepath, filename, group)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
else
|
19
|
-
ref = super_group.new_reference(refpath)
|
20
|
-
extname = File.extname(basename)
|
21
|
-
if !([".xcconfig", ".a", ".h"].include?(extname))
|
22
|
-
# 除去 [".a", ".xcconfig", ".h"] 文件外,都当做资源文件添加到 target 中
|
23
|
-
@target.add_resources([ref])
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.create_temp_proj(proj_name, output_dir)
|
29
|
-
# create_temp_proj : 创建一个临时项目
|
30
|
-
# proj_name : 项目名称
|
31
|
-
# output_dir : 项目导出目录
|
32
|
-
proj_path = output_dir + "/" + proj_name + ".xcodeproj"
|
33
|
-
Xcodeproj::Project.new(proj_path).save
|
34
|
-
project = Xcodeproj::Project.open(proj_path)
|
35
|
-
target = project.new_target(:application, proj_name, :ios)
|
36
|
-
project.save
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.create_proj(proj_name, output_dir, emm_pods_name, configs)
|
40
|
-
# create_temp_proj : 创建一个正式项目
|
41
|
-
# proj_name : 项目名称
|
42
|
-
# output_dir : 项目导出目录
|
43
|
-
# emm_pods_name : EMM_Pods 文件夹的名称
|
44
|
-
# configs : 项目配置
|
45
|
-
proj_path = output_dir + "/" + proj_name + "/" + proj_name + ".xcodeproj"
|
46
|
-
# 创建工程文件,并保存
|
47
|
-
Xcodeproj::Project.new(proj_path).save
|
48
|
-
# 打开创建的文件
|
49
|
-
project = Xcodeproj::Project.open(proj_path)
|
50
|
-
# 创建@target,主要的参数 type: application :dynamic_library framework :static_library
|
51
|
-
# name:@target名称
|
52
|
-
# platform:平台 :ios或者:osx
|
53
|
-
@target = project.new_target(:application, proj_name, :ios)
|
54
|
-
|
55
|
-
# 创建一个分组,名称为proj_name,对应的路径为./proj_name
|
56
|
-
group = project.new_group(proj_name)
|
57
|
-
# 给分组添加文件引用
|
58
|
-
group.new_reference("./" + proj_name + "/AppDelegate.h")
|
59
|
-
@target.add_file_references(
|
60
|
-
[group.new_reference("./" + proj_name + "/AppDelegate.m")]
|
61
|
-
);
|
62
|
-
group.new_reference("./" + proj_name + "/ViewController.h")
|
63
|
-
@target.add_file_references(
|
64
|
-
[group.new_reference("./" + proj_name + "/ViewController.m")]
|
65
|
-
);
|
66
|
-
|
67
|
-
# 在分组下创建一个名字为Supporting Files的子分组,并给该子分组添加main和info.plist文件引用
|
68
|
-
supportGroup = group.new_group("Supporting Files")
|
69
|
-
supportGroup.new_reference("./" + proj_name + "/Info.plist")
|
70
|
-
@target.add_file_references(
|
71
|
-
[supportGroup.new_reference("./" + proj_name + "/main.m")]
|
72
|
-
);
|
73
|
-
@target.add_resources(
|
74
|
-
[supportGroup.new_reference("./" + proj_name + "/Base.lproj/LaunchScreen.storyboard"),
|
75
|
-
supportGroup.new_reference("./" + proj_name + "/Base.lproj/Main.storyboard"),
|
76
|
-
supportGroup.new_reference("./" + proj_name + "/Assets.xcassets")]
|
77
|
-
);
|
78
|
-
|
79
|
-
# 添加@target配置信息
|
80
|
-
@target.build_configuration_list.set_setting("INFOPLIST_FILE", "$(SRCROOT)/" + proj_name + "/Info.plist")
|
81
|
-
@target.build_configuration_list.set_setting("PRODUCT_BUNDLE_IDENTIFIER", configs["bundle_identifier"])
|
82
|
-
@target.build_configuration_list.set_setting("IPHONEOS_DEPLOYMENT_TARGET", configs["deployment_target"])
|
83
|
-
|
84
|
-
# 添加 EMM_Pods 文件夹到项目中
|
85
|
-
@libs_dir = output_dir + "/" + proj_name + "/" + emm_pods_name
|
86
|
-
@emm_pods_name = emm_pods_name
|
87
|
-
|
88
|
-
traverse(File.dirname(@libs_dir), File.basename(@libs_dir), project.main_group)
|
89
|
-
|
90
|
-
@target.build_configuration_list["Debug"].base_configuration_reference = project.reference_for_path(@libs_dir + "/EMM_Debug.xcconfig")
|
91
|
-
@target.build_configuration_list["Release"].base_configuration_reference = project.reference_for_path(@libs_dir + "/EMM_Release.xcconfig")
|
92
|
-
|
93
|
-
# 保存
|
94
|
-
project.save
|
95
|
-
end
|
96
|
-
end
|
data/lib/emm/version.rb
DELETED
data/lib/emm.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
|
2
|
-
module EMM
|
3
|
-
|
4
|
-
require 'pathname'
|
5
|
-
require 'json'
|
6
|
-
require "emm/version"
|
7
|
-
require "emm/files"
|
8
|
-
require "emm/proj"
|
9
|
-
|
10
|
-
def self.create_emm_project(config_file, export_dir)
|
11
|
-
|
12
|
-
# config_file : 配置文件.json
|
13
|
-
# export_dir : 项目导出目录
|
14
|
-
|
15
|
-
config_path = Pathname.new(config_file).realpath.to_s # 配置文件绝对路径
|
16
|
-
export_path = Pathname.new(export_dir).realpath.to_s # 导出项目的绝对路径
|
17
|
-
root_path = Pathname.new(File.dirname(__FILE__) + "/emm").realpath.to_s # 源代码根目录
|
18
|
-
|
19
|
-
temp_proj_name = "EMM_Temp_Proj" # 临时项目名称,用于生成 pod 项目
|
20
|
-
temp_proj_path = "/tmp/" + temp_proj_name # 临时项目路劲
|
21
|
-
|
22
|
-
# 删除临时项目文件夹(如果存在)
|
23
|
-
FileUtils.remove_dir(temp_proj_path, true)
|
24
|
-
|
25
|
-
# 读取配置文件
|
26
|
-
json_file = File.open(config_path)
|
27
|
-
configs_string = json_file.read
|
28
|
-
configs = JSON.parse(configs_string) # 配置信息
|
29
|
-
proj_name = configs["project_name"] # 项目名称
|
30
|
-
|
31
|
-
emm_pods_name = "EMM_Pods" # EMM 目录名
|
32
|
-
emm_pods_path = export_path + "/" + proj_name + "/" + emm_pods_name # EMM 路径
|
33
|
-
|
34
|
-
# 创建一个临时 proj
|
35
|
-
EMMProj.create_temp_proj(temp_proj_name, temp_proj_path)
|
36
|
-
|
37
|
-
# 通过 json 配置文件,创建一个 podfile
|
38
|
-
EMMFiles.create_podfile(configs, temp_proj_path, temp_proj_name)
|
39
|
-
|
40
|
-
# 通过 shell 脚本生成 pod 项目,最终生成所需的 .a、.h 和 资源文件
|
41
|
-
cmd = "sh " + root_path + "/pods_build.sh " + temp_proj_path + " " + emm_pods_path
|
42
|
-
system(cmd)
|
43
|
-
|
44
|
-
# 从 pods 中拷贝出资源文件
|
45
|
-
EMMFiles.copy_resources(temp_proj_path + "/Pods", temp_proj_name, emm_pods_path + "/Resources")
|
46
|
-
|
47
|
-
# 提取 pods 中的 xcconfig,创建自己的xcconfig
|
48
|
-
xcconfig_source = temp_proj_path + "/Pods/Target\ Support\ Files/Pods-" + temp_proj_name + "/Pods-" + temp_proj_name + ".debug.xcconfig"
|
49
|
-
xcconfig_export = emm_pods_path + "/EMM_Debug.xcconfig"
|
50
|
-
EMMFiles.copy_xcconfig(xcconfig_source, xcconfig_export)
|
51
|
-
xcconfig_source = temp_proj_path + "/Pods/Target\ Support\ Files/Pods-" + temp_proj_name + "/Pods-" + temp_proj_name + ".release.xcconfig"
|
52
|
-
xcconfig_export = emm_pods_path + "/EMM_Release.xcconfig"
|
53
|
-
EMMFiles.copy_xcconfig(xcconfig_source, xcconfig_export)
|
54
|
-
|
55
|
-
# 从 Template 中拷贝 Project 的一些基本文件
|
56
|
-
FileUtils.cp_r(root_path + "/Template/", export_path + "/" + proj_name + "/" + proj_name)
|
57
|
-
|
58
|
-
# 创建最终输出的 Proj
|
59
|
-
EMMProj.create_proj(proj_name, export_path, emm_pods_name, configs)
|
60
|
-
|
61
|
-
# 拷贝 podfile 到输出的 proj 中
|
62
|
-
FileUtils.cp(temp_proj_path + "/Podfile", export_path + "/" + proj_name + "/.Podfile")
|
63
|
-
# 删除临时项目文件夹
|
64
|
-
FileUtils.remove_dir(temp_proj_path, true)
|
65
|
-
end
|
66
|
-
end
|