bmp 1.2.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.bmp.yml +3 -3
- data/.editorconfig +1 -2
- data/.rubocop.yml +8 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +15 -1
- data/README.md +42 -3
- data/Rakefile +5 -3
- data/TODO.md +9 -11
- data/bin/bmp +13 -1
- data/bump.gemspec +12 -13
- data/lib/bump.rb +0 -1
- data/lib/bump/application.rb +228 -217
- data/lib/bump/cli.rb +14 -34
- data/lib/bump/command.rb +12 -18
- data/lib/bump/domain.rb +0 -2
- data/lib/bump/domain/bump_info.rb +61 -120
- data/lib/bump/domain/bump_info_repository.rb +32 -42
- data/lib/bump/domain/file_update_rule.rb +41 -68
- data/lib/bump/domain/file_update_rule_factory.rb +19 -27
- data/lib/bump/domain/version_number.rb +39 -56
- data/lib/bump/domain/version_number_factory.rb +14 -20
- data/lib/bump/logger.rb +40 -46
- data/lib/bump/version.rb +1 -2
- data/spec/bump/application_spec.rb +119 -36
- data/spec/bump/cli_spec.rb +8 -1
- data/spec/bump/command_spec.rb +10 -17
- data/spec/bump/domain/bump_info_repository_spec.rb +17 -24
- data/spec/bump/domain/bump_info_spec.rb +50 -26
- data/spec/bump/domain/file_update_rule_factory_spec.rb +16 -26
- data/spec/bump/domain/file_update_rule_spec.rb +23 -33
- data/spec/bump/domain/version_number_factory_spec.rb +8 -31
- data/spec/bump/domain/version_number_spec.rb +46 -98
- data/spec/bump/logger_spec.rb +29 -1
- data/spec/fixture/bmp.yml +1 -1
- data/spec/fixture/bmp_invalid.yml +5 -0
- data/spec/fixture/bmp_invalid_pattern.yml +3 -0
- data/spec/fixture/bmp_tmp.yml +5 -0
- data/spec/spec_helper.rb +1 -4
- metadata +9 -2
data/lib/bump/cli.rb
CHANGED
@@ -1,44 +1,24 @@
|
|
1
|
-
|
2
1
|
require 'bump/version'
|
3
2
|
require 'yaml'
|
4
|
-
require 'slop'
|
5
3
|
|
6
4
|
module Bump
|
5
|
+
# The command line interface
|
6
|
+
class CLI
|
7
|
+
attr_reader :app
|
7
8
|
|
8
|
-
# The
|
9
|
-
|
10
|
-
|
11
|
-
# The bump info filename
|
12
|
-
VERSION_FILE = '.bmp.yml'
|
13
|
-
|
14
|
-
# The cli name
|
15
|
-
CLI_NAME = 'bmp'
|
16
|
-
|
17
|
-
# The main routine
|
18
|
-
#
|
19
|
-
# @return [void]
|
20
|
-
def main
|
21
|
-
|
22
|
-
opts = Slop.parse do |o|
|
23
|
-
o.banner = "Usage: #{CLI_NAME} [-p|-m|-j] [-c]"
|
9
|
+
# The bump info filename
|
10
|
+
VERSION_FILE = '.bmp.yml'.freeze
|
24
11
|
|
25
|
-
|
26
|
-
|
27
|
-
o.bool '-m', '--minor', 'bump minor (0.1.0) level'
|
28
|
-
o.bool '-j', '--major', 'bump major (1.0.0) level'
|
29
|
-
o.bool '-c', '--commit', 'commit bump changes (git required)'
|
30
|
-
o.bool '-h', '--help', 'show this help and exit'
|
31
|
-
o.bool '-v', '--version', 'show the version of this command and exit'
|
32
|
-
o.bool '-r', '--release', 'remove the pre-release version id'
|
33
|
-
o.string '-s', '--preid', 'set the pre-release version id (e.g. alpha, beta.1)'
|
34
|
-
end
|
35
|
-
|
36
|
-
app = Application.new opts.to_hash, opts.to_s, "#{CLI_NAME} v#{Bump::VERSION}", VERSION_FILE, Logger.new
|
37
|
-
|
38
|
-
app.main
|
39
|
-
|
40
|
-
end
|
12
|
+
# The cli name
|
13
|
+
CLI_NAME = 'bmp'.freeze
|
41
14
|
|
15
|
+
def initialize(opts)
|
16
|
+
@app = Application.new opts.to_hash, opts.to_s, "#{CLI_NAME} v#{Bump::VERSION}", VERSION_FILE, Logger.new
|
42
17
|
end
|
43
18
|
|
19
|
+
# The main of cli
|
20
|
+
def main
|
21
|
+
@app.main
|
22
|
+
end
|
23
|
+
end
|
44
24
|
end
|
data/lib/bump/command.rb
CHANGED
@@ -1,22 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
module Bump
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def initialize logger
|
10
|
-
@logger = logger
|
11
|
-
end
|
12
|
-
|
13
|
-
# @param [String] command
|
14
|
-
# @return [void]
|
15
|
-
def exec command
|
16
|
-
@logger.log "===> " + command
|
17
|
-
@logger.log `#{command}`
|
18
|
-
end
|
19
|
-
|
2
|
+
# Command class executes shell command
|
3
|
+
class Command
|
4
|
+
# @param [Bump::Logger] logger
|
5
|
+
def initialize(logger)
|
6
|
+
@logger = logger
|
20
7
|
end
|
21
8
|
|
9
|
+
# @param [String] command
|
10
|
+
# @return [void]
|
11
|
+
def exec(command)
|
12
|
+
@logger.log @logger.green('+' + command)
|
13
|
+
@logger.log `#{command}`, nil
|
14
|
+
end
|
15
|
+
end
|
22
16
|
end
|
data/lib/bump/domain.rb
CHANGED
@@ -1,133 +1,74 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
3
|
module Bump
|
4
|
+
# The bump information model
|
5
|
+
class BumpInfo
|
6
|
+
attr_reader :version, :files, :commit, :after_version, :before_version
|
7
|
+
|
8
|
+
# @param [Bump::VersionNumber] version The version
|
9
|
+
# @param [Array] files The replace patterns
|
10
|
+
# @param [String] commit The commit message
|
11
|
+
def initialize(version, files, commit)
|
12
|
+
@version = version
|
13
|
+
@files = files
|
14
|
+
@commit = commit
|
15
|
+
|
16
|
+
@commit = 'Bump to version v%.%.%' unless @commit
|
17
|
+
|
18
|
+
@before_version = @version.to_s
|
19
|
+
@after_version = @version.to_s
|
20
|
+
end
|
4
21
|
|
5
|
-
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
# @param [String] commit The commit message
|
11
|
-
def initialize version, files, commit
|
12
|
-
@version = version
|
13
|
-
@files = files
|
14
|
-
@commit = commit
|
15
|
-
|
16
|
-
if not @commit
|
17
|
-
@commit = 'Bump to version v%.%.%'
|
18
|
-
end
|
19
|
-
|
20
|
-
@before_version = @version.to_s
|
21
|
-
@after_version = @version.to_s
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
# Returns the version number object
|
26
|
-
#
|
27
|
-
# @return [Bump::VersionNumber]
|
28
|
-
def version
|
29
|
-
@version
|
30
|
-
end
|
31
|
-
|
32
|
-
# Returns files setting list
|
33
|
-
#
|
34
|
-
# @return [Array]
|
35
|
-
def files
|
36
|
-
@files
|
37
|
-
end
|
38
|
-
|
39
|
-
# Returns the commit message
|
40
|
-
#
|
41
|
-
# @return [String]
|
42
|
-
def commit
|
43
|
-
@commit
|
44
|
-
end
|
45
|
-
|
46
|
-
# Gets the commit message with the current version number
|
47
|
-
#
|
48
|
-
# @return [String]
|
49
|
-
def getCommitMessage
|
50
|
-
@commit.sub '%.%.%', @after_version
|
51
|
-
end
|
52
|
-
|
53
|
-
# Performs bumping version
|
54
|
-
#
|
55
|
-
# @param [Symbol] level
|
56
|
-
# @return [void]
|
57
|
-
def bump level
|
58
|
-
@version.bump level
|
59
|
-
@after_version = @version.to_s
|
60
|
-
end
|
61
|
-
|
62
|
-
# Sets the preid
|
63
|
-
#
|
64
|
-
# @return [void]
|
65
|
-
def setPreid preid
|
66
|
-
@version.setPreid preid
|
67
|
-
@after_version = @version.to_s
|
68
|
-
end
|
69
|
-
|
70
|
-
# Gets the file update rules
|
71
|
-
#
|
72
|
-
# @return [Array<Bump::FileUpdateRules>]
|
73
|
-
def updateRules
|
74
|
-
createUpdateRules
|
75
|
-
end
|
76
|
-
|
77
|
-
# Creates file update rules according to the current settings.
|
78
|
-
#
|
79
|
-
# @private
|
80
|
-
# @return [Array<Bump::FileUpdateRule>]
|
81
|
-
def createUpdateRules
|
82
|
-
@files.map { |file, pattern|
|
83
|
-
FileUpdateRuleFactory.create(file, pattern, @before_version, @after_version)
|
84
|
-
}.flatten
|
85
|
-
end
|
86
|
-
|
87
|
-
# Performs all updates.
|
88
|
-
#
|
89
|
-
# @return [void]
|
90
|
-
def performUpdate
|
91
|
-
|
92
|
-
createUpdateRules.each do |rule|
|
93
|
-
|
94
|
-
rule.perform
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
# Checks the all the version patterns are available
|
101
|
-
#
|
102
|
-
# @return [Boolean]
|
103
|
-
def check
|
104
|
-
|
105
|
-
createUpdateRules.each do |rule|
|
22
|
+
# Gets the commit message with the current version number
|
23
|
+
# @return [String]
|
24
|
+
def commit_message
|
25
|
+
@commit.sub '%.%.%', @after_version
|
26
|
+
end
|
106
27
|
|
107
|
-
|
108
|
-
|
109
|
-
|
28
|
+
# Performs bumping version.
|
29
|
+
# @param [Symbol] level
|
30
|
+
def bump(level)
|
31
|
+
@version.bump level
|
32
|
+
@after_version = @version.to_s
|
33
|
+
end
|
110
34
|
|
111
|
-
|
35
|
+
# Sets the preid.
|
36
|
+
# @param [String] preid The pre id
|
37
|
+
def preid=(preid)
|
38
|
+
@version.preid = preid
|
39
|
+
@after_version = @version.to_s
|
40
|
+
end
|
112
41
|
|
113
|
-
|
42
|
+
# Gets the file update rules.
|
43
|
+
# @return [Array<Bump::FileUpdateRules>]
|
44
|
+
def update_rules
|
45
|
+
create_update_rules
|
46
|
+
end
|
114
47
|
|
115
|
-
|
48
|
+
# Creates file update rules according to the current settings.
|
49
|
+
# @private
|
50
|
+
# @return [Array<Bump::FileUpdateRule>]
|
51
|
+
def create_update_rules
|
52
|
+
@files.map do |file, pattern|
|
53
|
+
FileUpdateRuleFactory.create(file, pattern, @before_version, @after_version)
|
54
|
+
end.flatten
|
55
|
+
end
|
116
56
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
57
|
+
# Performs all updates.
|
58
|
+
#
|
59
|
+
# @return [void]
|
60
|
+
def perform_update
|
61
|
+
create_update_rules.each(&:perform)
|
62
|
+
end
|
123
63
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
64
|
+
# Checks the all the version patterns are available
|
65
|
+
# @return [Boolean]
|
66
|
+
def valid?
|
67
|
+
create_update_rules.each do |rule|
|
68
|
+
return false if !rule.file_exists || !rule.pattern_exists
|
69
|
+
end
|
130
70
|
|
71
|
+
true
|
131
72
|
end
|
132
|
-
|
73
|
+
end
|
133
74
|
end
|
@@ -1,54 +1,44 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
3
|
module Bump
|
4
|
+
# The repository class for the bump info
|
5
|
+
# persistence in file as yaml string
|
6
|
+
class BumpInfoRepository
|
7
|
+
# @param [String] file
|
8
|
+
def initialize(file)
|
9
|
+
@file = file
|
10
|
+
end
|
4
11
|
|
5
|
-
#
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
# Gets the bump info from the given file
|
15
|
-
#
|
16
|
-
# @param [String] file
|
17
|
-
# @return [Bump::BumpInfo]
|
18
|
-
def fromFile
|
19
|
-
|
20
|
-
config = YAML.load_file @file
|
21
|
-
version = VersionNumberFactory.fromString config['version']
|
22
|
-
|
23
|
-
BumpInfo.new version, config['files'], config['commit']
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
# Saves the bump info
|
28
|
-
#
|
29
|
-
# @param [Bump::BumpInfo] bumpInfo
|
30
|
-
# @return [void]
|
31
|
-
def save bumpInfo
|
32
|
-
File.write @file, toYaml(bumpInfo)
|
33
|
-
end
|
34
|
-
|
35
|
-
# @private
|
36
|
-
# @param [Bump::BumpInfo] bumpInfo
|
37
|
-
# @return [Hash]
|
38
|
-
def toYaml bumpInfo
|
12
|
+
# Gets the bump info from the given file
|
13
|
+
#
|
14
|
+
# @param [String] file
|
15
|
+
# @return [Bump::BumpInfo]
|
16
|
+
def from_file
|
17
|
+
config = YAML.load_file @file
|
18
|
+
version = VersionNumberFactory.from_string config['version']
|
39
19
|
|
40
|
-
|
20
|
+
BumpInfo.new version, config['files'], config['commit']
|
21
|
+
end
|
41
22
|
|
42
|
-
|
43
|
-
|
44
|
-
|
23
|
+
# Saves the bump info
|
24
|
+
#
|
25
|
+
# @param [Bump::BumpInfo] bumpInfo
|
26
|
+
# @return [void]
|
27
|
+
def save(bump_info)
|
28
|
+
File.write @file, to_yaml(bump_info)
|
29
|
+
end
|
45
30
|
|
46
|
-
|
31
|
+
# @private
|
32
|
+
# @param [Bump::BumpInfo] bumpInfo
|
33
|
+
# @return [Hash]
|
34
|
+
def to_yaml(bump_info)
|
35
|
+
hash = { 'version' => bump_info.version.to_s }
|
47
36
|
|
48
|
-
|
37
|
+
hash['commit'] = bump_info.commit if bump_info.commit
|
49
38
|
|
50
|
-
|
39
|
+
hash['files'] = bump_info.files
|
51
40
|
|
41
|
+
hash.to_yaml
|
52
42
|
end
|
53
|
-
|
43
|
+
end
|
54
44
|
end
|
@@ -1,76 +1,49 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
module Bump
|
2
|
+
# The file update rule model
|
3
|
+
#
|
4
|
+
# is able to perform actual file update
|
5
|
+
class FileUpdateRule
|
6
|
+
attr_reader :file, :before_pattern, :after_pattern
|
7
|
+
|
8
|
+
# The placeholder pattern
|
9
|
+
PLACEHOLDER_PATTERN = '%.%.%'.freeze
|
10
|
+
|
11
|
+
# @param [String] file
|
12
|
+
# @param [String] pattern
|
13
|
+
# @param [Bump::VersionNumber] before_version
|
14
|
+
# @param [Bump::VersionNumber] after_version
|
15
|
+
def initialize(file, pattern, before_version, after_version)
|
16
|
+
@file = file
|
17
|
+
@pattern = pattern || PLACEHOLDER_PATTERN # default pattern is '%.%.%'
|
18
|
+
@before_version = before_version
|
19
|
+
@after_version = after_version
|
20
|
+
@before_pattern = @pattern.sub PLACEHOLDER_PATTERN, @before_version
|
21
|
+
@after_pattern = @pattern.sub PLACEHOLDER_PATTERN, @after_version
|
22
|
+
end
|
4
23
|
|
5
|
-
#
|
24
|
+
# Gets the contents of the file
|
6
25
|
#
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
PLACEHOLDER_PATTERN = '%.%.%'
|
12
|
-
|
13
|
-
# @param [String] file
|
14
|
-
# @param [String] pattern
|
15
|
-
# @param [Bump::VersionNumber] before_version
|
16
|
-
# @param [Bump::VersionNumber] after_version
|
17
|
-
def initialize(file, pattern, before_version, after_version)
|
18
|
-
@file = file
|
19
|
-
@pattern = pattern || PLACEHOLDER_PATTERN # default pattern is '%.%.%'
|
20
|
-
@before_version = before_version
|
21
|
-
@after_version = after_version
|
22
|
-
@before_pattern = @pattern.sub PLACEHOLDER_PATTERN, @before_version
|
23
|
-
@after_pattern = @pattern.sub PLACEHOLDER_PATTERN, @after_version
|
24
|
-
end
|
25
|
-
|
26
|
-
# Gets the file name
|
27
|
-
#
|
28
|
-
# @return [String]
|
29
|
-
def file
|
30
|
-
@file
|
31
|
-
end
|
32
|
-
|
33
|
-
# Gets the version string before bumping
|
34
|
-
#
|
35
|
-
# @return [String]
|
36
|
-
def beforePattern
|
37
|
-
@before_pattern
|
38
|
-
end
|
39
|
-
|
40
|
-
# Gets the version string after bumping
|
41
|
-
#
|
42
|
-
# @return [String]
|
43
|
-
def afterPattern
|
44
|
-
@after_pattern
|
45
|
-
end
|
46
|
-
|
47
|
-
# Gets the contents of the file
|
48
|
-
#
|
49
|
-
# @return [String]
|
50
|
-
def fileGetContents
|
51
|
-
File.read @file, :encoding => Encoding::UTF_8
|
52
|
-
end
|
53
|
-
|
54
|
-
# Returns true if the file exists
|
55
|
-
# @return [Boolean]
|
56
|
-
def fileExists
|
57
|
-
File.exist? @file
|
58
|
-
end
|
59
|
-
|
60
|
-
# Checks if the pattern found in the file
|
61
|
-
#
|
62
|
-
# @return [Boolean]
|
63
|
-
def patternExists
|
64
|
-
fileGetContents.index(@before_pattern) != nil
|
65
|
-
end
|
26
|
+
# @return [String]
|
27
|
+
def file_get_contents
|
28
|
+
File.read @file, encoding: Encoding::UTF_8
|
29
|
+
end
|
66
30
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
31
|
+
# Returns true if the file exists
|
32
|
+
# @return [Boolean]
|
33
|
+
def file_exists
|
34
|
+
File.exist? @file
|
35
|
+
end
|
73
36
|
|
37
|
+
# Checks if the pattern found in the file
|
38
|
+
# @return [Boolean]
|
39
|
+
def pattern_exists
|
40
|
+
!file_get_contents.index(@before_pattern).nil?
|
74
41
|
end
|
75
42
|
|
43
|
+
# Performs file update
|
44
|
+
# @return [void]
|
45
|
+
def perform
|
46
|
+
File.write @file, file_get_contents.sub(@before_pattern, @after_pattern)
|
47
|
+
end
|
48
|
+
end
|
76
49
|
end
|