cocoapods-tools 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0cbb1755812c41b7184ef6b796279d93dd1a7d3ff2e7a6a0e05ca884d6f07a46
4
+ data.tar.gz: cc919dfaca1ede5df431456d3feb6618cd85cf6c1718f20ea6baa525764fdf99
5
+ SHA512:
6
+ metadata.gz: 5e21dcf08657c9f23f0766f4e5daf0a1b36fb6e21b2e0f480075e54a237cc536319ce06380d061b55af701960ea20dc8966b98d2a03536dc86ff894c837fdd64
7
+ data.tar.gz: d3406bb5a2d8d6da2dc27c35c55f9daed92db62201e903ec6bb525ec290d2b20a1156e1b4314e1027e647724ace536ef0655114de02ca2480a2be2a79f0b17f0
data/bin/ht ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if Encoding.default_external != Encoding::UTF_8
4
+
5
+ if ARGV.include? '--no-ansi'
6
+ STDERR.puts <<-DOC
7
+ WARNING: CocoapodsTools requires your terminal to be using UTF-8 encoding.
8
+ Consider adding the following to ~/.profile:
9
+
10
+ export LANG=en_US.UTF-8
11
+ DOC
12
+ else
13
+ STDERR.puts <<-DOC
14
+ \e[33mWARNING: CocoapodsTools requires your terminal to be using UTF-8 encoding.
15
+ Consider adding the following to ~/.profile:
16
+
17
+ export LANG=en_US.UTF-8
18
+ \e[0m
19
+ DOC
20
+ end
21
+
22
+ end
23
+
24
+ if $PROGRAM_NAME == __FILE__ && !ENV['COCOAPODSTOOLS_NO_BUNDLER']
25
+ ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__)
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
29
+ elsif ENV['COCOAPODSTOOLS_NO_BUNDLER']
30
+ require 'rubygems'
31
+ gem 'cocoapods'
32
+ end
33
+
34
+ STDOUT.sync = true if ENV['CP_STDOUT_SYNC'] == 'TRUE'
35
+
36
+ require 'cocoapods-tools'
37
+ CocoapodsTools::Command.run(ARGV)
File without changes
@@ -0,0 +1,50 @@
1
+ require 'cocoapods-tools/helper/color'
2
+
3
+ module CocoapodsTools
4
+ # This command uses an argument for the extra parameter, instead of
5
+ # subcommands for each of the flavor.
6
+
7
+ class Spec < Command
8
+
9
+ require 'cocoapods-tools/command/spec/tag'
10
+
11
+ self.summary = 'cocoapods spec'
12
+
13
+ self.description = 'cocoapods spec'
14
+
15
+ self.arguments = [
16
+ CLAide::Argument.new('tag', '1.0'),
17
+ ]
18
+
19
+ def self.options
20
+ [['tag', '自动打 tag']].concat(super)
21
+ end
22
+
23
+ def initialize(argv)
24
+ @tag = argv.flag?('tag')
25
+ super
26
+ end
27
+
28
+ def validate!
29
+ super
30
+ # if @flavor.nil?
31
+ # help! 'A flavor argument is required.'
32
+ # end
33
+ # unless %w(black green oolong white).include?(@flavor)
34
+ # help! "`#{@flavor}' is not a valid flavor."
35
+ # end
36
+ end
37
+
38
+ def run
39
+ super
40
+ # puts "* Infuse #{@flavor} tea…"
41
+ # sleep 1
42
+ # if @iced
43
+ # puts '* Cool off…'
44
+ # sleep 1
45
+ # end
46
+ end
47
+
48
+
49
+ end
50
+ end
@@ -0,0 +1,308 @@
1
+ require 'cocoapods-tools/helper/color'
2
+ require 'fileutils'
3
+
4
+ module CocoapodsTools
5
+ # This command uses an argument for the extra parameter, instead of
6
+ # subcommands for each of the flavor.
7
+
8
+ class Tag < Spec
9
+
10
+ self.summary = 'cocoapods spec tag'
11
+
12
+ self.description = 'cocoapods spec tag'
13
+
14
+ self.arguments = [
15
+ # CLAide::Argument.new('TAG_VERSION', false, false),
16
+ ]
17
+
18
+ def self.options
19
+ []
20
+ end
21
+
22
+ def initialize(argv)
23
+ @arguments = argv.arguments!
24
+ super
25
+ end
26
+
27
+ def validate!
28
+ super
29
+ # puts Color.color_text('validate spec', Color.green)
30
+ help! '输入参数过多' if @arguments.count > 1
31
+ end
32
+
33
+ def run
34
+ super
35
+
36
+ # 搜索podspec路径
37
+ podspec_path = ''
38
+ find_podspec_path = Pathname.pwd
39
+
40
+ # 有可能存在多个 podspec,当用户没有指定时,需要给用户自主选择
41
+ pod_specs = find_podspec_path.children.select { |pn| pn.extname == '.podspec' }
42
+ example_path = Pathname.new("#{find_podspec_path}/Example").expand_path
43
+ project_path = example_path.children.select { |pn| pn.extname == '.xcodeproj' }.first
44
+ project_name = File.basename(project_path, '.*')
45
+ default_name = "#{project_name}.podspec"
46
+ podspec_path = default_name
47
+
48
+ # 默认为工程名同名的 spec
49
+ # default_name = "#{project_name}.podspec"
50
+ # spec_default = pod_specs.select { |path| path.basename.to_s == default_name }.first
51
+ spec_default = "#{project_name}.podspec"
52
+
53
+ if pod_specs.count > 1
54
+ input_tag = true
55
+ serial = 0
56
+ puts Color.color_text(
57
+ "Find #{pod_specs.count} podspec files, please enter the serial number selection:\n(default:#{spec_default})", Color.white)
58
+ while input_tag
59
+ (0...pod_specs.count).each do |i|
60
+ puts "#{i + 1}. #{pod_specs[i]}"
61
+ end
62
+ serial = $stdin.gets.chomp
63
+ input_tag = (serial.to_i > pod_specs.count || serial.to_i <= 0)
64
+ if serial.empty?
65
+ input_tag = false
66
+ podspec_path = spec_default
67
+ elsif input_tag
68
+ puts "Input serial = #{serial}, it's invalid and you need to input 1~#{pod_specs.count}:"
69
+ else
70
+ input_tag = false
71
+ podspec_path = pod_specs[serial.to_i - 1]
72
+ end
73
+ end
74
+ elsif pod_specs.count == 1
75
+ podspec_path = pod_specs.first.split.last
76
+ else
77
+ puts color_text("Can't find any podspec file", Color.red)
78
+ return
79
+ end
80
+
81
+ if !File.exist?(podspec_path)
82
+ puts ("找不到 podspec 文件: #{podspec_path}, 请确认当前路径")
83
+ return
84
+ else
85
+ puts "Ready to deal with podspec named #{Color.color_text(podspec_path.to_s, Color.white)}"
86
+ end
87
+
88
+ # 在当前podspec目录下新建一个临时 need_delete_temp.podspec 文件
89
+ podspec_dir = File.dirname podspec_path
90
+ podspec_absolute_path = "#{find_podspec_path}/#{podspec_path}"
91
+ temp_podspec_path = "#{podspec_dir}/need_delete_temp.podspec"
92
+ temp_podspec_absolute_path = "#{find_podspec_path}/#{temp_podspec_path}"
93
+
94
+ cur_version = ''
95
+ # 读取当前podspec文件的版本
96
+ File.open(podspec_absolute_path, 'r+') do |f|
97
+ f.each_line do |line|
98
+ # 查找.version
99
+ version_desc = /.*\.version\s*=.*/.match line
100
+ next if version_desc.nil?
101
+
102
+ cur_version = version_desc.to_s.split('=').last.to_s.gsub("'", '')
103
+ cur_version = cur_version.gsub(' ', '')
104
+ break
105
+ end
106
+ end
107
+
108
+ puts Color.color_text('Current version = ', Color.white) + Color.color_text(cur_version.to_s, Color.green)
109
+
110
+ # 自定义版本号
111
+ if @arguments.count == 1
112
+
113
+ input_version = @arguments.first
114
+ puts Color.color_text "不输入时默认自增。本次已输入,版本号:#{input_version}", Color.white
115
+
116
+ # 判断输入的version是否>当前的版本号
117
+ input_v_s = input_version.to_s.split('.')
118
+ cur_v_s = cur_version.split('.')
119
+ # 比较的位置,从最左边开始
120
+ v_index = 0
121
+ # 输入的version是否有效
122
+ input_valid = false
123
+ while v_index < cur_v_s.count && v_index < input_v_s.count do
124
+ if input_v_s[v_index].to_i > cur_v_s[v_index].to_i
125
+ # 说明用户输入的version比当前的大
126
+ input_valid = true
127
+ break
128
+ elsif input_v_s[v_index].to_i == cur_v_s[v_index].to_i
129
+ v_index += 1
130
+ else
131
+ break
132
+ end
133
+ end
134
+
135
+ puts Color.color_text "版本号 #{input_version} 无效,默认自增", Color.natural if input_valid == false
136
+ end
137
+
138
+ system("touch #{temp_podspec_path}") unless File.exist? temp_podspec_absolute_path
139
+
140
+ new_version = ''
141
+ git_source = ''
142
+
143
+ File.open(temp_podspec_absolute_path, 'r+') do |t|
144
+ File.open(podspec_absolute_path) do |f|
145
+ f.each_line do |line|
146
+ # # 查找.version
147
+ # s.version = "0.0.2"
148
+ # 需要注意的是,版本号可以是'',也可以是""
149
+ write_line = line
150
+ version_desc = /.*\.version\s*=.*/.match line
151
+ unless version_desc.nil?
152
+ version_comes = version_desc.to_s.split('=')
153
+ if (input_valid == true) && (@arguments.count == 1)
154
+ new_version = input_version.to_s
155
+ else
156
+ version_num = version_comes.last.to_s.gsub("'", '').gsub('"', '').gsub(' ', '')
157
+ v_s = version_num.split('.')
158
+ # 处理版本号 0.0.1
159
+ (0...v_s.count).each do |i|
160
+ new_version += if i == v_s.count - 1
161
+ (v_s[i].to_i + 1).to_s
162
+ else
163
+ "#{v_s[i]}."
164
+ end
165
+ end
166
+ end
167
+ puts Color.color_text('New version = ', Color.white) + Color.color_text(new_version.to_s, Color.green)
168
+ write_line = "#{version_comes.first}= '#{new_version}'\n"
169
+ end
170
+ source_desc = /.*\.source\s*=.*/.match line
171
+ unless source_desc.nil?
172
+ source_desc = /:git.*,/.match source_desc.to_s
173
+ source_desc = /'.*'/.match source_desc.to_s
174
+ git_source = source_desc.to_s.gsub("'", '')
175
+ puts "git source is #{git_source}"
176
+ end
177
+ t.write write_line
178
+ end
179
+ end
180
+ end
181
+
182
+ puts Color.color_text('Update version from ',
183
+ Color.white) + Color.color_text(cur_version.to_s,
184
+ Color.green) + Color.color_text(' to ', Color.white) + Color.color_text(new_version.to_s, Color.green)
185
+
186
+ # 将新数据反写回到原始podspec中
187
+ system("cp -f #{temp_podspec_path} #{podspec_path}")
188
+ system("rm -f #{temp_podspec_path}")
189
+
190
+ # pod_repo_name = 'third_specs'
191
+ # pod_repo_name = ''
192
+ pod_repo_source = 'ssh://git@office.hellotalk.net:7999/third/third_specs.git'
193
+ pod_repo_source = 'ssh://git@172.16.6.10:7999/third/third_specs.git'
194
+
195
+ # 处理正式 repo 逻辑,解析当前 repos
196
+ # pod_repos = `pod repo list`
197
+ #
198
+ # # pod_repos = Array.new
199
+ # # pod_repo = Array.new
200
+ # curren_pod_name = ''
201
+ # temp_pod_name = ''
202
+ # last_line = ''
203
+ # pod_repos.each_line do |line|
204
+ # continue if line == '\n'
205
+ #
206
+ # line = line.gsub(/\n/, '')
207
+ #
208
+ # if line.include?('- Type:')
209
+ # temp_pod_name = last_line
210
+ # elsif line.include?('- URL:')
211
+ # repo_url = line.split('- URL:').last.gsub(/ /, '')
212
+ # if repo_url == pod_repo_source
213
+ # pod_repo_name = temp_pod_name
214
+ # break
215
+ # end
216
+ # end
217
+ # last_line = line
218
+ # end
219
+ #
220
+ # if pod_repo_name == ''
221
+ pod_repo_name = pod_repo_source.split('/').last.split('.').first
222
+ # puts Color.color_text("Add pod repo named '#{pod_repo_name}' with source: #{pod_repo_source}", Color.white)
223
+ # system("pod repo add #{pod_repo_name} #{pod_repo_source}")
224
+ # end
225
+
226
+ # 提交代码到远程仓库
227
+ puts Color.color_text('Start upload code to remote', Color.white)
228
+
229
+ system("git commit -am 'update version to #{new_version}'")
230
+ Color.die_log('[!] git push code error') if system('git push origin master') == false
231
+ system("git tag #{new_version}")
232
+ if system('git push origin --tags') == false
233
+ Color.die_log('[!] git push tags error')
234
+ return
235
+ end
236
+
237
+ # 获取当前 repo 缓存路径,建立新版本 spec 的文件夹
238
+ home_dir ||= Pathname.new(ENV['CP_HOME_DIR'] || '~/.cocoapods').expand_path
239
+ specs_git_syn = Pathname.new("#{home_dir}/specs_git_syn").expand_path
240
+ FileUtils.mkdir_p(specs_git_syn) unless specs_git_syn.exist?
241
+
242
+ pod_spec_dir = Pathname.new("#{specs_git_syn}/#{pod_repo_name}").expand_path
243
+
244
+ Dir.chdir(specs_git_syn) do
245
+ # 同步文件夹中,没有当前源则克隆
246
+
247
+ system("git clone #{pod_repo_source} #{pod_spec_dir}") unless pod_spec_dir.exist?
248
+
249
+ pod_repo_dir = Pathname.new("#{pod_spec_dir}/#{project_name}").expand_path
250
+
251
+ # 添加最新版本文件夹
252
+ version_dir = Pathname.new("#{pod_repo_dir}/#{new_version.to_s}").expand_path
253
+ FileUtils.mkdir_p(version_dir, mode: 0o755)
254
+
255
+ # 将修改版本号的 spec 文件拷贝进去
256
+ spec_repo_path = Pathname.new("#{version_dir}/#{podspec_path}").expand_path
257
+ system("cp -f #{podspec_absolute_path} #{spec_repo_path}")
258
+
259
+ # 进入当前源对应的同步文件夹
260
+ Dir.chdir(pod_spec_dir) do
261
+ # git 提交到私有源
262
+ puts Color.color_text("Start push pod '#{pod_spec_dir}' to remote repo '#{pod_repo_name}'", Color.white)
263
+ system('git add .')
264
+ system("git commit -am 'update version to #{new_version}'")
265
+ Color.die_log('[!] git push code error') if system('git push origin master') == false
266
+ system("git tag #{new_version}")
267
+ if system('git push origin --tags') == false
268
+ Color.die_log('[!] git push tags error')
269
+ return
270
+ end
271
+ puts Color.color_text("Update success ☕️! Current version = #{new_version}", Color.green)
272
+
273
+ end
274
+
275
+ end
276
+ end
277
+
278
+ # system("pod repo update #{pod_repo_name}") unless specs_dir.exist?
279
+ # FileUtils.mkdir_p(specs_dir) unless specs_dir.exist?
280
+
281
+ # 验证podspec格式是否正确
282
+ # if verify_podspec_format == true
283
+ # puts Color.color_text("Start verify podspec '#{podspec_path}'...", Color.white)
284
+ # if system("pod lib lint #{podspec_path} --allow-warnings") == false
285
+ # die_log("[!] pod spec' format invalid")
286
+ # return
287
+ # end
288
+ # end
289
+
290
+ # 提交pod spec到spec仓库
291
+ # puts Color.color_text("Start push pod '#{podspec_path}' to remote repo '#{pod_repo_name}'", Color.white)
292
+ # system("pod repo push #{pod_repo_name} #{podspec_path} --allow-warnings")
293
+ # puts Color.color_text("Update success ☕️! Current version = #{new_version}", Color.green)
294
+
295
+ # if pod_repo_name == 'trunk'
296
+ # if (is_static_lib == true ? system("pod trunk push #{podspec_path} --allow-warnings --use-libraries") : system("pod trunk push #{podspec_path} --allow-warnings")) == false
297
+ # puts "If not timeout, you need to check your 'trunk' account like: 'pod trunk me', and register code is 'pod trunk register <your email> <your name>'"
298
+ # return
299
+ # end
300
+ # else
301
+ # if (is_static_lib == true ? system("pod repo push #{pod_repo_name} #{podspec_path} --allow-warnings --use-libraries") : system("pod repo push #{pod_repo_name} #{podspec_path} --allow-warnings")) == false
302
+ # return
303
+ # end
304
+ # end
305
+ #
306
+
307
+ end
308
+ end
@@ -0,0 +1,50 @@
1
+ module CocoapodsTools
2
+ require 'claide'
3
+
4
+ class Command < CLAide::Command
5
+
6
+ require 'cocoapods-tools/command/spec/spec'
7
+
8
+ self.abstract_command = true
9
+
10
+ self.description = 'cocoapods-tools'
11
+
12
+ # This would normally default to `beverage-maker`, based on the class’ name.
13
+ self.command = 'ht'
14
+
15
+ def self.options
16
+ [
17
+ # ['--no-milk', 'Don’t add milk to the beverage'],
18
+ # ['--sweetener=[sugar|honey]', 'Use one of the available sweeteners'],
19
+ ].concat(super)
20
+ end
21
+
22
+ def initialize(argv)
23
+ # @add_milk = argv.flag?('milk', true)
24
+ # @sweetener = argv.option('sweetener')
25
+ # puts 'cocoapods init'
26
+ super
27
+ end
28
+
29
+ def validate!
30
+ super
31
+ # puts 'cocoapods validate!'
32
+ # if @sweetener && !%w(sugar honey).include?(@sweetener)
33
+ # help! "`#{@sweetener}' is not a valid sweetener."
34
+ # end
35
+ end
36
+
37
+ def run
38
+ # puts '* cocoapods-tools…run'
39
+ # sleep 1
40
+ # if @add_milk
41
+ # puts '* Adding milk…'
42
+ # sleep 1
43
+ # end
44
+ # if @sweetener
45
+ # puts "* Adding #{@sweetener}…"
46
+ # sleep 1
47
+ # end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,51 @@
1
+ module CocoapodsTools
2
+ class Color
3
+ def self.natural
4
+ 0
5
+ end
6
+
7
+ def self.black
8
+ 30
9
+ end
10
+
11
+ def self.red
12
+ 31
13
+ end
14
+
15
+ def self.green
16
+ 32
17
+ end
18
+
19
+ def self.yellow
20
+ 33
21
+ end
22
+
23
+ def self.blue
24
+ 34
25
+ end
26
+
27
+ def self.magenta
28
+ 35
29
+ end
30
+
31
+ def self.cyan
32
+ 36
33
+ end
34
+
35
+ def self.white
36
+ 37
37
+ end
38
+
39
+ def self.color_text(text, color = Color.natural)
40
+ if color == 0
41
+ return text
42
+ end
43
+ return "\033[#{color}m#{text}\033[0m"
44
+ end
45
+
46
+ def self.die_log(text)
47
+ puts color_text(text, Color.red)
48
+ end
49
+ end
50
+
51
+ end
@@ -0,0 +1,3 @@
1
+ module CocoapodsTools
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ require "cocoapods-tools/version"
2
+
3
+ module CocoapodsTools
4
+ class Error < StandardError; end
5
+ # Your code goes here...
6
+ autoload :Command, 'cocoapods-tools/command'
7
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - pandaleecn
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-02-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: claide
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.3
27
+ description: A Command Line Tool Example
28
+ email:
29
+ - pandaleecn@gmail.com
30
+ executables:
31
+ - ht
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - bin/ht
36
+ - lib/cocoapods-tools.rb
37
+ - lib/cocoapods-tools/command.rb
38
+ - lib/cocoapods-tools/command/spec/init.rb
39
+ - lib/cocoapods-tools/command/spec/spec.rb
40
+ - lib/cocoapods-tools/command/spec/tag.rb
41
+ - lib/cocoapods-tools/helper/color.rb
42
+ - lib/cocoapods-tools/version.rb
43
+ homepage: https://github.com/pandaleecn/cocoapods-tools
44
+ licenses:
45
+ - MIT
46
+ metadata:
47
+ homepage_uri: https://github.com/pandaleecn/cocoapods-tools
48
+ source_code_uri: https://github.com/pandaleecn/cocoapods-tools
49
+ changelog_uri: https://github.com/pandaleecn/cocoapods-tools
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 2.3.0
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubygems_version: 3.3.5
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: cocoapods-tools
69
+ test_files: []