-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure
executable file
·135 lines (113 loc) · 3.38 KB
/
configure
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env ruby
module Pod
class TemplateConfigurator
attr_reader :plugin_file
attr_reader :dangerfile_name
def initialize(dangerfile_name)
unless dangerfile_name
puts 'Please specify a plugin name on the command line.'
exit
end
@plugin_file = dangerfile_name.split('-').last
@dangerfile_name = dangerfile_name
end
def run
puts "Configuring #{dangerfile_name}"
print_info
clean_template_files
replace_variables_in_files
rename_template_files
reinitialize_git_repo
bundle_install
run_tests
build_gem
puts "Done."
end
#----------------------------------------#
def print_info
puts "user name:#{user_name}"
puts "user email:#{user_email}"
puts "year:#{year}"
end
def clean_template_files
`rm -rf configure`
`rm -rf README.md`
`rm -rf LICENSE`
end
def replace_variables_in_files
file_names = [
'GEM_CHANGELOG.md',
'GEM_CONTRIBUTING.md',
'GEM_RELEASING.md',
'GEM_LICENSE.txt',
'GEM_README.md',
'Gemfile',
'GEM.gemspec.template',
'lib/GEM.rb',
'lib/GEM/gem_version.rb',
'spec/GEM_spec.rb'
]
file_names.each do |file_name|
text = File.read(file_name)
# dangerfile-no_eggs_please -> DangerNoEggsPlease
text.gsub!('${GEM_CLASS}', dangerfile_name.split(/\-|_/).map(&:capitalize).join)
# dangerfile-no_eggs_please -> NoEggsPlease
text.gsub!('${GEM_MODULE}', "Dangerfile#{dangerfile_name.gsub('dangerfile-', '').split('_').map(&:capitalize).join}")
# dangerfile-no_eggs_please -> no_eggs_please
text.gsub!('${GEM_FILE}', plugin_file)
text.gsub!('${GEM_NAME}', dangerfile_name)
text.gsub!('${USER_NAME}', user_name)
text.gsub!('${USER_EMAIL}', user_email)
text.gsub!('${YEAR}', year)
File.open(file_name, 'w') { |file| file.puts text }
end
end
def rename_template_files
`mv GEM_Dangerfile Dangerfile`
`mv GEM_CHANGELOG.md CHANGELOG.md`
`mv GEM_CONTRIBUTING.md CONTRIBUTING.md`
`mv GEM_RELEASING.md RELEASING.md`
`mv GEM_LICENSE.txt LICENSE.txt`
`mv GEM_README.md README.md`
`mv GEM.gemspec.template #{dangerfile_name}.gemspec`
`mv lib/GEM.rb lib/danger_#{plugin_file}.rb`
`mv lib/GEM lib/#{plugin_file}`
`mv spec/GEM_spec.rb spec/#{plugin_file}_spec.rb`
end
def reinitialize_git_repo
`rm -rf .git`
`git init`
`git add -A`
`git commit -m "Initial commit."`
end
def bundle_install
puts 'Running bundle install'
`bundle install`
end
def run_tests
puts 'Running rake'
`rake`
end
def build_gem
puts 'Running rake build'
`rake build`
end
#----------------------------------------#
def user_name
(ENV['GIT_COMMITTER_NAME'] || `git config user.name`).strip
end
def user_email
(ENV['GIT_COMMITTER_EMAIL'] || `git config user.email`).strip
end
def year
Time.now.year.to_s
end
#----------------------------------------#
end
end
#-----------------------------------------------------------------------------#
# TODO: Handle description
# TODO: Handle usage
# TODO: Handle GitHub URL
dangerfile_name = ARGV.shift
Pod::TemplateConfigurator.new(dangerfile_name).run