cocoapods-meitu-bin 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +20 -0
- data/README.md +56 -0
- data/lib/cocoapods-meitu-bin/command/bin/archive.rb +206 -0
- data/lib/cocoapods-meitu-bin/command/bin/auto.rb +212 -0
- data/lib/cocoapods-meitu-bin/command/bin/build_all.rb +345 -0
- data/lib/cocoapods-meitu-bin/command/bin/header_files_specifications.rb +262 -0
- data/lib/cocoapods-meitu-bin/command/bin/init.rb +72 -0
- data/lib/cocoapods-meitu-bin/command/bin/install.rb +44 -0
- data/lib/cocoapods-meitu-bin/command/bin/lib/lint.rb +67 -0
- data/lib/cocoapods-meitu-bin/command/bin/lock/dependency.rb +89 -0
- data/lib/cocoapods-meitu-bin/command/bin/lock/spec_repo.rb +105 -0
- data/lib/cocoapods-meitu-bin/command/bin/lock/version.rb +68 -0
- data/lib/cocoapods-meitu-bin/command/bin/lock.rb +36 -0
- data/lib/cocoapods-meitu-bin/command/bin/output_source.rb +146 -0
- data/lib/cocoapods-meitu-bin/command/bin/repo/push.rb +88 -0
- data/lib/cocoapods-meitu-bin/command/bin/repo/update.rb +42 -0
- data/lib/cocoapods-meitu-bin/command/bin/repo.rb +14 -0
- data/lib/cocoapods-meitu-bin/command/bin/source/add.rb +148 -0
- data/lib/cocoapods-meitu-bin/command/bin/source/delete.rb +59 -0
- data/lib/cocoapods-meitu-bin/command/bin/source/list.rb +46 -0
- data/lib/cocoapods-meitu-bin/command/bin/source.rb +30 -0
- data/lib/cocoapods-meitu-bin/command/bin/spec/create.rb +73 -0
- data/lib/cocoapods-meitu-bin/command/bin/spec/lint.rb +109 -0
- data/lib/cocoapods-meitu-bin/command/bin/spec.rb +13 -0
- data/lib/cocoapods-meitu-bin/command/bin/update.rb +154 -0
- data/lib/cocoapods-meitu-bin/command/bin/upload.rb +175 -0
- data/lib/cocoapods-meitu-bin/command/bin.rb +69 -0
- data/lib/cocoapods-meitu-bin/command.rb +1 -0
- data/lib/cocoapods-meitu-bin/config/config.rb +149 -0
- data/lib/cocoapods-meitu-bin/config/config_asker.rb +57 -0
- data/lib/cocoapods-meitu-bin/config/config_builder.rb +216 -0
- data/lib/cocoapods-meitu-bin/gem_version.rb +9 -0
- data/lib/cocoapods-meitu-bin/helpers/Info.plist +0 -0
- data/lib/cocoapods-meitu-bin/helpers/buildAll/bin_helper.rb +97 -0
- data/lib/cocoapods-meitu-bin/helpers/buildAll/builder.rb +434 -0
- data/lib/cocoapods-meitu-bin/helpers/buildAll/podspec_util.rb +140 -0
- data/lib/cocoapods-meitu-bin/helpers/buildAll/zip_file_helper.rb +87 -0
- data/lib/cocoapods-meitu-bin/helpers/build_helper.rb +167 -0
- data/lib/cocoapods-meitu-bin/helpers/build_utils.rb +64 -0
- data/lib/cocoapods-meitu-bin/helpers/framework.rb +86 -0
- data/lib/cocoapods-meitu-bin/helpers/framework_builder.rb +551 -0
- data/lib/cocoapods-meitu-bin/helpers/library.rb +54 -0
- data/lib/cocoapods-meitu-bin/helpers/library_builder.rb +90 -0
- data/lib/cocoapods-meitu-bin/helpers/pod_size_helper.rb +54 -0
- data/lib/cocoapods-meitu-bin/helpers/sources_helper.rb +35 -0
- data/lib/cocoapods-meitu-bin/helpers/spec_creator.rb +170 -0
- data/lib/cocoapods-meitu-bin/helpers/spec_files_helper.rb +80 -0
- data/lib/cocoapods-meitu-bin/helpers/spec_source_creator.rb +304 -0
- data/lib/cocoapods-meitu-bin/helpers/upload_helper.rb +104 -0
- data/lib/cocoapods-meitu-bin/helpers.rb +5 -0
- data/lib/cocoapods-meitu-bin/native/acknowledgements.rb +27 -0
- data/lib/cocoapods-meitu-bin/native/analyzer.rb +109 -0
- data/lib/cocoapods-meitu-bin/native/file_accessor.rb +28 -0
- data/lib/cocoapods-meitu-bin/native/gen.rb +79 -0
- data/lib/cocoapods-meitu-bin/native/installation_options.rb +28 -0
- data/lib/cocoapods-meitu-bin/native/installer.rb +259 -0
- data/lib/cocoapods-meitu-bin/native/linter.rb +26 -0
- data/lib/cocoapods-meitu-bin/native/lockfile.rb +85 -0
- data/lib/cocoapods-meitu-bin/native/path_source.rb +33 -0
- data/lib/cocoapods-meitu-bin/native/pod_source_installer.rb +19 -0
- data/lib/cocoapods-meitu-bin/native/pod_target_installer.rb +87 -0
- data/lib/cocoapods-meitu-bin/native/podfile.rb +99 -0
- data/lib/cocoapods-meitu-bin/native/podfile_env.rb +38 -0
- data/lib/cocoapods-meitu-bin/native/podfile_generator.rb +201 -0
- data/lib/cocoapods-meitu-bin/native/podspec_finder.rb +25 -0
- data/lib/cocoapods-meitu-bin/native/resolver.rb +299 -0
- data/lib/cocoapods-meitu-bin/native/sandbox_analyzer.rb +34 -0
- data/lib/cocoapods-meitu-bin/native/source.rb +35 -0
- data/lib/cocoapods-meitu-bin/native/sources_manager.rb +21 -0
- data/lib/cocoapods-meitu-bin/native/specification.rb +31 -0
- data/lib/cocoapods-meitu-bin/native/target_validator.rb +41 -0
- data/lib/cocoapods-meitu-bin/native/validator.rb +40 -0
- data/lib/cocoapods-meitu-bin/native.rb +26 -0
- data/lib/cocoapods-meitu-bin/source_provider_hook.rb +68 -0
- data/lib/cocoapods-meitu-bin.rb +2 -0
- data/lib/cocoapods_plugin.rb +11 -0
- data/spec/command/bin_spec.rb +12 -0
- data/spec/spec_helper.rb +50 -0
- metadata +201 -0
@@ -0,0 +1,175 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'cocoapods-meitu-bin/helpers/buildAll/bin_helper'
|
3
|
+
|
4
|
+
module Pod
|
5
|
+
class Command
|
6
|
+
class Bin < Command
|
7
|
+
class Upload < Bin
|
8
|
+
include Pod
|
9
|
+
|
10
|
+
self.summary = "上传二进制文件及podspec"
|
11
|
+
self.description = <<-DESC
|
12
|
+
#{self.summary}
|
13
|
+
|
14
|
+
`NAME`: 库名【必填】\n
|
15
|
+
`VERSION`: 版本号【必填】\n
|
16
|
+
`FILE`: 需要压缩的二进制文件或目录【必填】\n
|
17
|
+
`REPO`: 上传podspec的仓库,可以通过`pod repo list`查看【必填】\n
|
18
|
+
|
19
|
+
e.g.:\n
|
20
|
+
pod bin upload Pod1 1.0.0 Pod1.framework mtxxspecs --spec=Pod1.podspec
|
21
|
+
DESC
|
22
|
+
|
23
|
+
self.arguments = [
|
24
|
+
CLAide::Argument.new('NAME', true ),
|
25
|
+
CLAide::Argument.new('VERSION', true),
|
26
|
+
CLAide::Argument.new('FILE', true),
|
27
|
+
CLAide::Argument.new('REPO', true)
|
28
|
+
]
|
29
|
+
|
30
|
+
def self.options
|
31
|
+
[
|
32
|
+
%w[--spec=SPEC 指定podspec文件路径,如果不指定,将在当前目录下查找]
|
33
|
+
].concat(super)
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize(argv)
|
37
|
+
@name = argv.shift_argument
|
38
|
+
@version = argv.shift_argument
|
39
|
+
@file = argv.shift_argument
|
40
|
+
@repo = argv.shift_argument
|
41
|
+
@spec = argv.option('spec', nil)
|
42
|
+
@xcode_version = CBin::BuildAll::BinHelper.xcode_version
|
43
|
+
super
|
44
|
+
end
|
45
|
+
|
46
|
+
def run
|
47
|
+
# 参数检查
|
48
|
+
argvsCheck
|
49
|
+
# 压缩文件
|
50
|
+
zip_file
|
51
|
+
# 上传文件
|
52
|
+
upload_zip_file
|
53
|
+
# 修改podspec
|
54
|
+
modify_spec
|
55
|
+
# 上传podspec
|
56
|
+
upload_spec
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
# 参数检查
|
62
|
+
def argvsCheck
|
63
|
+
raise Informative, "name不能为空" if @name.nil?
|
64
|
+
raise Informative, "version不能为空" if @version.nil?
|
65
|
+
raise Informative, "repo不能为空" if @repo.nil?
|
66
|
+
raise Informative, "未找到需要压缩的二进制文件" if @file.nil?
|
67
|
+
raise Informative, "未找到podspec文件" unless File.exist?(podspec)
|
68
|
+
end
|
69
|
+
|
70
|
+
# 压缩文件
|
71
|
+
def zip_file
|
72
|
+
UI.title "压缩二进制文件`#{zip_file_name}`".yellow do
|
73
|
+
output_zip_file = File.join(Dir.pwd, zip_file_name)
|
74
|
+
FileUtils.rm_f(output_zip_file) if File.exist?(output_zip_file)
|
75
|
+
command = "zip --symlinks -r #{zip_file_name} #{@file}"
|
76
|
+
UI.info "#{command}"
|
77
|
+
`#{command}`
|
78
|
+
raise Informative, "压缩二进制文件失败" unless File.exist?(output_zip_file)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# 压缩后的zip包名
|
83
|
+
def zip_file_name
|
84
|
+
@zip_file_name ||= begin
|
85
|
+
"#{@name}_#{@version}.zip"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# 上传文件
|
90
|
+
def upload_zip_file
|
91
|
+
UI.title "上传二进制文件`#{zip_file_name}`".yellow do
|
92
|
+
zip_file = File.join(Dir.pwd, zip_file_name)
|
93
|
+
raise Informative, "`#{@zip_file_name}`不存在" unless File.exist?(zip_file)
|
94
|
+
upload_url = CBin.config.binary_upload_url_str
|
95
|
+
command = "curl -F \"name=#{@name}\" -F \"version=#{@version}\" -F \"file=@#{zip_file}\" #{upload_url}"
|
96
|
+
UI.info "#{command}"
|
97
|
+
json = `#{command}`
|
98
|
+
UI.info json
|
99
|
+
begin
|
100
|
+
error_code = JSON.parse(json)["error_code"]
|
101
|
+
raise Informative, "`#{zip_file_name}`上传失败" unless error_code == 0
|
102
|
+
UI.info "`#{zip_file_name}`上传成功".green
|
103
|
+
rescue JSON::ParserError => e
|
104
|
+
raise Informative, "`#{zip_file_name}`上传失败\n#{e.to_s}"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# 修改podspec
|
110
|
+
def modify_spec
|
111
|
+
UI.title "修改podspec:`#{podspec}`".yellow do
|
112
|
+
spec = Specification.from_file(podspec)
|
113
|
+
spec_hash = spec.to_hash
|
114
|
+
spec_hash['version'] = @version
|
115
|
+
spec_hash['source'] = source
|
116
|
+
spec = Specification.from_hash(spec_hash)
|
117
|
+
write_podspec_json(spec)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# 写入podspec
|
122
|
+
def write_podspec_json(spec)
|
123
|
+
FileUtils.rm_f(podspec_json_file) if File.exist?(podspec_json_file)
|
124
|
+
File.open(podspec_json_file, "w+") do |f|
|
125
|
+
f.write(spec.to_pretty_json)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def source
|
130
|
+
url = "#{CBin.config.binary_download_url_str}/#{@xcode_version}/#{@name}/#{@version}/#{zip_file_name}"
|
131
|
+
{ http: url, type: CBin.config.download_file_type }
|
132
|
+
end
|
133
|
+
|
134
|
+
# 上传podspec
|
135
|
+
def upload_spec
|
136
|
+
UI.title "推送podspec:`#{podspec_json_file_name}`".yellow do
|
137
|
+
raise Informative, "`#{podspec_json_file_name}`不存在" unless File.exist?(podspec_json_file)
|
138
|
+
argvs = %W[#{@repo} #{podspec_json_file} --skip-import-validation --use-libraries --allow-warnings --verbose]
|
139
|
+
|
140
|
+
begin
|
141
|
+
push = Pod::Command::Repo::Push.new(CLAide::ARGV.new(argvs))
|
142
|
+
push.validate!
|
143
|
+
push.run
|
144
|
+
rescue Pod::StandardError => e
|
145
|
+
raise Informative, "推送podspec:`#{podspec_json_file_name}失败\n#{e.to_s}"
|
146
|
+
end
|
147
|
+
# 上传完成后,清理工作目录
|
148
|
+
FileUtils.rm_f(podspec_json_file) if File.exist?(podspec_json_file)
|
149
|
+
FileUtils.rm_r('binary') if File.exist?('binary')
|
150
|
+
FileUtils.rm_f(zip_file_name) if File.exist?(zip_file_name)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def binary_dir
|
155
|
+
File.join(Dir.pwd, 'binary')
|
156
|
+
end
|
157
|
+
|
158
|
+
def podspec_json_file_name
|
159
|
+
"#{@name}.podspec.json"
|
160
|
+
end
|
161
|
+
|
162
|
+
def podspec_json_file
|
163
|
+
File.join(Dir.pwd, podspec_json_file_name)
|
164
|
+
end
|
165
|
+
|
166
|
+
def podspec
|
167
|
+
@spec ||= begin
|
168
|
+
"#{@name}.podspec"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'cocoapods-meitu-bin/command/bin/init'
|
2
|
+
# require 'cocoapods-meitu-bin/command/bin/archive'
|
3
|
+
# require 'cocoapods-meitu-bin/command/bin/auto'
|
4
|
+
# require 'cocoapods-meitu-bin/command/bin/code'
|
5
|
+
# require 'cocoapods-meitu-bin/command/bin/update'
|
6
|
+
# require 'cocoapods-meitu-bin/command/bin/install'
|
7
|
+
require 'cocoapods-meitu-bin/command/bin/repo'
|
8
|
+
require 'cocoapods-meitu-bin/command/bin/spec'
|
9
|
+
require 'cocoapods-meitu-bin/command/bin/build_all'
|
10
|
+
require 'cocoapods-meitu-bin/command/bin/output_source'
|
11
|
+
require 'cocoapods-meitu-bin/command/bin/header_files_specifications'
|
12
|
+
require 'cocoapods-meitu-bin/command/bin/upload'
|
13
|
+
require 'cocoapods-meitu-bin/command/bin/lock'
|
14
|
+
require 'cocoapods-meitu-bin/command/bin/source'
|
15
|
+
require 'cocoapods-meitu-bin/helpers'
|
16
|
+
require 'cocoapods-meitu-bin/helpers/framework_builder'
|
17
|
+
|
18
|
+
module Pod
|
19
|
+
class Command
|
20
|
+
# This is an example of a cocoapods plugin adding a top-level subcommand
|
21
|
+
# to the 'pod' command.
|
22
|
+
#
|
23
|
+
# You can also create subcommands of existing or new commands. Say you
|
24
|
+
# wanted to add a subcommand to `list` to show newly deprecated pods,
|
25
|
+
# (e.g. `pod list deprecated`), there are a few things that would need
|
26
|
+
# to change.
|
27
|
+
#
|
28
|
+
# - move this file to `lib/pod/command/list/deprecated.rb` and update
|
29
|
+
# the class to exist in the the Pod::Command::List namespace
|
30
|
+
# - change this class to extend from `List` instead of `Command`. This
|
31
|
+
# tells the plugin system that it is a subcommand of `list`.
|
32
|
+
# - edit `lib/cocoapods_plugins.rb` to require this file
|
33
|
+
#
|
34
|
+
# @todo Create a PR to add your plugin to CocoaPods/cocoapods.org
|
35
|
+
# in the `plugins.json` file, once your plugin is released.
|
36
|
+
#
|
37
|
+
class Bin < Command
|
38
|
+
include CBin::SourcesHelper
|
39
|
+
include CBin::SpecFilesHelper
|
40
|
+
|
41
|
+
self.abstract_command = true
|
42
|
+
|
43
|
+
# self.default_subcommand = 'open'
|
44
|
+
self.summary = '组件二进制化插件'
|
45
|
+
# self.description = <<-DESC.strip_heredoc
|
46
|
+
# 组件二进制化插件
|
47
|
+
#
|
48
|
+
# 利用源码私有源与二进制私有源实现对组件依赖类型的切换
|
49
|
+
# DESC
|
50
|
+
|
51
|
+
def initialize(argv)
|
52
|
+
# !!! 下面这个require必须放在这里,不能放到文件顶部,切记 !!!
|
53
|
+
require 'cocoapods-meitu-bin/native'
|
54
|
+
|
55
|
+
# @help = argv.flag?('help')
|
56
|
+
super
|
57
|
+
# @env = argv.option('env') || 'dev'
|
58
|
+
# CBin.config.set_configuration_env(@env)
|
59
|
+
# msg = "cocoapods-meitu-bin #{CBin::VERSION} 版本 #{@env} 环境"
|
60
|
+
# UI.info "\033[44;30m#{msg}\033[0m\n"
|
61
|
+
end
|
62
|
+
|
63
|
+
# def validate!
|
64
|
+
# super
|
65
|
+
# banner! if @help
|
66
|
+
# end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'cocoapods-meitu-bin/command/bin'
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'cocoapods-meitu-bin/native/podfile'
|
3
|
+
require 'cocoapods-meitu-bin/native/podfile_env'
|
4
|
+
require 'cocoapods/generate'
|
5
|
+
|
6
|
+
module CBin
|
7
|
+
class Config
|
8
|
+
def config_file
|
9
|
+
config_file_with_configuration_env(configuration_env)
|
10
|
+
end
|
11
|
+
|
12
|
+
def template_hash
|
13
|
+
{
|
14
|
+
'configuration_env' => { description: '编译环境', default: 'dev', selection: %w[dev debug_iphoneos release_iphoneos] },
|
15
|
+
'binary_repo_url' => { description: '二进制podspec私有源地址', default: 'git@github.com:Zhangyanshen/example-private-spec-bin.git' },
|
16
|
+
'binary_upload_url' => { description: '二进制文件上传地址', default: 'http://localhost:8080/frameworks' },
|
17
|
+
'binary_download_url' => { description: '二进制文件下载地址,后面会依次传入Xcode版本、configuration、组件名称与组件版本', default: 'http://localhost:8080/frameworks' },
|
18
|
+
'download_file_type' => { description: '二进制文件类型', default: 'zip', selection: %w[zip tgz tar tbz txz dmg] }
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def config_file_with_configuration_env(configuration_env)
|
23
|
+
file = config_dev_file
|
24
|
+
if configuration_env == "release_iphoneos"
|
25
|
+
file = config_release_iphoneos_file
|
26
|
+
elsif configuration_env == "debug_iphoneos"
|
27
|
+
file = config_debug_iphoneos_file
|
28
|
+
elsif configuration_env == "dev"
|
29
|
+
file = config_dev_file
|
30
|
+
else
|
31
|
+
raise "===== #{configuration_env} %w[dev debug_iphoneos release_iphoneos]===="
|
32
|
+
end
|
33
|
+
|
34
|
+
File.expand_path("#{Pod::Config.instance.project_root}/#{file}")
|
35
|
+
end
|
36
|
+
|
37
|
+
def configuration_env
|
38
|
+
#如果是dev 再去 podfile的配置文件中获取,确保是正确的, pod update时会用到
|
39
|
+
if @configuration_env == "dev" || @configuration_env == nil
|
40
|
+
if Pod::Config.instance.podfile
|
41
|
+
configuration_env ||= Pod::Config.instance.podfile.configuration_env
|
42
|
+
end
|
43
|
+
configuration_env ||= "dev"
|
44
|
+
@configuration_env = configuration_env
|
45
|
+
end
|
46
|
+
@configuration_env
|
47
|
+
end
|
48
|
+
|
49
|
+
# 上传二进制的url
|
50
|
+
def binary_upload_url_str
|
51
|
+
CBin.config.binary_upload_url
|
52
|
+
end
|
53
|
+
|
54
|
+
# 下载二进制的url
|
55
|
+
def binary_download_url_str
|
56
|
+
CBin.config.binary_download_url
|
57
|
+
end
|
58
|
+
|
59
|
+
def set_configuration_env(env)
|
60
|
+
@configuration_env = env
|
61
|
+
end
|
62
|
+
|
63
|
+
#包含arm64 armv7架构,xcodebuild 是Debug模式
|
64
|
+
def config_debug_iphoneos_file
|
65
|
+
".bin_debug_iphoneos.yml"
|
66
|
+
end
|
67
|
+
#包含arm64 armv7架构,xcodebuild 是Release模式
|
68
|
+
def config_release_iphoneos_file
|
69
|
+
".bin_release_iphoneos.yml"
|
70
|
+
end
|
71
|
+
#包含x86 arm64 armv7架构,xcodebuild 是Release模式
|
72
|
+
def config_dev_file
|
73
|
+
".bin_dev.yml"
|
74
|
+
end
|
75
|
+
|
76
|
+
# 配置信息写入文件
|
77
|
+
def sync_config(config)
|
78
|
+
File.open(config_file_with_configuration_env(config['configuration_env']), 'w+') do |f|
|
79
|
+
f.write(config.to_yaml)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# def sync_config_code_repo_url_list(config)
|
84
|
+
# File.open(config_file_with_configuration_env_list(config['code_repo_url_list']), 'w+') do |f|
|
85
|
+
# f.write(config.to_yaml)
|
86
|
+
# end
|
87
|
+
# end
|
88
|
+
|
89
|
+
def default_config
|
90
|
+
@default_config ||= Hash[template_hash.map { |k, v| [k, v[:default]] }]
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def load_config
|
96
|
+
if File.exist?(config_file)
|
97
|
+
YAML.load_file(config_file)
|
98
|
+
else
|
99
|
+
default_config
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def config
|
104
|
+
@config ||= begin
|
105
|
+
@config = OpenStruct.new load_config
|
106
|
+
validate!
|
107
|
+
@config
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def validate!
|
112
|
+
template_hash.each do |k, v|
|
113
|
+
selection = v[:selection]
|
114
|
+
next if !selection || selection.empty?
|
115
|
+
|
116
|
+
config_value = @config.send(k)
|
117
|
+
next unless config_value
|
118
|
+
unless selection.include?(config_value)
|
119
|
+
raise Pod::Informative, "#{k} 字段的值必须限定在可选值 [ #{selection.join(' / ')} ] 内".red
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def respond_to_missing?(method, include_private = false)
|
125
|
+
config.respond_to?(method) || super
|
126
|
+
end
|
127
|
+
|
128
|
+
def method_missing(method, *args, &block)
|
129
|
+
if config.respond_to?(method)
|
130
|
+
config.send(method, *args)
|
131
|
+
elsif template_hash.keys.include?(method.to_s)
|
132
|
+
raise Pod::Informative, "#{method} 字段必须在配置文件 #{config_file} 中设置, 请执行 init 命令配置或手动修改配置文件".red
|
133
|
+
else
|
134
|
+
super
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
public
|
139
|
+
|
140
|
+
# 判断配置文件是否存在
|
141
|
+
def config_file_exist?
|
142
|
+
raise Pod::Informative, "当前目录下没有配置文件,请先执行`pod bin init`" unless File.exist?(config_file)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def self.config
|
147
|
+
@config ||= Config.new
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'cocoapods-meitu-bin/config/config'
|
3
|
+
|
4
|
+
module CBin
|
5
|
+
class Config
|
6
|
+
class Asker
|
7
|
+
def show_prompt
|
8
|
+
print ' > '.green
|
9
|
+
end
|
10
|
+
|
11
|
+
def ask_with_answer(question, pre_answer, selection)
|
12
|
+
print "\n#{question}\n"
|
13
|
+
|
14
|
+
print_selection_info = lambda {
|
15
|
+
print "可选值:[ #{selection.join(' / ')} ]\n" if selection
|
16
|
+
}
|
17
|
+
print_selection_info.call
|
18
|
+
print "旧值:#{pre_answer}\n" unless pre_answer.nil?
|
19
|
+
|
20
|
+
answer = ''
|
21
|
+
loop do
|
22
|
+
show_prompt
|
23
|
+
answer = STDIN.gets.chomp.strip
|
24
|
+
|
25
|
+
if answer == '' && !pre_answer.nil?
|
26
|
+
answer = pre_answer
|
27
|
+
print answer.yellow
|
28
|
+
print "\n"
|
29
|
+
end
|
30
|
+
|
31
|
+
next if answer.empty?
|
32
|
+
break if !selection || selection.include?(answer)
|
33
|
+
|
34
|
+
print_selection_info.call
|
35
|
+
end
|
36
|
+
|
37
|
+
answer
|
38
|
+
end
|
39
|
+
|
40
|
+
def welcome_message
|
41
|
+
print <<~EOF
|
42
|
+
|
43
|
+
设置插件配置信息.
|
44
|
+
所有的信息都会保存在 #{CBin.config.config_file} 文件中.
|
45
|
+
你可以在对应目录下手动添加编辑该文件.
|
46
|
+
文件包含的配置信息样式如下:
|
47
|
+
|
48
|
+
#{CBin.config.default_config.to_yaml}
|
49
|
+
EOF
|
50
|
+
end
|
51
|
+
|
52
|
+
def done_message
|
53
|
+
print "\n设置完成.\n".green
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,216 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module CBin
|
4
|
+
class Config
|
5
|
+
class Builder
|
6
|
+
|
7
|
+
include Pod
|
8
|
+
|
9
|
+
def self.instance
|
10
|
+
@instance ||= new
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
load_build_config
|
15
|
+
# clean
|
16
|
+
end
|
17
|
+
|
18
|
+
# 加载配置项
|
19
|
+
def load_build_config
|
20
|
+
@white_pod_list = []
|
21
|
+
@ignore_git_list = []
|
22
|
+
project_root = Pod::Config.instance.project_root
|
23
|
+
path = File.join(project_root.to_s, 'BinArchive.json')
|
24
|
+
|
25
|
+
if File.exist?(path)
|
26
|
+
config = JSON.parse(File.read(path))
|
27
|
+
@white_pod_list = config['archive-white-pod-list']
|
28
|
+
UI.warn "====== archive-white-pod-list = #{@white_pod_list}" if @white_pod_list
|
29
|
+
@ignore_git_list = config['ignore-git-list']
|
30
|
+
UI.warn "====== ignore_git_list = #{@ignore_git_list}" if @ignore_git_list
|
31
|
+
@ignore_http_list = config['ignore-http-list']
|
32
|
+
|
33
|
+
@xcode_build_name = config['xcode_build_path']
|
34
|
+
@root_dir = config['root_dir'] unless config['root_dir'].nil?
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def clean
|
40
|
+
#清除之前的缓存
|
41
|
+
FileUtils.rm_rf(Dir.glob("#{zip_dir}/*")) if File.exist?(zip_dir)
|
42
|
+
FileUtils.rm_rf(Dir.glob("#{binary_json_dir}/*")) if File.exist?(binary_json_dir)
|
43
|
+
FileUtils.rm_rf(Dir.glob("#{local_psec_dir}/*")) if File.exist?(local_psec_dir)
|
44
|
+
end
|
45
|
+
|
46
|
+
# 制作二进制打包 工程目录
|
47
|
+
def gen_name
|
48
|
+
'bin-archive'
|
49
|
+
end
|
50
|
+
|
51
|
+
# 制作二进制打包 工程目录
|
52
|
+
def gen_dir
|
53
|
+
@gen_dir ||= begin
|
54
|
+
dir = File.join(root_dir,gen_name)
|
55
|
+
Dir.mkdir(dir) unless File.exist?dir
|
56
|
+
Pathname.new(dir)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def framework_name(spec)
|
62
|
+
"#{spec.module_name}.framework"
|
63
|
+
end
|
64
|
+
|
65
|
+
def framework_name_version(spec)
|
66
|
+
"#{spec.module_name}.framework_#{spec.version}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def framework_zip_file(spec)
|
70
|
+
File.join(zip_dir_name, framework_name_version(spec))
|
71
|
+
end
|
72
|
+
|
73
|
+
def framework_file(spec)
|
74
|
+
File.join(zip_dir_name, framework_name(spec))
|
75
|
+
end
|
76
|
+
|
77
|
+
def library_name(spec)
|
78
|
+
library_name_version(spec.name, spec.version)
|
79
|
+
end
|
80
|
+
|
81
|
+
def library_name_version(name,version)
|
82
|
+
"bin_#{name}_#{version}"
|
83
|
+
end
|
84
|
+
def library_file(spec)
|
85
|
+
File.join(zip_dir_name, library_name(spec))
|
86
|
+
end
|
87
|
+
|
88
|
+
def zip_dir_name
|
89
|
+
"bin-zip"
|
90
|
+
end
|
91
|
+
|
92
|
+
def zip_dir
|
93
|
+
@zip_dir ||= begin
|
94
|
+
dir = File.join(root_dir,zip_dir_name)
|
95
|
+
Dir.mkdir(dir) unless File.exist?dir
|
96
|
+
Pathname.new(dir)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
#本地
|
101
|
+
def local_spec_dir_name
|
102
|
+
"bin-spec"
|
103
|
+
end
|
104
|
+
|
105
|
+
def local_psec_dir
|
106
|
+
@local_psec_dir ||= begin
|
107
|
+
dir = File.join(root_dir,local_spec_dir_name)
|
108
|
+
Dir.mkdir(dir) unless File.exist?dir
|
109
|
+
Pathname.new(dir)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def binary_json_dir_name
|
114
|
+
"bin-json"
|
115
|
+
end
|
116
|
+
|
117
|
+
def binary_json_dir
|
118
|
+
@binary_json_dir ||= begin
|
119
|
+
dir = File.join(root_dir,binary_json_dir_name)
|
120
|
+
Dir.mkdir(dir) unless File.exist?dir
|
121
|
+
Pathname.new(dir)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
#编译target名,如 seeyou
|
128
|
+
def target_name
|
129
|
+
@target_name ||= begin
|
130
|
+
target_name_str = Pod::Config.instance.podfile.root_target_definitions.first.children.first.to_s
|
131
|
+
target_name_str[5,target_name_str.length]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
#编译缓存文件目录,如Xcodebuild的编译缓存目录
|
136
|
+
# 如果有配置, 配置完整路径,会使用
|
137
|
+
def xcode_build_name
|
138
|
+
@xcode_build_name ||= begin
|
139
|
+
project_root = Pod::Config.instance.project_root
|
140
|
+
path = File.join(project_root.to_s, 'BinArchive.json')
|
141
|
+
|
142
|
+
if File.exist?(path)
|
143
|
+
config = JSON.parse(File.read(path))
|
144
|
+
@xcode_build_name = config['xcode_build_path']
|
145
|
+
end
|
146
|
+
#默认值,在美柚上使用默认
|
147
|
+
if @xcode_build_name.nil? || Dir.exist?(@xcode_build_name)
|
148
|
+
@xcode_build_name = "xcode-build/Build/Intermediates.noindex/ArchiveIntermediates/#{target_name}/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/"
|
149
|
+
end
|
150
|
+
puts @xcode_build_name
|
151
|
+
@xcode_build_name
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
#完整的xcodebuild 输出路径
|
157
|
+
def xcode_build_dir
|
158
|
+
@xcode_build_dir ||= begin
|
159
|
+
temp_xcode_build_name = xcode_build_name
|
160
|
+
if File.exist?(temp_xcode_build_name)
|
161
|
+
Pathname.new(temp_xcode_build_name)
|
162
|
+
else
|
163
|
+
dir = File.join(root_dir,xcode_build_name)
|
164
|
+
Pathname.new(dir)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
#完整的xcodebuild BuildProductsPath输出路径,
|
169
|
+
def xcode_BuildProductsPath_dir
|
170
|
+
@xcode_BuildProductsPath_dir ||= begin
|
171
|
+
temp_xcode_BuildProductsPath_dir = "xcode-build/Build/Intermediates.noindex/ArchiveIntermediates/#{target_name}/BuildProductsPath/"
|
172
|
+
full_path = File.join(root_dir, temp_xcode_BuildProductsPath_dir)
|
173
|
+
|
174
|
+
if (File.exist?(full_path))
|
175
|
+
Dir.chdir(full_path) do
|
176
|
+
iphoneos = Dir.glob('*-iphoneos')
|
177
|
+
if iphoneos.length > 0
|
178
|
+
full_path = File.join(full_path,iphoneos.first)
|
179
|
+
else
|
180
|
+
UI.warn "====== 找不到 *-iphoneos @xcode_BuildProductsPath_dir = #{@xcode_BuildProductsPath_dir}"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
Pathname.new(full_path)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
#处理编译产物后存储根目录,会存放spec、 json、zip的父目录,默认是工程的同级目录下,"#{basename}-build-temp"
|
190
|
+
def root_dir
|
191
|
+
@root_dir ||= begin
|
192
|
+
basename = File.basename(Pod::Config.instance.installation_root)
|
193
|
+
parent_dir = File.dirname(Pod::Config.instance.installation_root)
|
194
|
+
root_name = File.join(parent_dir,"#{basename}-build-temp")
|
195
|
+
Dir.mkdir(root_name) unless File.exist?root_name
|
196
|
+
Pathname.new(root_name)
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
#制作二进制 白名单
|
202
|
+
def white_pod_list
|
203
|
+
@white_pod_list
|
204
|
+
end
|
205
|
+
#忽略制作二进制组件的 git
|
206
|
+
def ignore_git_list
|
207
|
+
@ignore_git_list
|
208
|
+
end
|
209
|
+
|
210
|
+
def ignore_http_list
|
211
|
+
@ignore_http_list
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
Binary file
|