vump 1.2.0 → 2.0.0.pre.alpha.1

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
- SHA1:
3
- metadata.gz: 3d543e02895efb7d90e6290285d2dac81231fa64
4
- data.tar.gz: 8b74fc23c676f4fb68420500ec3c316889cd7381
2
+ SHA256:
3
+ metadata.gz: ec1748a44dde478e47b682e58b26b93acd5576b1943b190f6d51273503bdb41b
4
+ data.tar.gz: 15ca18dc809e13ccd90e93fa213b2428931a2005353bbf8c40b608993ac8183c
5
5
  SHA512:
6
- metadata.gz: 833188c62cabdb019ca07567876f6973f4041dd9bb40b90041ae4b82d729fbd9d09243f454e9976f244b670fa208aaa96710cffded9e1cfcf935a1f837b359ce
7
- data.tar.gz: 7937abf084f9a310de1714bf636c20b58a712bc1ddb8018f8b3f8eb1875f1a807a4e11e7437b72e617f9d7f148765d893e8f714e00bbe3582a1653036d95889a
6
+ metadata.gz: e8318b5ea233fed11cf79c570ef1748f5fc98a6393065246f6dbfd29dbe28cb87e83bd35de3b6bc21426e71b2472c96cc00e0fd4fa327b7f44bd1d01efd82236
7
+ data.tar.gz: 92bbad25ecf6116304382d3097b98191dc841914593b8a8ad85f950466735343ff081d73b063d6586e4e1a7b110963e036393af77f3e7e97c347e4b3974d0fec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Jaroslav Šmolík
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,47 @@
1
+ <p align="center">
2
+ <img src="https://i.imgur.com/ZH8ftR9.png" height="170">
3
+ </p>
4
+
5
+ # Vump
6
+
7
+ [![Build Status](https://img.shields.io/travis/grissius/vump/master.svg?style=flat-square)](https://travis-ci.org/grissius/vump)
8
+ [![Coverage Status](https://img.shields.io/coveralls/github/grissius/vump.svg?style=flat-square)](https://coveralls.io/github/grissius/vump?branch=master)
9
+ [![Gem](https://img.shields.io/gem/v/vump.svg?style=flat-square)](https://rubygems.org/gems/vump)
10
+ [![Maintainability](https://img.shields.io/codeclimate/maintainability/grissius/vump.svg?style=flat-square)](https://codeclimate.com/github/grissius/vump)
11
+ [![License](https://img.shields.io/github/license/grissius/vump.svg?style=flat-square)](https://github.com/grissius/vump/blob/master/LICENSE)
12
+
13
+ CLI semantic verison bumper for every project. With a kitty inside.
14
+
15
+ ## Demo
16
+ :construction: TODO
17
+
18
+ ## Getting started
19
+
20
+ ```
21
+ gem install vump
22
+ ```
23
+
24
+ :gem: Don't like ruby? There are likely to be prebundled packages for Linux, Windows and Mac in the future.
25
+
26
+ ## Usage
27
+
28
+ ```
29
+ vump <major|minor|patch> [...options]
30
+ ```
31
+
32
+ | Option | Example value | Explanation |
33
+ |----------------------|---------------|---------------------------------------------------------------------|
34
+ | `--silent` , `-s` | - | Restrict output |
35
+ | `--version`, `-v` | - | Output Vump's version |
36
+ | `--help` , `-h` | - | Print this help |
37
+ | `--no-git` , | - | Skip staging, commit and tag |
38
+ | `--tag-prefix`, `-t` | `@foo/v` | Modify version string prefix for git tag (default "v") |
39
+ | `--build` , `-b` | `001` | Set semver's build tag (default none) |
40
+ | `--pre` | `alpha.1` | Set semver's pre release tag (default none) |
41
+ | `--date` , | `2020-12-20` | Modify date of committing release. Used by changelog. (default now) |
42
+ | `--dry` , `-d` | - | Dry run (no writes or CSV manipulation) |
43
+ | `--path` , `-p` | `/foo/bar` | Path to the repo (default pwd) |
44
+
45
+ ## License
46
+
47
+ Licensed under [MIT](./LICENSE)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 2.0.0-alpha.1
data/bin/vump CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- require_relative '../lib/cli'
2
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
3
+ require 'vump/cli/cli'
4
4
 
5
5
  Vump::CLI.start(ARGV)
@@ -0,0 +1,100 @@
1
+ require 'vump/vump'
2
+ require 'vump/meta'
3
+ require 'time'
4
+
5
+ module Vump
6
+ module CLI
7
+ def self.parse_args(inputs) # rubocop:disable Metrics/MethodLength
8
+ options = {}
9
+ args = []
10
+ inputs.each do |input|
11
+ case input
12
+ when /--(?<key>.*?)=(?<value>.*)/
13
+ options[Regexp.last_match(1).to_sym] = Regexp.last_match(2)
14
+ when /--?(.*)/
15
+ options[Regexp.last_match(1).to_sym] = true
16
+ else
17
+ args << input
18
+ end
19
+ end
20
+ [args, options]
21
+ end
22
+
23
+ def self.parse_inputs(inputs)
24
+ args, options = parse_args(inputs)
25
+ [parse_arg(args), parse_options(options)]
26
+ end
27
+
28
+ def self.parse_arg(args)
29
+ case args.first
30
+ when /^ma.*/
31
+ :major
32
+ when /^mi.*/
33
+ :minor
34
+ else
35
+ :patch
36
+ end
37
+ end
38
+
39
+ # rubocop:disable Metrics/MethodLength
40
+ # rubocop:disable Metrics/AbcSize
41
+ # rubocop:disable Metrics/CyclomaticComplexity
42
+ # rubocop:disable Metrics/BlockLength
43
+ def self.parse_options(options)
44
+ defaults = {
45
+ date: Time.now,
46
+ dry: false,
47
+ no_git: false,
48
+ silent: false,
49
+ verbose: false,
50
+ version: false,
51
+ tag_prefix: 'v',
52
+ path: Dir.pwd,
53
+ }
54
+ options.keys.each_with_object(defaults) do |k, acc|
55
+ case k
56
+ when :s, :silent
57
+ acc[:silent] = options[k]
58
+ when :verbose
59
+ acc[:verbose] = options[k]
60
+ when :d, :dry
61
+ acc[:dry] = options[k]
62
+ when :'no-git', :no_git
63
+ acc[:no_git] = options[k]
64
+ when :v, :version
65
+ acc[:version] = options[k]
66
+ when :h, :help
67
+ acc[:help] = options[k]
68
+ when :t, :tag_prefix, :'tag-prefix'
69
+ acc[:tag_prefix] = options[k]
70
+ when :b, :build
71
+ acc[:build] = options[k]
72
+ when :pre
73
+ acc[:pre] = options[k]
74
+ when :date
75
+ acc[:date] = Time.parse(options[k]) rescue defaults[:date]
76
+ when :p, :path
77
+ acc[:path] = options[k]
78
+ else
79
+ acc[k] = options[k]
80
+ end
81
+ end
82
+ end
83
+ # rubocop:enable Metrics/MethodLength
84
+ # rubocop:enable Metrics/AbcSize
85
+ # rubocop:enable Metrics/CyclomaticComplexity
86
+ # rubocop:enable Metrics/BlockLength
87
+
88
+ def self.start(inputs)
89
+ arg, opts = parse_inputs(inputs)
90
+ return puts ::Vump::Meta.version if opts[:version]
91
+
92
+ vump = ::Vump::Vump.new(opts[:path], arg, opts)
93
+ if opts[:help]
94
+ vump.help
95
+ else
96
+ vump.bump(arg, opts[:pre], opts[:build])
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,116 @@
1
+ require 'command_line_reporter'
2
+ require 'logger'
3
+ require 'vump/meta'
4
+
5
+ FRAGMENTS1 = <<'_'.freeze
6
+
7
+ |\__/,| (`\
8
+ Vump _.|o o |_ ) )
9
+ _
10
+ # rubocop:disable Layout/IndentHeredoc
11
+ FRAGMENTS2 = <<'_'.freeze
12
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━(((━━━(((━━━━━━━━━━━━━━━━
13
+ _
14
+ # rubocop:enable Layout/IndentHeredoc
15
+ module Vump
16
+ class Reporter
17
+ include CommandLineReporter
18
+
19
+ def initialize(options)
20
+ @modules = {}
21
+ @level = ::Logger::INFO
22
+ @level = ::Logger::DEBUG if options[:verbose]
23
+ @level = ::Logger::UNKNOWN if options[:silent]
24
+ end
25
+
26
+ def add_loaded_modules(mods)
27
+ mods.map(&:name).each { |m| @modules[m] = { loaded: true } }
28
+ end
29
+
30
+ def add_relevant_modules(mods)
31
+ mods.map(&:name).each { |m| @modules[m][:relevant] = true }
32
+ end
33
+
34
+ def add_read_version(mod, version)
35
+ @modules[mod.name][:read_version] = version
36
+ end
37
+
38
+ # rubocop:disable Metrics/MethodLength
39
+ # rubocop:disable Metrics/AbcSize
40
+ # rubocop:disable Metrics/LineLength
41
+ def help
42
+ puts 'vump'.bold.yellow + ' <major|minor|patch> [...options]'.yellow
43
+ header title: 'Available options:'
44
+ table(border: false) do
45
+ [
46
+ ['-s, --silent', '', 'Restrict output'],
47
+ ['-v, --version', '', 'Output Vump\'s version'],
48
+ ['-h, --help', '', 'Print this help'],
49
+ ['--no-git', '', 'Skip staging, commit and tag'],
50
+ ['-t, --tag-prefix', '=@foo/v', 'Modify version string prefix for git tag (default "v")'],
51
+ ['-b, --build', '=001', 'Set semver\'s build tag (default none)'],
52
+ ['--pre', '=alpha1', 'Set semver\'s pre release tag (default none)'],
53
+ ['--date', '=2020-12-20', 'Modify date of committing release. Used by changelog. (default now)'],
54
+ ['-d, --dry', '', 'Dry run (no writes or CSV manipulation)'],
55
+ ['-p, --path', '=/foo/bar', 'Path to the repo (default pwd)'],
56
+ ].each do |option, arg, descr|
57
+ row do
58
+ column(option, width: 18, color: 'yellow')
59
+ column(arg, width: 12, color: 'cyan')
60
+ column(descr, width: 40)
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ def report_preamble(base_path, arg, options)
67
+ return if @level > ::Logger::INFO
68
+
69
+ puts FRAGMENTS1.chomp.bold.yellow + ' ' + Meta.version.yellow
70
+ puts FRAGMENTS2.chomp.bold.yellow
71
+ puts "#{' ' * 27} Semantic version bumper\n".yellow
72
+
73
+ return if @level > ::Logger::DEBUG
74
+
75
+ table(border: false) do
76
+ row do
77
+ column('Base path', width: 10)
78
+ column(base_path, width: 70)
79
+ end
80
+ row do
81
+ column('Argument')
82
+ column(arg)
83
+ end
84
+ row do
85
+ column('Options')
86
+ column(options)
87
+ end
88
+ end
89
+ end
90
+
91
+ def report_module_overview
92
+ return if @level > ::Logger::INFO
93
+
94
+ header title: 'Version module overview', align: 'center', width: 80
95
+ table(border: true) do
96
+ row do
97
+ column('NAME', width: 20)
98
+ column('STATUS', width: 30)
99
+ column('READ VERSION', width: 20)
100
+ end
101
+ @modules.each do |name, data|
102
+ row do
103
+ rel = data[:relevant]
104
+ column(name)
105
+ column(rel ? 'relevant' : 'loaded', color: rel ? 'green' : nil)
106
+ column(data[:read_version], color: rel ? 'green' : nil)
107
+ end
108
+ end
109
+ end
110
+ end
111
+
112
+ # rubocop:enable Metrics/AbcSize
113
+ # rubocop:enable Metrics/MethodLength
114
+ # rubocop:enable Metrics/LineLength
115
+ end
116
+ end
@@ -0,0 +1,42 @@
1
+ require 'git'
2
+ require 'logger'
3
+
4
+ module Vump
5
+ class Git
6
+ def initialize(base, options = {})
7
+ @git = ::Git.open(base)
8
+ @logger = options[:logger]
9
+ @options = options
10
+ rescue ArgumentError
11
+ @git = nil
12
+ end
13
+
14
+ def loaded?
15
+ !@git.nil?
16
+ end
17
+
18
+ def stage(files)
19
+ @logger.debug("Staging files: #{files}") if @logger
20
+ @git.add(files) unless @options[:dry]
21
+ @logger.debug('Files staged') if @logger
22
+ end
23
+
24
+ def commit(version)
25
+ message = "Release version #{version}"
26
+ result = @options[:dry] ? 'Dry run success' : @git.commit(message)
27
+ if @logger
28
+ if result != ''
29
+ @logger.info("Created commit #{message}")
30
+ else
31
+ @logger.error('Could not commit files. Perhaps the hook failed.')
32
+ end
33
+ end
34
+ result == '' ? false : message
35
+ end
36
+
37
+ def tag(version_tag)
38
+ @git.add_tag(version_tag) unless @options[:dry]
39
+ @logger.info("Created tag #{version_tag}") if @logger
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,34 @@
1
+ require 'logger'
2
+ require 'forwardable'
3
+
4
+ module Vump
5
+ class Logger
6
+ extend Forwardable
7
+ def_delegators :@logger, :level=
8
+
9
+ def initialize(options = {})
10
+ @logger = ::Logger.new(options[:out] || STDOUT)
11
+ @logger.level = ::Logger::DEBUG if options[:verbose]
12
+ @logger.level = ::Logger::UNKNOWN if options[:silent]
13
+ @logger.formatter = proc do |_severity, _datetime, progname, msg|
14
+ progname ? "[#{progname}] #{msg}\n" : "#{msg}\n"
15
+ end
16
+ end
17
+
18
+ def info(message, module_name = nil)
19
+ @logger.add(::Logger::INFO, message, module_name)
20
+ end
21
+
22
+ def debug(message, module_name = nil)
23
+ @logger.add(::Logger::DEBUG, message, module_name)
24
+ end
25
+
26
+ def warn(message, module_name = nil)
27
+ @logger.add(::Logger::WARN, message, module_name)
28
+ end
29
+
30
+ def error(message, module_name = nil)
31
+ @logger.add(::Logger::ERROR, message, module_name)
32
+ end
33
+ end
34
+ end
@@ -1,4 +1,40 @@
1
+ require 'vump/modules/version_file'
2
+
1
3
  module Vump
2
- # Brief summary of the package
3
- SUMMARY = 'Raise version version in root of semver project.'.freeze
4
+ module Meta
5
+ def self.name
6
+ 'vump'.freeze
7
+ end
8
+
9
+ def self.version
10
+ VersionFile.new(File.expand_path('../..', __dir__)).read
11
+ end
12
+
13
+ def self.summary
14
+ 'Raise version version in root of semver project.'.freeze
15
+ end
16
+
17
+ def self.description
18
+ text = <<-DESCRIPTION
19
+ Semantic version bumper. CLI tool to easily manage projects using semver and automate menial version raising.
20
+ DESCRIPTION
21
+ text.strip
22
+ end
23
+
24
+ def self.homepage
25
+ 'https://github.com/grissius/vump'.freeze
26
+ end
27
+
28
+ def self.license
29
+ 'MIT'.freeze
30
+ end
31
+
32
+ def self.author
33
+ 'Jaroslav Šmolík'.freeze
34
+ end
35
+
36
+ def self.email
37
+ 'grissius@gmail.com'.freeze
38
+ end
39
+ end
4
40
  end
@@ -0,0 +1,39 @@
1
+ require 'vump/modules/base_module'
2
+
3
+ module Vump
4
+ class BaseFileModule < BaseModule
5
+ def filename
6
+ raise NotImplementedError, "Missing filename on #{name}"
7
+ end
8
+
9
+ def file_path
10
+ File.expand_path(filename, @base_path)
11
+ end
12
+
13
+ def relevant?
14
+ File.file?(file_path)
15
+ end
16
+
17
+ def to_stage
18
+ [file_path]
19
+ end
20
+
21
+ def read
22
+ @contents = File.read(file_path)
23
+ select(@contents)
24
+ end
25
+
26
+ def write(version)
27
+ contents = compose(@contents, version)
28
+ File.write(file_path, contents) unless @options[:dry]
29
+ end
30
+
31
+ def select(_contents)
32
+ raise NotImplementedError, "Missing select on #{name}"
33
+ end
34
+
35
+ def compose(_contents, _version)
36
+ raise NotImplementedError, "Missing compose on #{name}"
37
+ end
38
+ end
39
+ end