cocoapods-fy-bin 0.0.1

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.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +22 -0
  3. data/README.md +1 -0
  4. data/lib/cocoapods-fy-bin/command/bin/archive.rb +202 -0
  5. data/lib/cocoapods-fy-bin/command/bin/auto.rb +204 -0
  6. data/lib/cocoapods-fy-bin/command/bin/code.rb +232 -0
  7. data/lib/cocoapods-fy-bin/command/bin/imy.rb +46 -0
  8. data/lib/cocoapods-fy-bin/command/bin/init.rb +69 -0
  9. data/lib/cocoapods-fy-bin/command/bin/initHotKey.rb +70 -0
  10. data/lib/cocoapods-fy-bin/command/bin/install.rb +44 -0
  11. data/lib/cocoapods-fy-bin/command/bin/lib/lint.rb +69 -0
  12. data/lib/cocoapods-fy-bin/command/bin/repo/update.rb +43 -0
  13. data/lib/cocoapods-fy-bin/command/bin/spec/create.rb +73 -0
  14. data/lib/cocoapods-fy-bin/command/bin/spec/push.rb +114 -0
  15. data/lib/cocoapods-fy-bin/command/bin/update.rb +154 -0
  16. data/lib/cocoapods-fy-bin/command/bin.rb +59 -0
  17. data/lib/cocoapods-fy-bin/command.rb +2 -0
  18. data/lib/cocoapods-fy-bin/config/config.rb +137 -0
  19. data/lib/cocoapods-fy-bin/config/config_asker.rb +57 -0
  20. data/lib/cocoapods-fy-bin/config/config_builder.rb +228 -0
  21. data/lib/cocoapods-fy-bin/config/config_hot_key.rb +103 -0
  22. data/lib/cocoapods-fy-bin/config/config_hot_key_asker.rb +57 -0
  23. data/lib/cocoapods-fy-bin/gem_version.rb +10 -0
  24. data/lib/cocoapods-fy-bin/helpers/build_helper.rb +164 -0
  25. data/lib/cocoapods-fy-bin/helpers/build_utils.rb +63 -0
  26. data/lib/cocoapods-fy-bin/helpers/framework.rb +94 -0
  27. data/lib/cocoapods-fy-bin/helpers/framework_builder.rb +419 -0
  28. data/lib/cocoapods-fy-bin/helpers/library.rb +54 -0
  29. data/lib/cocoapods-fy-bin/helpers/library_builder.rb +91 -0
  30. data/lib/cocoapods-fy-bin/helpers/sources_helper.rb +36 -0
  31. data/lib/cocoapods-fy-bin/helpers/spec_creator.rb +170 -0
  32. data/lib/cocoapods-fy-bin/helpers/spec_files_helper.rb +77 -0
  33. data/lib/cocoapods-fy-bin/helpers/spec_source_creator.rb +229 -0
  34. data/lib/cocoapods-fy-bin/helpers/upload_helper.rb +97 -0
  35. data/lib/cocoapods-fy-bin/helpers.rb +5 -0
  36. data/lib/cocoapods-fy-bin/native/acknowledgements.rb +27 -0
  37. data/lib/cocoapods-fy-bin/native/analyzer.rb +55 -0
  38. data/lib/cocoapods-fy-bin/native/file_accessor.rb +28 -0
  39. data/lib/cocoapods-fy-bin/native/installation_options.rb +25 -0
  40. data/lib/cocoapods-fy-bin/native/installer.rb +204 -0
  41. data/lib/cocoapods-fy-bin/native/linter.rb +26 -0
  42. data/lib/cocoapods-fy-bin/native/path_source.rb +33 -0
  43. data/lib/cocoapods-fy-bin/native/pod_source_installer.rb +19 -0
  44. data/lib/cocoapods-fy-bin/native/pod_target_installer.rb +94 -0
  45. data/lib/cocoapods-fy-bin/native/podfile.rb +91 -0
  46. data/lib/cocoapods-fy-bin/native/podfile_env.rb +37 -0
  47. data/lib/cocoapods-fy-bin/native/podfile_generator.rb +199 -0
  48. data/lib/cocoapods-fy-bin/native/podspec_finder.rb +25 -0
  49. data/lib/cocoapods-fy-bin/native/resolver.rb +238 -0
  50. data/lib/cocoapods-fy-bin/native/sandbox_analyzer.rb +34 -0
  51. data/lib/cocoapods-fy-bin/native/source.rb +35 -0
  52. data/lib/cocoapods-fy-bin/native/sources_manager.rb +20 -0
  53. data/lib/cocoapods-fy-bin/native/specification.rb +31 -0
  54. data/lib/cocoapods-fy-bin/native/target_validator.rb +41 -0
  55. data/lib/cocoapods-fy-bin/native/validator.rb +40 -0
  56. data/lib/cocoapods-fy-bin/native.rb +23 -0
  57. data/lib/cocoapods-fy-bin/source_provider_hook.rb +55 -0
  58. data/lib/cocoapods-fy-bin.rb +2 -0
  59. data/lib/cocoapods_plugin.rb +3 -0
  60. data/spec/command/bin_spec.rb +12 -0
  61. data/spec/spec_helper.rb +50 -0
  62. metadata +177 -0
@@ -0,0 +1,59 @@
1
+
2
+ require 'cocoapods-fy-bin/command/bin/initHotKey'
3
+ require 'cocoapods-fy-bin/command/bin/init'
4
+ require 'cocoapods-fy-bin/command/bin/archive'
5
+ require 'cocoapods-fy-bin/command/bin/auto'
6
+ require 'cocoapods-fy-bin/command/bin/code'
7
+ require 'cocoapods-fy-bin/command/bin/update'
8
+ require 'cocoapods-fy-bin/command/bin/install'
9
+ require 'cocoapods-fy-bin/command/bin/imy'
10
+
11
+ require 'cocoapods-fy-bin/helpers'
12
+
13
+ module Pod
14
+ class Command
15
+ # This is an example of a cocoapods plugin adding a top-level subcommand
16
+ # to the 'pod' command.
17
+ #
18
+ # You can also create subcommands of existing or new commands. Say you
19
+ # wanted to add a subcommand to `list` to show newly deprecated pods,
20
+ # (e.g. `pod list deprecated`), there are a few things that would need
21
+ # to change.
22
+ #
23
+ # - move this file to `lib/pod/command/list/deprecated.rb` and update
24
+ # the class to exist in the the Pod::Command::List namespace
25
+ # - change this class to extend from `List` instead of `Command`. This
26
+ # tells the plugin system that it is a subcommand of `list`.
27
+ # - edit `lib/cocoapods_plugins.rb` to require this file
28
+ #
29
+ # @todo Create a PR to add your plugin to CocoaPods/cocoapods.org
30
+ # in the `plugins.json` file, once your plugin is released.
31
+ #
32
+ class Bin < Command
33
+ include CBin::SourcesHelper
34
+ include CBin::SpecFilesHelper
35
+
36
+ self.abstract_command = true
37
+
38
+ self.default_subcommand = 'open'
39
+ self.summary = '组件二进制化插件.'
40
+ self.description = <<-DESC
41
+ 组件二进制化插件。利用源码私有源与二进制私有源实现对组件依赖类型的切换。
42
+ DESC
43
+
44
+ def initialize(argv)
45
+ require 'cocoapods-fy-bin/native'
46
+
47
+ @help = argv.flag?('help')
48
+ super
49
+ end
50
+
51
+ def validate!
52
+ super
53
+ # 这里由于 --help 是在 validate! 方法中提取的,会导致 --help 失效
54
+ # pod lib create 也有这个问题
55
+ banner! if @help
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,2 @@
1
+
2
+ require 'cocoapods-fy-bin/command/bin'
@@ -0,0 +1,137 @@
1
+ require 'yaml'
2
+ require 'cocoapods-fy-bin/native/podfile'
3
+ require 'cocoapods-fy-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
+ 'code_repo_url' => { description: '源码私有源 Git 地址', default: 'git@github.com:su350380433/example_spec_source.git' },
16
+ 'binary_repo_url' => { description: '二进制私有源 Git 地址', default: 'git@github.com:su350380433/example_spec_bin_dev.git' },
17
+ 'binary_download_url' => { description: '二进制下载地址,内部会依次传入组件名称与版本,替换字符串中的 %s ', default: 'http://localhost:8080/frameworks/%s/%s/zip' },
18
+ # 'binary_type' => { description: '二进制打包类型', default: 'framework', selection: %w[framework library] },
19
+ 'download_file_type' => { description: '下载二进制文件类型', default: 'zip', selection: %w[zip tgz tar tbz txz dmg] }
20
+ }
21
+ end
22
+
23
+ def config_file_with_configuration_env(configuration_env)
24
+ file = config_dev_file
25
+ if configuration_env == "release_iphoneos"
26
+ file = config_release_iphoneos_file
27
+ puts "\n====== #{configuration_env} 环境 ========"
28
+ elsif configuration_env == "debug_iphoneos"
29
+ file = config_debug_iphoneos_file
30
+ puts "\n====== #{configuration_env} 环境 ========"
31
+ elsif configuration_env == "dev"
32
+ puts "\n====== #{configuration_env} 环境 ========"
33
+ else
34
+ raise "\n===== #{configuration_env} 参数有误,请检查%w[dev debug_iphoneos release_iphoneos]===="
35
+ end
36
+
37
+ File.expand_path("#{Pod::Config.instance.home_dir}/#{file}")
38
+ end
39
+
40
+ def configuration_env
41
+ #如果是dev 再去 podfile的配置文件中获取,确保是正确的, pod update时会用到
42
+ if @configuration_env == "dev" || @configuration_env == nil
43
+ if Pod::Config.instance.podfile
44
+ configuration_env ||= Pod::Config.instance.podfile.configuration_env
45
+ end
46
+ configuration_env ||= "dev"
47
+ @configuration_env = configuration_env
48
+ end
49
+ @configuration_env
50
+ end
51
+
52
+ #上传的url
53
+ def binary_upload_url
54
+ cut_string = "/%s/%s/zip"
55
+ binary_download_url[0,binary_download_url.length - cut_string.length]
56
+ end
57
+
58
+ def set_configuration_env(env)
59
+ @configuration_env = env
60
+ end
61
+
62
+ #包含arm64 armv7架构,xcodebuild 是Debug模式
63
+ def config_debug_iphoneos_file
64
+ "bin_debug_iphoneos.yml"
65
+ end
66
+ #包含arm64 armv7架构,xcodebuild 是Release模式
67
+ def config_release_iphoneos_file
68
+ "bin_release_iphoneos.yml"
69
+ end
70
+ #包含x86 arm64 armv7架构,xcodebuild 是Release模式
71
+ def config_dev_file
72
+ "bin_dev.yml"
73
+ end
74
+
75
+ def sync_config(config)
76
+ File.open(config_file_with_configuration_env(config['configuration_env']), 'w+') do |f|
77
+ f.write(config.to_yaml)
78
+ end
79
+ end
80
+
81
+ def default_config
82
+ @default_config ||= Hash[template_hash.map { |k, v| [k, v[:default]] }]
83
+ end
84
+
85
+ private
86
+
87
+ def load_config
88
+ if File.exist?(config_file)
89
+ YAML.load_file(config_file)
90
+ else
91
+ default_config
92
+ end
93
+ end
94
+
95
+ def config
96
+ @config ||= begin
97
+ puts "====== cocoapods-fy-bin #{CBin::VERSION} 版本 ======== \n"
98
+ @config = OpenStruct.new load_config
99
+ validate!
100
+ @config
101
+ end
102
+ end
103
+
104
+ def validate!
105
+ template_hash.each do |k, v|
106
+ selection = v[:selection]
107
+ next if !selection || selection.empty?
108
+
109
+ config_value = @config.send(k)
110
+ next unless config_value
111
+ unless selection.include?(config_value)
112
+ raise Pod::Informative, "#{k} 字段的值必须限定在可选值 [ #{selection.join(' / ')} ] 内".red
113
+ end
114
+ end
115
+ end
116
+
117
+ def respond_to_missing?(method, include_private = false)
118
+ config.respond_to?(method) || super
119
+ end
120
+
121
+ def method_missing(method, *args, &block)
122
+ if config.respond_to?(method)
123
+ config.send(method, *args)
124
+ elsif template_hash.keys.include?(method.to_s)
125
+ raise Pod::Informative, "#{method} 字段必须在配置文件 #{config_file} 中设置, 请执行 init 命令配置或手动修改配置文件".red
126
+ else
127
+ super
128
+ end
129
+ end
130
+ end
131
+
132
+ def self.config
133
+ @config ||= Config.new
134
+ end
135
+
136
+
137
+ end
@@ -0,0 +1,57 @@
1
+ require 'yaml'
2
+ require 'cocoapods-fy-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 wellcome_message
41
+ print <<~EOF
42
+
43
+ 开始设置二进制化初始信息.
44
+ 所有的信息都会保存在 #{CBin.config.config_file} 文件中.
45
+ %w[bin_dev.yml bin_debug_iphoneos.yml bin_release_iphoneos.yml]
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,228 @@
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
+ # 处理后的framework文件名称
61
+ def treated_framework_name(spec)
62
+ treated_framework_name = spec.name.sub('-', '_')
63
+ if !spec.module_name.nil?
64
+ treated_framework_name = spec.module_name
65
+ end
66
+ treated_framework_name
67
+ end
68
+
69
+ def framework_name(spec)
70
+ "#{treated_framework_name(spec)}.framework"
71
+ end
72
+
73
+ def framework_dsym_name(spec)
74
+ "#{treated_framework_name(spec)}.framework.dSYM"
75
+ end
76
+
77
+ def framework_name_version(spec)
78
+ "#{treated_framework_name(spec)}.framework_#{spec.version}"
79
+ end
80
+
81
+ def framework_zip_file(spec)
82
+ File.join(zip_dir_name, framework_name_version(spec))
83
+ end
84
+
85
+ def framework_file(spec)
86
+ File.join(zip_dir_name, framework_name(spec))
87
+ end
88
+
89
+ def library_name(spec)
90
+ library_name_version(spec.name, spec.version)
91
+ end
92
+
93
+ def library_name_version(name,version)
94
+ "bin_#{name}_#{version}"
95
+ end
96
+ def library_file(spec)
97
+ File.join(zip_dir_name, library_name(spec))
98
+ end
99
+
100
+ def zip_dir_name
101
+ "bin-zip"
102
+ end
103
+
104
+ def zip_dir
105
+ @zip_dir ||= begin
106
+ dir = File.join(root_dir,zip_dir_name)
107
+ Dir.mkdir(dir) unless File.exist?dir
108
+ Pathname.new(dir)
109
+ end
110
+ end
111
+
112
+ #本地
113
+ def local_spec_dir_name
114
+ "bin-spec"
115
+ end
116
+
117
+ def local_psec_dir
118
+ @local_psec_dir ||= begin
119
+ dir = File.join(root_dir,local_spec_dir_name)
120
+ Dir.mkdir(dir) unless File.exist?dir
121
+ Pathname.new(dir)
122
+ end
123
+ end
124
+
125
+ def binary_json_dir_name
126
+ "bin-json"
127
+ end
128
+
129
+ def binary_json_dir
130
+ @binary_json_dir ||= begin
131
+ dir = File.join(root_dir,binary_json_dir_name)
132
+ Dir.mkdir(dir) unless File.exist?dir
133
+ Pathname.new(dir)
134
+ end
135
+ end
136
+
137
+
138
+
139
+ #编译target名,如 seeyou
140
+ def target_name
141
+ @target_name ||= begin
142
+ target_name_str = Pod::Config.instance.podfile.root_target_definitions.first.children.first.to_s
143
+ target_name_str[5,target_name_str.length]
144
+ end
145
+ end
146
+
147
+ #编译缓存文件目录,如Xcodebuild的编译缓存目录
148
+ # 如果有配置, 配置完整路径,会使用
149
+ def xcode_build_name
150
+ @xcode_build_name ||= begin
151
+ project_root = Pod::Config.instance.project_root
152
+ path = File.join(project_root.to_s, 'BinArchive.json')
153
+
154
+ if File.exist?(path)
155
+ config = JSON.parse(File.read(path))
156
+ @xcode_build_name = config['xcode_build_path']
157
+ end
158
+ #默认值,在美柚上使用默认
159
+ if @xcode_build_name.nil? || Dir.exist?(@xcode_build_name)
160
+ @xcode_build_name = "xcode-build/Build/Intermediates.noindex/ArchiveIntermediates/#{target_name}/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/"
161
+ end
162
+ puts @xcode_build_name
163
+ @xcode_build_name
164
+ end
165
+ end
166
+
167
+
168
+ #完整的xcodebuild 输出路径
169
+ def xcode_build_dir
170
+ @xcode_build_dir ||= begin
171
+ temp_xcode_build_name = xcode_build_name
172
+ if File.exist?(temp_xcode_build_name)
173
+ Pathname.new(temp_xcode_build_name)
174
+ else
175
+ dir = File.join(root_dir,xcode_build_name)
176
+ Pathname.new(dir)
177
+ end
178
+ end
179
+ end
180
+ #完整的xcodebuild BuildProductsPath输出路径,
181
+ def xcode_BuildProductsPath_dir
182
+ @xcode_BuildProductsPath_dir ||= begin
183
+ temp_xcode_BuildProductsPath_dir = "xcode-build/Build/Intermediates.noindex/ArchiveIntermediates/#{target_name}/BuildProductsPath/"
184
+ full_path = File.join(root_dir, temp_xcode_BuildProductsPath_dir)
185
+
186
+ if (File.exist?(full_path))
187
+ Dir.chdir(full_path) do
188
+ iphoneos = Dir.glob('*-iphoneos')
189
+ if iphoneos.length > 0
190
+ full_path = File.join(full_path,iphoneos.first)
191
+ else
192
+ UI.warn "====== 找不到 *-iphoneos @xcode_BuildProductsPath_dir = #{@xcode_BuildProductsPath_dir}"
193
+ end
194
+ end
195
+ end
196
+ Pathname.new(full_path)
197
+ end
198
+ end
199
+
200
+
201
+ #处理编译产物后存储根目录,会存放spec、 json、zip的父目录,默认是工程的同级目录下,"#{basename}-build-temp"
202
+ def root_dir
203
+ @root_dir ||= begin
204
+ basename = File.basename(Pod::Config.instance.installation_root)
205
+ parent_dir = File.dirname(Pod::Config.instance.installation_root)
206
+ root_name = File.join(parent_dir,"#{basename}-build-temp")
207
+ Dir.mkdir(root_name) unless File.exist?root_name
208
+ Pathname.new(root_name)
209
+ end
210
+
211
+ end
212
+
213
+ #制作二进制 白名单
214
+ def white_pod_list
215
+ @white_pod_list
216
+ end
217
+ #忽略制作二进制组件的 git
218
+ def ignore_git_list
219
+ @ignore_git_list
220
+ end
221
+
222
+ def ignore_http_list
223
+ @ignore_http_list
224
+ end
225
+
226
+ end
227
+ end
228
+ end
@@ -0,0 +1,103 @@
1
+ require 'yaml'
2
+ require 'cocoapods-fy-bin/native/podfile'
3
+ require 'cocoapods-fy-bin/native/podfile_env'
4
+ require 'cocoapods/generate'
5
+
6
+ module CBin
7
+ class Config_Hot_Key
8
+
9
+ def config_file
10
+ config_file_with_hot_key_index(hot_key_index)
11
+ end
12
+
13
+ def template_hash
14
+ {
15
+ 'hot_key_index' => { description: '快捷键', default: '1', selection: %w[1 2 3...] },
16
+ 'hot_key_dir' => { description: '快捷键执行目录', default: '' },
17
+ 'hot_key_cmd' => { description: '快捷键执行命令', default: 'pod bin update --no-repo-update' }
18
+ }
19
+ end
20
+
21
+ def config_file_with_hot_key_index(hot_key_index)
22
+ file = config_file_whith_hot_key_index(hot_key_index)
23
+ raise "\n===== #{hot_key_index} 参数有误,请检查%w[1 2 3...]===" unless (hot_key_index.to_i).is_a?(Integer)
24
+ File.expand_path("#{Pod::Config.instance.home_dir}/#{file}")
25
+ end
26
+
27
+ def hot_key_index
28
+ @hot_key_index = 1 if @hot_key_index.is_a?(NilClass)
29
+ @hot_key_index
30
+ end
31
+
32
+ def set_hot_key_index(hot_key_index)
33
+ @hot_key_index = hot_key_index
34
+ end
35
+
36
+ def config_file_whith_hot_key_index(hot_key_index)
37
+ "hot_key_#{hot_key_index}.yml"
38
+ end
39
+
40
+ def sync_config(config)
41
+ File.open(config_file_with_hot_key_index(config['hot_key_index']), 'w+') do |f|
42
+ f.write(config.to_yaml)
43
+ end
44
+ end
45
+
46
+ def default_config
47
+ @default_config ||= Hash[template_hash.map { |k, v| [k, v[:default]] }]
48
+ end
49
+
50
+ private
51
+
52
+ def load_config
53
+ file = config_file
54
+ if (!file.nil?) && File.exist?(config_file)
55
+ YAML.load_file(config_file)
56
+ else
57
+ default_config
58
+ end
59
+ end
60
+
61
+ def config
62
+ @config ||= begin
63
+ puts "====== cocoapods-fy-bin #{CBin::VERSION} 版本 ======== \n"
64
+ @config = OpenStruct.new load_config
65
+ validate!
66
+ @config
67
+ end
68
+ end
69
+
70
+ def validate!
71
+ template_hash.each do |k, v|
72
+ selection = v[:selection]
73
+ next if !selection || selection.empty?
74
+
75
+ config_value = @config.send(k)
76
+ next unless config_value
77
+ unless selection.include?(config_value)
78
+ raise Pod::Informative, "#{k} 字段的值必须限定在可选值 [ #{selection.join(' / ')} ] 内".red
79
+ end
80
+ end
81
+ end
82
+
83
+ def respond_to_missing?(method, include_private = false)
84
+ config.respond_to?(method) || super
85
+ end
86
+
87
+ def method_missing(method, *args, &block)
88
+ if config.respond_to?(method)
89
+ config.send(method, *args)
90
+ elsif template_hash.keys.include?(method.to_s)
91
+ raise Pod::Informative, "#{method} 字段必须在配置文件 #{config_file} 中设置, 请执行 init 命令配置或手动修改配置文件".red
92
+ else
93
+ super
94
+ end
95
+ end
96
+ end
97
+
98
+ def self.config_hot_key
99
+ @config_hot_key ||= Config_Hot_Key.new
100
+ end
101
+
102
+ end
103
+
@@ -0,0 +1,57 @@
1
+ require 'yaml'
2
+ require 'cocoapods-fy-bin/config/config_hot_key'
3
+
4
+ module CBin
5
+ class Config_Hot_Key
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 wellcome_message
41
+ print <<~EOF
42
+
43
+ 开始设置快捷键 pod bin imy.
44
+ 所有的信息都会保存在 #{CBin.config_hot_key.config_file} 文件中.
45
+ %w[hot_key.yaml]
46
+ 你可以在对应目录下手动添加编辑该文件. 文件包含的配置信息样式如下:
47
+
48
+ #{CBin.config_hot_key.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,10 @@
1
+
2
+ module CBin
3
+ VERSION = '0.0.1'
4
+ end
5
+
6
+ module Pod
7
+ def self.match_version?(*version)
8
+ Gem::Dependency.new('', *version).match?('', Pod::VERSION)
9
+ end
10
+ end