cocoapods-ocean_modulemap 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 03bc04855c1443d617f41abe08ef774de9ddd9b01c6b02530c8a7851a5b73543
4
+ data.tar.gz: f740b5ce3d7e2e0d201554f276f5640aa4014c68e8990f13ee50fa5e57f9367a
5
+ SHA512:
6
+ metadata.gz: de0a9fbfd084941443b266db2f294781d61277195371bb18df1cd2d2170577491def86ce06205d0d7d4a5cfc1bfbadb130e39fa2bcf4f84319a25e8fdc7f90a3
7
+ data.tar.gz: 40db0cdd6c2e9d9d3da201cc4c54a2e9f8207bb9cd59c4a6466c1fc99d0d2a99a4c924e15518b7cb0bebf9b7fd6e2d08c50b8226193056fb530e8830d49c6e8c
@@ -0,0 +1,2 @@
1
+ require 'cocoapods-ocean_modulemap/gem_version'
2
+ require 'cocoapods'
@@ -0,0 +1 @@
1
+ require 'cocoapods-ocean_modulemap/command/ocean_modulemap'
@@ -0,0 +1,209 @@
1
+ module Pod
2
+ class Command
3
+ # This is an example of a cocoapods plugin adding a top-level subcommand
4
+ # to the 'pod' command.
5
+ #
6
+ # You can also create subcommands of existing or new commands. Say you
7
+ # wanted to add a subcommand to `list` to show newly deprecated pods,
8
+ # (e.g. `pod list deprecated`), there are a few things that would need
9
+ # to change.
10
+ #
11
+ # - move this file to `lib/pod/command/list/deprecated.rb` and update
12
+ # the class to exist in the the Pod::Command::List namespace
13
+ # - change this class to extend from `List` instead of `Command`. This
14
+ # tells the plugin system that it is a subcommand of `list`.
15
+ # - edit `lib/cocoapods_plugins.rb` to require this file
16
+ #
17
+ # @todo Create a PR to add your plugin to CocoaPods/cocoapods.org
18
+ # in the `plugins.json` file, once your plugin is released.
19
+ #
20
+ class OceanModulemap < Command
21
+ self.summary = 'generate modulemap file content'
22
+
23
+ self.description = <<-DESC
24
+ modulemap file generated
25
+ DESC
26
+
27
+ self.arguments = 'ocean-modulemap'
28
+
29
+ def initialize(argv)
30
+ # 获取参数
31
+ @target_dir = argv.shift_argument
32
+ super
33
+ end
34
+
35
+ def validate!
36
+ super
37
+ # help! 'A Pod name is required.' unless @name
38
+ end
39
+
40
+ def run
41
+ # UI.puts "Add your implementation for the cocoapods-ocean_modulemap plugin in #{__FILE__}"
42
+
43
+ # 找到pods目录进行 framework 文件中 modulemap 文件的生成
44
+
45
+ # 最终的目录
46
+ dir = fetch_final_dir
47
+ # 文件夹校验
48
+ unless File.directory?(dir)
49
+ puts "#{dir} is not a valid directory !!\n"
50
+ exit(1)
51
+ end
52
+
53
+ # 获取所有的 framework 路径
54
+ framework_paths = find_all_framework_paths(dir)
55
+ framework_paths.each do |path|
56
+ handle_framework_modulemap(path)
57
+ end
58
+ end
59
+
60
+ # 获取最终的文件夹目录
61
+ # @return [String] 最终的文件夹目录
62
+ def fetch_final_dir
63
+ # 目标文件夹,默认是当前目录
64
+ dir = Dir.pwd
65
+ dir = @target_dir.to_s if @target_dir
66
+
67
+ puts "\n you not set target dir, so use current dir (pwd) !!!\n" unless @target_dir
68
+ puts 'final dir: ' + dir.to_s
69
+ dir.to_s
70
+ end
71
+
72
+ # 查找指定目录内所有的 framework
73
+ # @param dir 目录
74
+ # @return [String] framework 的路径
75
+ def find_all_framework_paths(dir = '')
76
+ # 遍历所有的文件
77
+ find_framework_cmd = 'find ' + dir.to_s
78
+ find_framework_cmd += ' -name *.framework'
79
+ find_framework_res = %x(#{find_framework_cmd})
80
+
81
+ framework_paths = find_framework_res.to_s.split
82
+ puts '-----'
83
+ puts 'find framework path result: '
84
+ puts framework_paths
85
+ puts '-----'
86
+ framework_paths
87
+ end
88
+
89
+ # 处理 framework 的 modulemap 文件
90
+ # @param [String] path framework的路径
91
+ def handle_framework_modulemap(path = '')
92
+ puts "\nhandle_framework_modulemap at path: " + path.to_s
93
+
94
+ name = File.basename(path)
95
+ puts 'basename: ' + name.to_s
96
+ framework_name = File.basename(path, '.framework')
97
+ puts 'framework_name: ' + framework_name.to_s
98
+
99
+ # /Modules 目录处理
100
+ module_dir = path + '/Modules'
101
+ puts 'module dir: ' + module_dir.to_s
102
+ # 不存在则进行创建
103
+ if File.exist?(module_dir)
104
+ puts 'already exist !'
105
+ else
106
+ puts 'not exist, need mkdir !'
107
+ FileUtils.mkdir_p(module_dir.to_s)
108
+ end
109
+
110
+ # modulemap 文件处理, module.modulemap
111
+ modulemap_path = module_dir.to_s + '/module.modulemap'
112
+ puts 'modulemap path: ' + modulemap_path.to_s
113
+
114
+ if File.exist?(modulemap_path)
115
+ puts 'already exist, need return, do nothings !'
116
+ else
117
+ puts 'not exist, need generate modulemap file !'
118
+
119
+ # 从 Headers 目录中找到所有的 头文件
120
+ headers_dir = path + '/Headers'
121
+ framework_headers_paths = find_all_header_paths(headers_dir)
122
+ # 普通的.h文件
123
+ framework_normal_headers_paths = framework_headers_paths.reject do |header_path|
124
+ header_path.to_s.include?('-umbrella.h')
125
+ end
126
+ # -umbrella.h 文件
127
+ framework_umbrella_headers_paths = framework_headers_paths - framework_normal_headers_paths
128
+
129
+ # 文件名称
130
+ framework_normal_headers = map_basename(framework_normal_headers_paths)
131
+ framework_umbrella_headers = map_basename(framework_umbrella_headers_paths)
132
+
133
+ content = generate_moudulemap_content(framework_name, framework_umbrella_headers, framework_normal_headers)
134
+
135
+ # 保存到文件中
136
+ Pathname.new(modulemap_path.to_s).open('w') do |f|
137
+ f.write(content)
138
+ end
139
+ end
140
+ end
141
+
142
+ # 查找所有的 headers(.h) 文件路径
143
+ # @param dir 目录路径
144
+ # @return 所有的头文件路径
145
+ def find_all_header_paths(dir = '')
146
+ # 遍历所有的文件
147
+ framework_headers_cmd = 'find ' + dir.to_s
148
+ framework_headers_cmd += ' -name *.h'
149
+ framework_headers_res = %x(#{framework_headers_cmd})
150
+
151
+ framework_headers_res.to_s.split
152
+ end
153
+
154
+ # 把路径映射为文件名称
155
+ # @param paths 路径列表
156
+ # @return names 文件名称列表
157
+ def map_basename(paths = [])
158
+ paths.map do |path|
159
+ File.basename(path)
160
+ end
161
+ end
162
+
163
+ # 根据头文件类型,生成在 moudulemap 中显示的内容
164
+ # @param header 头文件
165
+ # @return 生成的内容
166
+ def generate_header_content(header = '')
167
+ content = if header.include?('-umbrella.h')
168
+ 'umbrella header ' + '"' + header.to_s + '"'
169
+ else
170
+ 'header ' + '"' + header.to_s + '"'
171
+ end
172
+ puts "header: #{header}, module map content: #{content}"
173
+ content
174
+ end
175
+
176
+ # 生成 moudulemap 文件内容
177
+ # @param framework_name framework 名称
178
+ # @param umbrella_headers umbrella headers 文件名称列表
179
+ # @param normal_headers normal headers 文件名称列表
180
+ # @return 内容
181
+ def generate_moudulemap_content(framework_name = '', umbrella_headers = [], normal_headers = [])
182
+
183
+ # 生成 header 对应的内容
184
+ normal_headers_contents = normal_headers.map do |header_path|
185
+ generate_header_content(header_path)
186
+ end
187
+ umbrella_headers_contents = umbrella_headers.map do |header_path|
188
+ generate_header_content(header_path)
189
+ end
190
+
191
+ # 生成 modulemap 文件内容
192
+ content = <<-MODULE_MAP
193
+ framework module #{framework_name} {
194
+ #{umbrella_headers_contents.join("\n ")}
195
+ #{normal_headers_contents.join("\n ")}
196
+
197
+ export *
198
+ module * { export * }
199
+ }
200
+ MODULE_MAP
201
+
202
+ puts '\n generate_moudulemap_content result: '
203
+ puts content
204
+
205
+ content
206
+ end
207
+ end
208
+ end
209
+ end
@@ -0,0 +1,3 @@
1
+ module CocoapodsOcean_modulemap
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1 @@
1
+ require 'cocoapods-ocean_modulemap/command'
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-ocean_modulemap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ocean
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.4
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: modulemap
42
+ email:
43
+ - 849638313@qq.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/cocoapods-ocean_modulemap.rb
49
+ - lib/cocoapods-ocean_modulemap/command.rb
50
+ - lib/cocoapods-ocean_modulemap/command/ocean_modulemap.rb
51
+ - lib/cocoapods-ocean_modulemap/gem_version.rb
52
+ - lib/cocoapods_plugin.rb
53
+ homepage: https://github.com/oceanfive/cocoapods-ocean_modulemap
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.0.3
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: modulemap 文件处理
76
+ test_files: []