This repository has been archived by the owner on Aug 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Rakefile
74 lines (60 loc) · 2.1 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require 'json'
require 'nokogiri'
require 'semver'
desc <<~DESC
Update all version strings to match the current version.
This includes the "general", Android, iOS version codes in config.xml
as well as the version stored in package.json.
DESC
task version: 'version:default'
namespace :version do
task default: [:deps, :modify_general, :modify_android, :modify_ios] do
Rake::Task['version:cleanup'].invoke
end
desc <<~DESC
Update the "general" version code to match the current version.
Also updates the version stored in package.json.
DESC
task general: [:deps, :modify_general] do
Rake::Task['version:cleanup'].invoke
end
desc 'Update the Android version code to match the current version.'
task android: [:deps, :modify_android] do
Rake::Task['version:cleanup'].invoke
end
desc 'Update the iOS version code to match the current version.'
task ios: [:deps, :modify_ios] do
Rake::Task['version:cleanup'].invoke
end
task :modify_general do
attribute = @doc.at_css('widget').attributes['version']
version = @version.format("%M.%m.%p%s")
attribute.value = @json['version'] = version
end
task :modify_android do
attribute = @doc.at_css('widget').attributes['android-versionCode']
version = "%d%02d%02d" % [@version.major, @version.minor, @version.patch]
attribute.value = version
end
task :modify_ios do
attribute = @doc.at_css('widget').attributes['ios-CFBundleVersion']
attribute.value = @version.format("%M.%m.%p%s")
end
task :deps do
@version = SemVer.find
config_filename = File.join(__dir__, 'config.xml')
config_file = File.open(config_filename, 'r')
@doc = Nokogiri::XML(config_file)
@config_file = config_file.reopen(config_filename, 'w')
package_filename = File.join(__dir__, 'package.json')
package_file = File.open(package_filename, 'r')
@json = JSON.parse(package_file.read)
@package_file = package_file.reopen(package_filename, 'w')
end
task :cleanup do
@config_file.write @doc.to_xml
@config_file.close
@package_file.write JSON.pretty_generate(@json)
@package_file.close
end
end