Class: Pod::Command::Binary::Lib::Upgrade
Class Method Summary
collapse
Instance Method Summary
collapse
#binary_config, #first_podspec, #private_sources
Constructor Details
#initialize(argv) ⇒ Upgrade
23
24
25
26
27
28
29
|
# File 'lib/cocoapods-tdfire-binary/command/lib/upgrade.rb', line 23
def initialize(argv)
@type = argv.option('type') || 'patch'
@version = argv.option('version')
@commit = argv.option('commit')
@spec_file = first_podspec
super
end
|
Class Method Details
.options ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/cocoapods-tdfire-binary/command/lib/upgrade.rb', line 15
def self.options
[
['--type', '更新版本类型,patch/minor/major'],
['--version', '更新版本号,优先级比 --type 高'],
['--commit', '提交 commit 日志,没有设置则不 add']
].concat(super)
end
|
Instance Method Details
#run ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/cocoapods-tdfire-binary/command/lib/upgrade.rb', line 36
def run
path = Pathname.new(@spec_file)
spec = Pod::Specification.from_file(path)
version = unit_increase_version(spec.version, @type)
version = @version if @version
UI.section("Tdfire: upgrade podspec version to #{version} ...") do
spec_string = File.read(Pathname.new(@spec_file))
spec_content = update_podspec_content(spec_string, version)
File.open(path, "w") do |io|
io << spec_content
end
if @commit
`git add #{path}`
`git commit -m "#{@commit}"`
end
end
end
|
#unit_increase_version(version, type) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/cocoapods-tdfire-binary/command/lib/upgrade.rb', line 67
def unit_increase_version(version, type)
major = version.major
minor = version.minor
patch = version.patch
case type
when 'major'
major += 1
when 'minor'
minor += 1
when 'patch'
patch += 1
else
end
Pod::Version.new("#{major}.#{minor}.#{patch}")
end
|
#update_podspec_content(podspec_content, version) ⇒ Object
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/cocoapods-tdfire-binary/command/lib/upgrade.rb', line 56
def update_podspec_content(podspec_content, version)
require_variable_prefix = true
version_var_name = 'version'
variable_prefix = require_variable_prefix ? /\w\./ : //
version_regex = /^(?<begin>[^#]*#{variable_prefix}#{version_var_name}\s*=\s*['"])(?<value>(?<major>[0-9]+)(\.(?<minor>[0-9]+))?(\.(?<patch>[0-9]+))?(?<appendix>(\.[0-9]+)*)?(-(?<prerelease>(.+)))?)(?<end>['"])/i
version_match = version_regex.match(podspec_content)
updated_podspec_content = podspec_content.gsub(version_regex, "#{version_match[:begin]}#{version}#{version_match[:end]}")
updated_podspec_content
end
|
#validate! ⇒ Object
31
32
33
34
|
# File 'lib/cocoapods-tdfire-binary/command/lib/upgrade.rb', line 31
def validate!
super
help! '当前目录下没有podspec文件.' if @spec_file.nil?
end
|