-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·123 lines (101 loc) · 3.36 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
#!/usr/bin/env ruby
module Pod
class TemplateConfigurator
attr_reader :plugin_file
attr_reader :plugin_name
def initialize(plugin_name)
unless plugin_name
puts "Please specify a plugin name on the command line."
exit
end
@plugin_file = plugin_name.split("-").last
@plugin_name = plugin_name
end
def run
unless plugin_name =~ /danger-.+/
puts "Plugin name needs to be of the form 'danger-*'."
exit
end
if plugin_name.count("-") > 1
puts "Plugin name should have one '-', and then '_'s to separate words in your plugin name"
puts "See http://guides.rubygems.org/name-your-gem/ for more info"
exit
end
puts "Configuring #{plugin_name}"
print_info
clean_template_files
replace_variables_in_files
rename_template_files
reinitialize_git_repo
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 = [
'PLUGIN_LICENSE.txt',
'PLUGIN_README.md',
'Gemfile',
'static_analyzer_comments.gemspec',
'lib/static_analyzer_comments.rb',
'lib/static_analyzer_comments/gem_version.rb',
'lib/danger_plugin.rb',
'lib/static_analyzer_comments/plugin.rb',
'spec/static_analyzer_comments_spec.rb'
]
file_names.each do |file_name|
text = File.read(file_name)
# danger-no_eggs_please -> DangerNoEggsPlease
text.gsub!("${PLUGIN_CLASS}", plugin_name.split(%r{\-|_}).map(&:capitalize).join)
# danger-no_eggs_please -> NoEggsPlease
text.gsub!("${PLUGIN_MODULE}", plugin_name.gsub("danger-","").split('_').map(&:capitalize).join)
# danger-no_eggs_please -> no_eggs_please
text.gsub!("${PLUGIN_FILE}", plugin_file)
text.gsub!("${PLUGIN_NAME}", plugin_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 PLUGIN_LICENSE.txt LICENSE.txt`
`mv PLUGIN_README.md README.md`
`mv static_analyzer_comments.gemspec #{plugin_name}.gemspec`
`mv lib/static_analyzer_comments.rb lib/danger_#{plugin_file}.rb`
`mv lib/static_analyzer_comments lib/#{plugin_file}`
`mv spec/static_analyzer_comments_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 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
plugin_name = ARGV.shift
Pod::TemplateConfigurator.new(plugin_name).run