incr 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d059fe92f6628e9b0bae63291a88ad1eda8fb3d
4
- data.tar.gz: ea9db15b60a3b059a9d653904af4d57b4d569186
3
+ metadata.gz: 7bdaa6e710bb2671d274aeacae659da6b6f554c4
4
+ data.tar.gz: 7a00062159e3d02ce80fb392f498d3f676c28d62
5
5
  SHA512:
6
- metadata.gz: ff4cb64daaa3a77c68599040064c4b716af0a94102e4fd6ea48cd394b7860f08d2471580cb6e8888b09e898d5c37a50c091b83e38a3e5758b7df7505acd10825
7
- data.tar.gz: 6dec466693726597dac4e460be389d6c614f800b54c1a72f2c06aba90eecac92c9cef6fc85b27d1f868fd5677bd6fea5f8a7ea16e07dba31acd429c18dfa07e7
6
+ metadata.gz: 3139a7c692f8294ae936b2752d3758f7421b050dc5666b69be161d2f96505495b3591f416c146aade7fa0762421e5196b072ca0ccd1d94f5be1914bd36524655
7
+ data.tar.gz: eef09657bf9e8e0ccba569c77ef603df5e2449b7c6cb5a64f65dea5053238e0238bd2959ee8ee9a0e4e5083cd90a091de8381e428001a06cd19e82a572d703c8
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at jcouture@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in incr.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,23 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ incr (0.1.0)
5
+ gli (= 2.17.1)
6
+ rugged (= 0.26.0)
7
+ sem_version (= 2.0.1)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ gli (2.17.1)
13
+ rugged (0.26.0)
14
+ sem_version (2.0.1)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ incr!
21
+
22
+ BUNDLED WITH
23
+ 1.16.0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Jean-Philippe Couture
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ <p align="center">
2
+ <a href="https://github.com/jcouture/incr">
3
+ <img src="https://i.imgur.com/cHimJRm.png" alt="incr" />
4
+ </a>
5
+ <br />
6
+ Incr is a tool to help you easily increment the version number of your NPM or Mix packages.
7
+ <br /><br />
8
+ <a href="https://rubygems.org/gems/incr"><img src="http://img.shields.io/gem/v/incr.svg" /></a>
9
+ <a href="https://codeclimate.com/github/jcouture/incr"><img src="http://img.shields.io/codeclimate/github/jcouture/incr.svg" /></a>
10
+ <a href="https://gemnasium.com/jcouture/incr"><img src="http://img.shields.io/gemnasium/jcouture/incr.svg" /></a>
11
+ <a href="https://travis-ci.org/jcouture/incr"><img src="http://img.shields.io/travis/jcouture/incr.svg" /></a>
12
+ </p>
13
+
14
+ ## Installation
15
+
16
+ ```shell
17
+ ~> gem install incr
18
+ ```
19
+
20
+ incr depends on the [Rugged](https://github.com/libgit2/rugged) Ruby bindings for [libgit2](https://libgit2.github.com/). You need to have `CMake` and `pkg-config` installed on your system to be able to build the included version of libgit2.
21
+ On OS X, after installing [Homebrew](https://brew.sh/), you can get CMake with:
22
+
23
+ ```shell
24
+ ~> brew install cmake
25
+ ```
26
+
27
+ ## Usage
28
+ To increment the patch segment of your NPM package version number:
29
+ ```shell
30
+ ~> incr npm patch
31
+ ```
32
+
33
+ To increment the minor segment of your Mix package version number:
34
+ ```shell
35
+ ~> incr mix minor
36
+ ```
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jcouture/incr. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
45
+
46
+ The incr shield logo is based on [this icon](https://thenounproject.com/term/increment/621415/) by [blackspike](https://thenounproject.com/blackspike/), from the Noun Project. Used under a [Creative Commons BY 3.0](http://creativecommons.org/licenses/by/3.0/) license.
data/incr.gemspec ADDED
@@ -0,0 +1,24 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'incr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'incr'
8
+ spec.version = Incr::VERSION
9
+ spec.authors = ['Jean-Philippe Couture']
10
+ spec.email = ['jcouture@gmail.com']
11
+
12
+ spec.summary = 'Tasteful utility to increment the version number and create a corresponding git tag.'
13
+ spec.homepage = 'https://github.com/jcouture/incr'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split("\n")
17
+ spec.bindir = 'bin'
18
+ spec.executables << 'incr'
19
+ spec.require_paths << 'lib'
20
+
21
+ spec.add_runtime_dependency('gli', '2.17.1')
22
+ spec.add_runtime_dependency('sem_version', '2.0.1')
23
+ spec.add_runtime_dependency('rugged', '0.26.0')
24
+ end
data/lib/incr.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'incr/service/git'
2
+ require 'incr/service/version'
3
+ require 'incr/service/file_helper'
4
+ require 'incr/command/npm'
5
+ require 'incr/command/mix'
6
+ require 'incr/version'
@@ -0,0 +1,45 @@
1
+ module Incr
2
+ module Command
3
+ class Mix
4
+ MIXFILE_FILENAME = 'mix.exs'.freeze
5
+
6
+ def initialize(args)
7
+ @segment = args[0]
8
+ end
9
+
10
+ def execute
11
+ file_content = parse_content(MIXFILE_FILENAME)
12
+ if file_content == nil
13
+ return
14
+ end
15
+
16
+ file_version = file_content.match(/version:\W*\"(\d*.\d*.\d*)",/)[1]
17
+ old_version = SemVersion.new(file_version)
18
+ new_version = Incr::Service::Version.increment_segment(old_version, @segment)
19
+ Incr::Service::FileHelper.replace(MIXFILE_FILENAME, version_pattern(old_version.to_s), version_pattern(new_version.to_s))
20
+
21
+ puts "v#{new_version.to_s}"
22
+
23
+ git = Incr::Service::Git.new('.')
24
+ git.add(MIXFILE_FILENAME)
25
+ oid = git.commit(new_version.to_s)
26
+ git.tag("v#{new_version.to_s}", oid)
27
+ end
28
+
29
+ private
30
+
31
+ def parse_content(filename)
32
+ if !File.exist?(filename)
33
+ STDERR.puts("[Err] '#{filename}' not found.")
34
+ return nil
35
+ end
36
+
37
+ IO.read(filename)
38
+ end
39
+
40
+ def version_pattern(version)
41
+ "version: \"#{version}\""
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,52 @@
1
+ require 'json'
2
+ require 'sem_version'
3
+
4
+ module Incr
5
+ module Command
6
+ class Npm
7
+ PACKAGE_JSON_FILENAME = 'package.json'.freeze
8
+ PACKAGE_LOCK_JSON_FILENAME = 'package-lock.json'.freeze
9
+
10
+ def initialize(args)
11
+ @segment = args[0]
12
+ end
13
+
14
+ def execute
15
+ package_json = parse_content(PACKAGE_JSON_FILENAME)
16
+ if package_json == nil
17
+ return
18
+ end
19
+
20
+ file_version = package_json['version']
21
+ old_version = SemVersion.new(file_version)
22
+ new_version = Incr::Service::Version.increment_segment(old_version, @segment)
23
+
24
+ Incr::Service::FileHelper.replace(PACKAGE_JSON_FILENAME, version_pattern(old_version.to_s), version_pattern(new_version.to_s))
25
+ Incr::Service::FileHelper.replace(PACKAGE_LOCK_JSON_FILENAME, version_pattern(old_version.to_s), version_pattern(new_version.to_s))
26
+
27
+ puts "v#{new_version.to_s}"
28
+
29
+ git = Incr::Service::Git.new('.')
30
+ git.add(PACKAGE_JSON_FILENAME)
31
+ git.add(PACKAGE_LOCK_JSON_FILENAME)
32
+ oid = git.commit(new_version.to_s)
33
+ git.tag("v#{new_version.to_s}", oid)
34
+ end
35
+
36
+ private
37
+
38
+ def parse_content(filename)
39
+ if !File.exist?(filename)
40
+ STDERR.puts("[Err] '#{filename}' not found.")
41
+ return nil
42
+ end
43
+
44
+ JSON.parse(IO.read(filename))
45
+ end
46
+
47
+ def version_pattern(version)
48
+ "\"version\": \"#{version}\""
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,11 @@
1
+ module Incr
2
+ module Service
3
+ class FileHelper
4
+ def self.replace(filename, old_text, new_text)
5
+ old_content = File.read(filename)
6
+ new_content = old_content.gsub(/#{Regexp.escape(old_text)}/, new_text)
7
+ File.open(filename, 'w') { |file| file << new_content }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,46 @@
1
+ require 'rugged'
2
+
3
+ module Incr
4
+ module Service
5
+ class Git
6
+ def initialize(path)
7
+ @repository = Rugged::Repository.new(path)
8
+ @index = @repository.index
9
+ @author = @repository.head.target.author
10
+ end
11
+
12
+ def add(filename)
13
+ @index.add(filename)
14
+ @index.write
15
+ end
16
+
17
+ def commit(message)
18
+ options = {}
19
+ options[:tree] = @index.write_tree(@repository)
20
+
21
+ author = @author.clone
22
+ author[:time] = Time.now
23
+
24
+ options[:author] = author
25
+ options[:committer] = author
26
+ options[:message] ||= message
27
+ options[:parents] = @repository.empty? ? [] : [ @repository.head.target ].compact
28
+ options[:update_ref] = 'HEAD'
29
+
30
+ Rugged::Commit.create(@repository, options)
31
+ end
32
+
33
+ def tag(name, target)
34
+ author = @author.clone
35
+ author[:time] = Time.now
36
+
37
+ # annotation = {
38
+ # tagger: author,
39
+ # message: 'a message?'
40
+ # }
41
+ # @repository.tags.create(name, target, annotation)
42
+ @repository.tags.create(name, target)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,22 @@
1
+ require 'sem_version'
2
+
3
+ module Incr
4
+ module Service
5
+ class Version
6
+ def self.increment_segment(version, segment)
7
+ incremented_version = version.clone
8
+
9
+ case segment
10
+ when 'major'
11
+ incremented_version.major = version.major + 1
12
+ when 'minor'
13
+ incremented_version.minor = version.minor + 1
14
+ when 'patch'
15
+ incremented_version.patch = version.patch + 1
16
+ end
17
+
18
+ incremented_version
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Incr
2
+ VERSION = '0.1.2'
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: incr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Philippe Couture
@@ -60,7 +60,21 @@ executables:
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
+ - ".gitignore"
64
+ - CODE_OF_CONDUCT.md
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE.txt
68
+ - README.md
63
69
  - bin/incr
70
+ - incr.gemspec
71
+ - lib/incr.rb
72
+ - lib/incr/command/mix.rb
73
+ - lib/incr/command/npm.rb
74
+ - lib/incr/service/file_helper.rb
75
+ - lib/incr/service/git.rb
76
+ - lib/incr/service/version.rb
77
+ - lib/incr/version.rb
64
78
  homepage: https://github.com/jcouture/incr
65
79
  licenses:
66
80
  - MIT