-
Notifications
You must be signed in to change notification settings - Fork 26
/
Rakefile
87 lines (77 loc) · 2.35 KB
/
Rakefile
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
79
80
81
82
83
84
85
86
87
require 'rubygems'
require 'rake'
require 'readline'
require 'pry' if ENV['TEST']
PROJECT_ROOT = File.expand_path(File.dirname(__FILE__))
desc "Write changes to the CHANGELOG"
task :changes do
text = ask("CHANGELOG Entry:")
text.insert(0, "*#{read_version.join('.')}* (#{Time.now.strftime("%B %d, %Y")})\n\n")
text << "\n"
prepend_changelog(text)
system("#{ENV['EDITOR']} CHANGELOG")
end
desc "Increment the patch version and write changes to the changelog"
task :bump_patch do
major, minor, patch = read_version
patch = patch.to_i + 1
write_version([major, minor, patch])
version = open('VERSION').read.chomp
readme = open('README.md').read
File.open('README.md', 'w') {|f| f.write(readme.gsub(/^\*\*Version: [0-9\.]+\*\*$/, "**Version: #{version}**")) }
Rake::Task["changes"].invoke
end
desc "Alias for :bump_patch"
task :bump => :bump_patch do; end
desc "Increment the minor version and write changes to the changelog"
task :bump_minor do
major, minor, patch = read_version
minor = minor.to_i + 1
patch = 0
write_version([major, minor, patch])
Rake::Task["changes"].invoke
end
desc "Increment the major version and write changes to the changelog"
task :bump_major do
major, minor, patch = read_version
major = major.to_i + 1
minor = 0
patch = 0
write_version([major, minor, patch])
Rake::Task["changes"].invoke
end
desc "Open the github site in your browser"
task :github do
system("open https://github.com/midwire/.env")
end
desc "Alias for :github task"
task :home => [:github] do; end
##################################################
private
def read_version
text = File.read("#{PROJECT_ROOT}/VERSION").to_s.chomp
major, minor, patch = text.split('.')
end
def write_version(version_array)
version = version_array.join('.')
File.open("#{PROJECT_ROOT}/VERSION", 'w') {|f| f.write(version.to_s) }
end
def prepend_changelog(text_array)
# read current changelog
old = File.read("#{PROJECT_ROOT}/CHANGELOG").to_s.chomp
text_array.push(old)
File.open("#{PROJECT_ROOT}/CHANGELOG", 'w') do |f|
text_array.flatten.each do |line|
f.puts(line)
end
end
end
def ask(message)
response = []
puts message
puts "Hit <Control>-D when finished:"
while line = Readline.readline('* ', false)
response << "* #{line.chomp}" unless line.nil?
end
response
end