incr 0.4.0 → 0.7.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 +5 -5
- data/Gemfile.lock +2 -2
- data/README.md +5 -4
- data/bin/incr +5 -2
- data/lib/incr/command/mix.rb +19 -6
- data/lib/incr/command/npm.rb +19 -6
- data/lib/incr/service/file_helper.rb +6 -2
- data/lib/incr/version.rb +1 -1
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 637f1247da8e04e0718b52ef9e2a10998615107658b6cc81b1229b9ed2d03e59
|
4
|
+
data.tar.gz: b79e61194d1eca2a6ee102c0a85fd9a0c2be352c041994a129e68b20932a811c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 357ac98e744072a23294c56b527c4393efa9c73fb78dfee45b735c22e0f787475479099eb9dfaa35fd3d945b31fb7fdc522e55fabe98b98c8c2fc5f76c12549b
|
7
|
+
data.tar.gz: 0c829902f6251d72b5ef17ceeb49a831a2a7503916fc954ff0eb70ef139e2cbd1248ef33e6ffec467f5139c31f83200bf34c9bc4fd45c87d78aaf83ee2c1b4e4
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -6,8 +6,7 @@
|
|
6
6
|
Incr is a tool to help you easily increment the version number of your NPM or Mix packages.
|
7
7
|
<br /><br />
|
8
8
|
<a href="https://rubygems.org/gems/incr"><img src="http://img.shields.io/gem/v/incr.svg" /></a>
|
9
|
-
|
10
|
-
<a href="https://gemnasium.com/jcouture/incr"><img src="http://img.shields.io/gemnasium/jcouture/incr.svg" /></a>
|
9
|
+
|
11
10
|
<a href="https://travis-ci.org/jcouture/incr"><img src="http://img.shields.io/travis/jcouture/incr.svg" /></a>
|
12
11
|
</p>
|
13
12
|
|
@@ -46,16 +45,18 @@ To increment the minor segment of your Mix package version number:
|
|
46
45
|
Here are some arguments that can be used with `incr`:
|
47
46
|
- `-d` : Directory where to search for the version files (default: `.`)
|
48
47
|
- `-t` : Tag name pattern, where `%s` will be replaced with the new version (default: `v%s`)
|
48
|
+
- `--[no-]commit` : Commit changes. (default: enabled)
|
49
|
+
- `--[no-]tag` : Create a git tag. (default: enabled)
|
49
50
|
|
50
51
|
Example:
|
51
52
|
```shell
|
52
|
-
~> incr
|
53
|
+
~> incr --no-tag -d ./subprojects/web/ -t MyCustomTagPrefix/%s npm patch
|
53
54
|
```
|
54
55
|
|
55
56
|
This will :
|
56
57
|
- Search for `package.json` and `package-lock.json` files inside `./subprojects/web/` and update the patch version
|
57
|
-
- Create a tag named `MyCustomTagPrefix/2.3.4`
|
58
58
|
- Commit the changes under the message `MyCustomTagPrefix/2.3.4`
|
59
|
+
- Not create a tag with the new version
|
59
60
|
|
60
61
|
## Contributing
|
61
62
|
|
data/bin/incr
CHANGED
@@ -10,8 +10,11 @@ include GLI::App
|
|
10
10
|
program_desc('Tasteful utility to increment the version number and create a corresponding git tag.')
|
11
11
|
version(Incr::VERSION)
|
12
12
|
|
13
|
-
flag [:d, :versionFileDirectory], :default_value => '.', :desc => 'Directory where to search for version file
|
14
|
-
flag [:t, :tagNamePattern], :default_value => 'v%s'
|
13
|
+
flag [:d, :versionFileDirectory], :default_value => '.', :desc => 'Directory where to search for version file'
|
14
|
+
flag [:t, :tagNamePattern], :default_value => 'v%s', :desc => 'Pattern for the tag name'
|
15
|
+
|
16
|
+
switch :commit, :default_value => true, :desc => 'Commit changes'
|
17
|
+
switch :tag, :default_value => true, :desc => 'Create a git tag'
|
15
18
|
|
16
19
|
pre do |global, command, options, args|
|
17
20
|
if args.length != 1 || !['major', 'minor', 'patch'].any? {|segment| args.include?(segment)}
|
data/lib/incr/command/mix.rb
CHANGED
@@ -1,10 +1,18 @@
|
|
1
1
|
module Incr
|
2
2
|
module Command
|
3
3
|
class Mix
|
4
|
+
VERSION_REGEX = /@?version:?\W*\"(\d*.\d*.\d*)"/
|
5
|
+
VERSION_REPLACEMENT_PATTERNS = [
|
6
|
+
"version: \"%s\"",
|
7
|
+
"@version \"%s\""
|
8
|
+
]
|
9
|
+
|
4
10
|
def initialize(args, global_options)
|
5
11
|
@segment = args[0]
|
6
12
|
@mix_file_filename = File.join('.', global_options[:versionFileDirectory], 'mix.exs')
|
7
13
|
@tag_pattern = global_options[:tagNamePattern]
|
14
|
+
@commit = global_options[:commit]
|
15
|
+
@tag = global_options[:tag]
|
8
16
|
end
|
9
17
|
|
10
18
|
def execute
|
@@ -13,10 +21,10 @@ module Incr
|
|
13
21
|
return
|
14
22
|
end
|
15
23
|
|
16
|
-
file_version = file_content.match(
|
24
|
+
file_version = file_content.match(VERSION_REGEX)[1]
|
17
25
|
old_version = SemVersion.new(file_version)
|
18
26
|
new_version = Incr::Service::Version.increment_segment(old_version, @segment)
|
19
|
-
|
27
|
+
replace_file_version(old_version, new_version)
|
20
28
|
|
21
29
|
new_tag = @tag_pattern % new_version.to_s
|
22
30
|
|
@@ -24,8 +32,8 @@ module Incr
|
|
24
32
|
|
25
33
|
repository = Incr::Service::Repository.new('.')
|
26
34
|
repository.add(@mix_file_filename)
|
27
|
-
repository.commit(new_tag)
|
28
|
-
repository.tag(new_tag)
|
35
|
+
repository.commit(new_tag) if @commit
|
36
|
+
repository.tag(new_tag) if @tag
|
29
37
|
end
|
30
38
|
|
31
39
|
private
|
@@ -39,8 +47,13 @@ module Incr
|
|
39
47
|
IO.read(filename)
|
40
48
|
end
|
41
49
|
|
42
|
-
def
|
43
|
-
|
50
|
+
def replace_file_version(old_version, new_version)
|
51
|
+
VERSION_REPLACEMENT_PATTERNS.each do |pattern|
|
52
|
+
old_version_pattern = format(pattern, old_version.to_s)
|
53
|
+
new_version_pattern = format(pattern, new_version.to_s)
|
54
|
+
|
55
|
+
Incr::Service::FileHelper.replace_string_once(@mix_file_filename, old_version_pattern, new_version_pattern)
|
56
|
+
end
|
44
57
|
end
|
45
58
|
end
|
46
59
|
end
|
data/lib/incr/command/npm.rb
CHANGED
@@ -4,6 +4,14 @@ require 'sem_version'
|
|
4
4
|
module Incr
|
5
5
|
module Command
|
6
6
|
class Npm
|
7
|
+
# pattern for any semver version, including pre-release label (ie. 1.0.0-alpha)
|
8
|
+
VERSION_PATTERN = "[\\w\\.\\-]*"
|
9
|
+
|
10
|
+
# pattern preceding the version in package.json and package-lock.json (v1 and v2)
|
11
|
+
LOOKBEHIND_PATTERNS = [
|
12
|
+
"\\A{[^{}]*\"version\": \"\\K",
|
13
|
+
"\"\": {[^{}]*\"version\": \"\\K"
|
14
|
+
]
|
7
15
|
|
8
16
|
def initialize(args, global_options)
|
9
17
|
@segment = args[0]
|
@@ -11,6 +19,8 @@ module Incr
|
|
11
19
|
@package_json_filename = File.join('.', global_options[:versionFileDirectory], 'package.json')
|
12
20
|
@package_json_lock_filename = File.join('.', global_options[:versionFileDirectory], 'package-lock.json')
|
13
21
|
@tag_pattern = global_options[:tagNamePattern]
|
22
|
+
@commit = global_options[:commit]
|
23
|
+
@tag = global_options[:tag]
|
14
24
|
end
|
15
25
|
|
16
26
|
def execute
|
@@ -23,8 +33,8 @@ module Incr
|
|
23
33
|
old_version = SemVersion.new(file_version)
|
24
34
|
new_version = Incr::Service::Version.increment_segment(old_version, @segment)
|
25
35
|
|
26
|
-
|
27
|
-
|
36
|
+
replace_file_version(@package_json_filename, new_version.to_s)
|
37
|
+
replace_file_version(@package_json_lock_filename, new_version.to_s)
|
28
38
|
|
29
39
|
new_tag = @tag_pattern % new_version.to_s
|
30
40
|
|
@@ -33,8 +43,8 @@ module Incr
|
|
33
43
|
repository = Incr::Service::Repository.new('.')
|
34
44
|
repository.add(@package_json_filename)
|
35
45
|
repository.add(@package_json_lock_filename)
|
36
|
-
repository.commit(new_tag)
|
37
|
-
repository.tag(new_tag)
|
46
|
+
repository.commit(new_tag) if @commit
|
47
|
+
repository.tag(new_tag) if @tag
|
38
48
|
end
|
39
49
|
|
40
50
|
private
|
@@ -48,8 +58,11 @@ module Incr
|
|
48
58
|
JSON.parse(IO.read(filename))
|
49
59
|
end
|
50
60
|
|
51
|
-
def
|
52
|
-
|
61
|
+
def replace_file_version(filename, new_version)
|
62
|
+
LOOKBEHIND_PATTERNS.each do |lookbehind_pattern|
|
63
|
+
pattern = /#{lookbehind_pattern}#{VERSION_PATTERN}/
|
64
|
+
Incr::Service::FileHelper.replace_regexp_once(filename, pattern, new_version)
|
65
|
+
end
|
53
66
|
end
|
54
67
|
end
|
55
68
|
end
|
@@ -1,9 +1,13 @@
|
|
1
1
|
module Incr
|
2
2
|
module Service
|
3
3
|
class FileHelper
|
4
|
-
def self.
|
4
|
+
def self.replace_string_once(filename, old_text, new_text)
|
5
|
+
replace_regexp_once(/#{Regexp.escape(old_text)}/, new_text)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.replace_regexp_once(filename, pattern, replacement_text)
|
5
9
|
old_content = File.read(filename)
|
6
|
-
new_content = old_content.sub(
|
10
|
+
new_content = old_content.sub(pattern, replacement_text)
|
7
11
|
File.open(filename, 'w') { |file| file << new_content }
|
8
12
|
end
|
9
13
|
end
|
data/lib/incr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: incr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean-Philippe Couture
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gli
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 1.3.0
|
55
|
-
description:
|
55
|
+
description:
|
56
56
|
email:
|
57
57
|
- jcouture@gmail.com
|
58
58
|
executables:
|
@@ -79,7 +79,7 @@ homepage: https://github.com/jcouture/incr
|
|
79
79
|
licenses:
|
80
80
|
- MIT
|
81
81
|
metadata: {}
|
82
|
-
post_install_message:
|
82
|
+
post_install_message:
|
83
83
|
rdoc_options: []
|
84
84
|
require_paths:
|
85
85
|
- lib
|
@@ -95,9 +95,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
requirements: []
|
98
|
-
|
99
|
-
|
100
|
-
signing_key:
|
98
|
+
rubygems_version: 3.3.3
|
99
|
+
signing_key:
|
101
100
|
specification_version: 4
|
102
101
|
summary: Tasteful utility to increment the version number and create a corresponding
|
103
102
|
git tag.
|