cocoapods-aomi-bin 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +22 -0
  3. data/README.md +11 -0
  4. data/lib/cocoapods-lhj-bin.rb +2 -0
  5. data/lib/cocoapods-lhj-bin/command.rb +1 -0
  6. data/lib/cocoapods-lhj-bin/command/bin.rb +58 -0
  7. data/lib/cocoapods-lhj-bin/command/bin/archive.rb +233 -0
  8. data/lib/cocoapods-lhj-bin/command/bin/auto.rb +200 -0
  9. data/lib/cocoapods-lhj-bin/command/bin/code.rb +232 -0
  10. data/lib/cocoapods-lhj-bin/command/bin/dup.rb +78 -0
  11. data/lib/cocoapods-lhj-bin/command/bin/import.rb +130 -0
  12. data/lib/cocoapods-lhj-bin/command/bin/init.rb +69 -0
  13. data/lib/cocoapods-lhj-bin/command/bin/initHotKey.rb +70 -0
  14. data/lib/cocoapods-lhj-bin/command/bin/install.rb +44 -0
  15. data/lib/cocoapods-lhj-bin/command/bin/lhj.rb +46 -0
  16. data/lib/cocoapods-lhj-bin/command/bin/lib/lint.rb +69 -0
  17. data/lib/cocoapods-lhj-bin/command/bin/repo/update.rb +43 -0
  18. data/lib/cocoapods-lhj-bin/command/bin/spec/create.rb +73 -0
  19. data/lib/cocoapods-lhj-bin/command/bin/spec/push.rb +115 -0
  20. data/lib/cocoapods-lhj-bin/command/bin/update.rb +153 -0
  21. data/lib/cocoapods-lhj-bin/config/config.rb +147 -0
  22. data/lib/cocoapods-lhj-bin/config/config_asker.rb +57 -0
  23. data/lib/cocoapods-lhj-bin/config/config_builder.rb +216 -0
  24. data/lib/cocoapods-lhj-bin/config/config_hot_key.rb +103 -0
  25. data/lib/cocoapods-lhj-bin/config/config_hot_key_asker.rb +57 -0
  26. data/lib/cocoapods-lhj-bin/gem_version.rb +9 -0
  27. data/lib/cocoapods-lhj-bin/helpers.rb +5 -0
  28. data/lib/cocoapods-lhj-bin/helpers/Info.plist +0 -0
  29. data/lib/cocoapods-lhj-bin/helpers/build_helper.rb +158 -0
  30. data/lib/cocoapods-lhj-bin/helpers/build_utils.rb +93 -0
  31. data/lib/cocoapods-lhj-bin/helpers/framework.rb +85 -0
  32. data/lib/cocoapods-lhj-bin/helpers/framework_builder.rb +444 -0
  33. data/lib/cocoapods-lhj-bin/helpers/library.rb +54 -0
  34. data/lib/cocoapods-lhj-bin/helpers/library_builder.rb +90 -0
  35. data/lib/cocoapods-lhj-bin/helpers/sources_helper.rb +34 -0
  36. data/lib/cocoapods-lhj-bin/helpers/spec_creator.rb +168 -0
  37. data/lib/cocoapods-lhj-bin/helpers/spec_files_helper.rb +75 -0
  38. data/lib/cocoapods-lhj-bin/helpers/spec_source_creator.rb +220 -0
  39. data/lib/cocoapods-lhj-bin/helpers/upload_helper.rb +105 -0
  40. data/lib/cocoapods-lhj-bin/native.rb +19 -0
  41. data/lib/cocoapods-lhj-bin/native/acknowledgements.rb +27 -0
  42. data/lib/cocoapods-lhj-bin/native/analyzer.rb +55 -0
  43. data/lib/cocoapods-lhj-bin/native/file_accessor.rb +28 -0
  44. data/lib/cocoapods-lhj-bin/native/installation_options.rb +25 -0
  45. data/lib/cocoapods-lhj-bin/native/installer.rb +135 -0
  46. data/lib/cocoapods-lhj-bin/native/linter.rb +26 -0
  47. data/lib/cocoapods-lhj-bin/native/path_source.rb +33 -0
  48. data/lib/cocoapods-lhj-bin/native/pod_source_installer.rb +19 -0
  49. data/lib/cocoapods-lhj-bin/native/pod_target_installer.rb +94 -0
  50. data/lib/cocoapods-lhj-bin/native/podfile.rb +91 -0
  51. data/lib/cocoapods-lhj-bin/native/podfile_env.rb +37 -0
  52. data/lib/cocoapods-lhj-bin/native/podfile_generator.rb +199 -0
  53. data/lib/cocoapods-lhj-bin/native/podspec_finder.rb +25 -0
  54. data/lib/cocoapods-lhj-bin/native/resolver.rb +230 -0
  55. data/lib/cocoapods-lhj-bin/native/sandbox_analyzer.rb +34 -0
  56. data/lib/cocoapods-lhj-bin/native/source.rb +35 -0
  57. data/lib/cocoapods-lhj-bin/native/sources_manager.rb +20 -0
  58. data/lib/cocoapods-lhj-bin/native/specification.rb +31 -0
  59. data/lib/cocoapods-lhj-bin/native/target_validator.rb +41 -0
  60. data/lib/cocoapods-lhj-bin/native/validator.rb +40 -0
  61. data/lib/cocoapods-lhj-bin/source_provider_hook.rb +66 -0
  62. data/lib/cocoapods_plugin.rb +2 -0
  63. data/spec/command/bin_spec.rb +12 -0
  64. data/spec/spec_helper.rb +50 -0
  65. metadata +178 -0
@@ -0,0 +1,103 @@
1
+ require 'yaml'
2
+ require 'cocoapods-lhj-bin/native/podfile'
3
+ require 'cocoapods-lhj-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-lhj-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-lhj-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 lhj.
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,9 @@
1
+ module CBin
2
+ VERSION = '0.0.2'
3
+ end
4
+
5
+ module Pod
6
+ def self.match_version?(*version)
7
+ Gem::Dependency.new('', *version).match?('', Pod::VERSION)
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ require 'cocoapods-lhj-bin/helpers/sources_helper'
2
+ require 'cocoapods-lhj-bin/helpers/spec_creator'
3
+ require 'cocoapods-lhj-bin/helpers/spec_files_helper'
4
+ require 'cocoapods-lhj-bin/helpers/spec_source_creator'
5
+ require 'cocoapods-lhj-bin/helpers/build_utils'
@@ -0,0 +1,158 @@
1
+ # copy from https://github.com/CocoaPods/cocoapods-packager
2
+
3
+ require 'cocoapods-lhj-bin/native/podfile'
4
+ require 'cocoapods/command/gen'
5
+ require 'cocoapods/generate'
6
+ require 'cocoapods-lhj-bin/helpers/framework_builder'
7
+ require 'cocoapods-lhj-bin/helpers/library_builder'
8
+ require 'cocoapods-lhj-bin/config/config_builder'
9
+
10
+ module CBin
11
+ class Build
12
+ class Helper
13
+ include Pod
14
+ #class var
15
+ @@build_defines = ""
16
+ #Debug下还待完成
17
+ def initialize(spec,
18
+ platform,
19
+ framework_output,
20
+ zip,
21
+ rootSpec,
22
+ skip_archive = false,
23
+ build_model="Release")
24
+ @spec = spec
25
+ @platform = platform
26
+ @build_model = build_model
27
+ @rootSpec = rootSpec
28
+ @isRootSpec = rootSpec.name == spec.name
29
+ @skip_archive = skip_archive
30
+ @framework_output = framework_output
31
+ @zip = zip
32
+
33
+ @framework_path
34
+ end
35
+
36
+ def build
37
+ UI.section("Building static framework #{@spec}") do
38
+
39
+ build_static_framework
40
+ unless @skip_archive
41
+ unless CBin::Build::Utils.is_framework(@spec)
42
+ build_static_library
43
+ zip_static_library
44
+ else
45
+ zip_static_framework
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ def build_static_framework
54
+ source_dir = Dir.pwd
55
+ file_accessor = Sandbox::FileAccessor.new(Pathname.new('.').expand_path, @spec.consumer(@platform))
56
+ Dir.chdir(workspace_directory) do
57
+ builder = CBin::Framework::Builder.new(@spec, file_accessor, @platform, source_dir, @isRootSpec, @build_model )
58
+ @@build_defines = builder.build if @isRootSpec
59
+ begin
60
+ @framework_path = builder.lipo_build(@@build_defines) unless @skip_archive
61
+ rescue
62
+ @skip_archive = true
63
+ end
64
+ end
65
+ end
66
+
67
+ def build_static_library
68
+ source_dir = zip_dir
69
+ file_accessor = Sandbox::FileAccessor.new(Pathname.new('.').expand_path, @spec.consumer(@platform))
70
+ Dir.chdir(workspace_directory) do
71
+ builder = CBin::Library::Builder.new(@spec, file_accessor, @platform, source_dir,@framework_path)
72
+ builder.build
73
+ end
74
+ end
75
+
76
+ def zip_static_framework
77
+ Dir.chdir(File.join(workspace_directory, @framework_path.root_path)) do
78
+ output_name = File.join(zip_dir, framework_name_zip)
79
+ unless File.exist?(framework_name)
80
+ UI.puts "没有需要压缩的 framework 文件:#{framework_name}"
81
+ return
82
+ end
83
+
84
+ UI.puts "Compressing #{framework_name} into #{output_name}"
85
+ `zip --symlinks -r #{output_name} #{framework_name}`
86
+ end
87
+ end
88
+
89
+ def zip_static_library
90
+ Dir.chdir(zip_dir) do
91
+ output_library = "#{library_name}.zip"
92
+ unless File.exist?(library_name)
93
+ raise Informative, "没有需要压缩的 library 文件:#{library_name}"
94
+ end
95
+
96
+ UI.puts "Compressing #{library_name} into #{output_library}"
97
+
98
+ `zip --symlinks -r #{output_library} #{library_name}`
99
+ end
100
+
101
+ end
102
+
103
+
104
+ def clean_workspace
105
+ UI.puts 'Cleaning workspace'
106
+
107
+ FileUtils.rm_rf(gen_name)
108
+ Dir.chdir(zip_dir) do
109
+ FileUtils.rm_rf(framework_name) if @zip
110
+ FileUtils.rm_rf(library_name)
111
+ FileUtils.rm_rf(framework_name) unless @framework_output
112
+ FileUtils.rm_rf("#{framework_name}.zip") unless @framework_output
113
+ end
114
+ end
115
+
116
+ def framework_name
117
+ CBin::Config::Builder.instance.framework_name(@spec)
118
+ end
119
+
120
+ def framework_name_zip
121
+ CBin::Config::Builder.instance.framework_name_version(@spec) + ".zip"
122
+ end
123
+
124
+ def library_name
125
+ CBin::Config::Builder.instance.library_name(@spec)
126
+ end
127
+
128
+ def workspace_directory
129
+ File.expand_path("#{gen_name}/#{@rootSpec.name}")
130
+ end
131
+
132
+ def zip_dir
133
+ CBin::Config::Builder.instance.zip_dir
134
+ end
135
+
136
+ def gen_name
137
+ CBin::Config::Builder.instance.gen_dir
138
+ end
139
+
140
+
141
+ def spec_file
142
+ @spec_file ||= begin
143
+ if @podspec
144
+ find_spec_file(@podspec)
145
+ else
146
+ if code_spec_files.empty?
147
+ raise Informative, '当前目录下没有找到可用源码 podspec.'
148
+ end
149
+
150
+ spec_file = code_spec_files.first
151
+ spec_file
152
+ end
153
+ end
154
+ end
155
+
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,93 @@
1
+ require 'yaml'
2
+ require 'cocoapods'
3
+ require 'cocoapods-lhj-bin/config/config'
4
+
5
+ module CBin
6
+ class Build
7
+ class Utils
8
+ def Utils.is_framework(spec)
9
+ return true
10
+ # if Utils.uses_frameworks?
11
+ # return true
12
+ # end
13
+ # return Utils.is_swift_module(spec)
14
+ end
15
+
16
+ def Utils.spec_header_dir(spec)
17
+
18
+ header_dir = "./Headers/Public/#{spec.name}"
19
+ header_dir = "./Pods/Headers/Public/#{spec.name}" unless File.exist?(header_dir)
20
+
21
+ unless File.exist?(header_dir)
22
+ # 一些库名称中使用了中划线如AAA-BBB,public header中库名称会默认处理成下划线AAA_BBB
23
+ module_name = spec.name.gsub("-", "_")
24
+ header_dir = "./Pods/Headers/Public/#{module_name}"
25
+ end
26
+
27
+ # 暂时只支持:ios
28
+ consumer = Pod::Specification::Consumer.new(spec, :ios)
29
+ unless consumer.header_dir.nil?
30
+ header_dir = File.join(header_dir, consumer.header_dir)
31
+ end
32
+
33
+ header_dir
34
+ end
35
+
36
+ def Utils.spec_module_dir(spec)
37
+ if spec.module_name.nil?
38
+ module_dir = "./Headers/Public/#{spec.name}"
39
+ module_dir = "./Pods/Headers/Public/#{spec.name}" unless File.exist?(module_dir)
40
+ unless File.exist?(module_dir)
41
+ # 一些库名称中使用了中划线如AAA-BBB,public header中库名称会默认处理成下划线AAA_BBB
42
+ module_name = spec.name.gsub("-", "_")
43
+ module_dir = "./Pods/Headers/Public/#{module_name}"
44
+ end
45
+ else
46
+ module_dir = "./Headers/Public/#{spec.module_name}"
47
+ module_dir = "./Pods/Headers/Public/#{spec.module_name}" unless File.exist?(module_dir)
48
+ end
49
+
50
+ module_dir
51
+ end
52
+
53
+ def Utils.is_swift_module(spec)
54
+
55
+ is_framework = false
56
+ dir = File.join(CBin::Config::Builder.instance.gen_dir, CBin::Config::Builder.instance.target_name)
57
+ #auto 走这里
58
+ if File.exist?(dir)
59
+ Dir.chdir(dir) do
60
+ spec_module_dir = Utils.spec_module_dir(spec)
61
+ return false unless File.exist?(spec_module_dir)
62
+ is_framework = File.exist?(File.join(spec_module_dir, "#{spec.name}-umbrella.h"))
63
+ end
64
+ end
65
+
66
+ if $ARGV[1] == "local"
67
+ is_framework = File.exist?(File.join(CBin::Config::Builder.instance.xcode_build_dir, "#{spec.name}.framework"))
68
+ unless is_framework
69
+ is_framework = File.exist?(File.join(CBin::Config::Builder.instance.xcode_BuildProductsPath_dir, "#{spec.name}","Swift Compatibility Header"))
70
+ end
71
+ end
72
+
73
+ is_framework
74
+ end
75
+
76
+ def Utils.uses_frameworks?
77
+ uses_frameworks = false
78
+ Pod::Config.instance.podfile.target_definitions.each do |key,value|
79
+ if key != "Pods"
80
+ uses_frameworks = value.uses_frameworks?
81
+ if uses_frameworks
82
+ break;
83
+ end
84
+ end
85
+ end
86
+
87
+ return uses_frameworks
88
+ end
89
+
90
+ end
91
+
92
+ end
93
+ end
@@ -0,0 +1,85 @@
1
+ # copy from https://github.com/CocoaPods/cocoapods-packager
2
+
3
+ module CBin
4
+ class Framework
5
+ attr_reader :headers_path
6
+ attr_reader :module_map_path
7
+ attr_reader :resources_path
8
+ attr_reader :root_path
9
+ attr_reader :versions_path
10
+ attr_reader :swift_module_path
11
+ attr_reader :fwk_path
12
+
13
+ def initialize(name, platform)
14
+ @name = name
15
+ @platform = platform
16
+ end
17
+
18
+ def make
19
+ make_root
20
+ make_framework
21
+ make_headers
22
+ make_resources
23
+ make_current_version
24
+ end
25
+
26
+ def delete_resources
27
+ Pathname.new(@resources_path).rmtree if File.exist? (@resources_path)
28
+ (Pathname.new(@fwk_path) + Pathname.new('Resources')).delete if File.exist?(Pathname.new(@fwk_path) + Pathname.new('Resources'))
29
+ end
30
+
31
+ def remove_current_version
32
+ FileUtils.rm_f(File.join(@fwk_path,@name))
33
+ FileUtils.rm_f(File.join(@fwk_path,"Headers"))
34
+ FileUtils.rm_f(File.join(@fwk_path,"Resources"))
35
+
36
+ FileUtils.cp_r("#{@versions_path}/.", @fwk_path)
37
+ # FileUtils.remove_dir(@versions_path)
38
+ FileUtils.remove_dir("#{@fwk_path}/Versions")
39
+
40
+ # current_version_path = @versions_path + Pathname.new('../Current')
41
+ # `ln -sf A #{current_version_path}`
42
+ # `ln -sf Versions/Current/Headers #{@fwk_path}/`
43
+ # `ln -sf Versions/Current/Resources #{@fwk_path}/`
44
+ # `ln -sf Versions/Current/#{@name} #{@fwk_path}/`
45
+ end
46
+
47
+ private
48
+
49
+ def make_current_version
50
+ current_version_path = @versions_path + Pathname.new('../Current')
51
+ `ln -sf A #{current_version_path}`
52
+ `ln -sf Versions/Current/Headers #{@fwk_path}/`
53
+ `ln -sf Versions/Current/Resources #{@fwk_path}/`
54
+ `ln -sf Versions/Current/#{@name} #{@fwk_path}/`
55
+ end
56
+
57
+
58
+
59
+ def make_framework
60
+ @fwk_path = @root_path + Pathname.new(@name + '.framework')
61
+ @fwk_path.mkdir unless @fwk_path.exist?
62
+
63
+ @module_map_path = @fwk_path + Pathname.new('Modules')
64
+ @swift_module_path = @module_map_path + Pathname.new(@name + '.swiftmodule')
65
+
66
+
67
+ @versions_path = @fwk_path + Pathname.new('Versions/A')
68
+ end
69
+
70
+ def make_headers
71
+ @headers_path = @versions_path + Pathname.new('Headers')
72
+ @headers_path.mkpath unless @headers_path.exist?
73
+ end
74
+
75
+ def make_resources
76
+ @resources_path = @versions_path + Pathname.new('Resources')
77
+ @resources_path.mkpath unless @resources_path.exist?
78
+ end
79
+
80
+ def make_root
81
+ @root_path = Pathname.new(@platform)
82
+ @root_path.mkpath unless @root_path.exist?
83
+ end
84
+ end
85
+ end