forked from avdgaag/nanoc-cachebuster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
78 lines (64 loc) · 1.82 KB
/
Copy pathRakefile
File metadata and controls
78 lines (64 loc) · 1.82 KB
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
75
76
77
78
require 'bundler/setup'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
require 'nanoc/cachebuster/version'
task :log do
changes = `git log --oneline $(git describe --abbrev=0 2>/dev/null)..HEAD`
abort 'Nothing to do' if changes.empty?
changes.gsub!(/^\w+/, '*')
path = File.expand_path('../HISTORY.md', __FILE__)
original_content = File.read(path)
addition = "# #{Nanoc::Cachebuster::VERSION}\n\n#{changes}"
puts addition
File.open(path, 'w') do |f|
f.write "#{addition}\n#{original_content}"
end
end
desc 'Print current version number'
task :version do
puts Nanoc::Cachebuster::VERSION
end
class Version
def initialize(version_string)
@major, @minor, @patch = version_string.split('.').map { |s| s.to_i }
end
def bump(part)
case part
when :major then @major, @minor, @patch = @major + 1, 0, 0
when :minor then @minor, @patch = @minor + 1, 0
when :patch then @patch += 1
end
self
end
def to_s
[@major, @minor, @patch].join('.')
end
def write
file = File.expand_path('../lib/nanoc/cachebuster/version.rb', __FILE__)
original_contents = File.read(file)
File.open(file, 'w') do |f|
f.write original_contents.gsub(/VERSION = ('|")\d+\.\d+\.\d+\1/, "VERSION = '#{to_s}'")
end
puts to_s
to_s
end
end
namespace :version do
namespace :bump do
desc 'Bump a major version'
task :major do
Version.new(Nanoc::Cachebuster::VERSION).bump(:major).write
end
desc 'Bump a minor version'
task :minor do
Version.new(Nanoc::Cachebuster::VERSION).bump(:minor).write
end
desc 'Bump a patch version'
task :patch do
Version.new(Nanoc::Cachebuster::VERSION).bump(:patch).write
end
end
end