-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathRakefile
More file actions
185 lines (147 loc) · 4.53 KB
/
Rakefile
File metadata and controls
185 lines (147 loc) · 4.53 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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
gem "rdoc", "~> 6.4"
require 'rdoc/rdoc'
require 'rdoc/task'
require 'fileutils'
require_relative 'lib/options_list_markdownizer'
$:.unshift '.', '../rubygems/lib'
ENV['RUBYGEMS_DIR'] ||= File.expand_path '../../..', __FILE__
task :RUBYGEMS_DIR_exists do
message = <<-NO_RUBYGEMS_DIR
The Rubygems rdocs are required to build the spec guide.
Install or clone it from GitHub, then:
RUBYGEMS_DIR=/path/to/rubygems/source rake spec_guide --trace
The RUBYGEMS_DIR is assumed to exist at:
#{ENV['RUBYGEMS_DIR']}
NO_RUBYGEMS_DIR
abort message unless File.exist? ENV['RUBYGEMS_DIR']
end
# RUBYGEMS_DIR should be checked first
task rdoc_spec: %w[RUBYGEMS_DIR_exists]
RDoc::Task.new(:rdoc_spec) do |rd|
spec_file = File.join(ENV["RUBYGEMS_DIR"].to_s, "lib", "rubygems", "specification.rb")
rd.rdoc_files.include(spec_file)
rd.template = "jekdoc"
rd.options << '--quiet'
end
desc "move spec guide into the right place"
task :move_spec => %w[specification-reference.md]
file 'html/Gem/Specification.html' => %w[rdoc_spec]
file 'specification-reference.md' => %w[html/Gem/Specification.html] do
cp 'html/Gem/Specification.html', 'specification-reference.md'
end
desc "clean up after rdoc"
task :clean do
FileUtils.rm_rf "html"
end
desc "generate specification guide"
task :spec_guide => [:rdoc_spec, :move_spec, :clean]
desc "generate command guide"
task :command_guide => %w[command-reference.md]
command_reference_files = Rake::FileList.new(*%W[
Rakefile
command-reference.erb
#{ENV['RUBYGEMS_DIR']}/lib/rubygems.rb
#{ENV['RUBYGEMS_DIR']}/lib/rubygems/command_manager.rb
#{ENV['RUBYGEMS_DIR']}/lib/rubygems/commands/*.rb
])
file 'command-reference.md' =>
%w[RUBYGEMS_DIR_exists] + command_reference_files do
require 'rubygems/command_manager'
require 'rdoc/erbio'
names = Gem::CommandManager.instance.command_names
commands = {}
names.each do |name|
command = Gem::CommandManager.instance[name]
command.options[:help] = ''
commands[name] = command
end
def htmlify(string)
lines = string.split("\n")
html_string = ''
lines.each do |line|
if line
if line =~ /^ /
# This will end up in a <pre> block
html_string += line
else
html_string += line.gsub("<", "<").gsub(">", ">")
end
html_string += "\n"
end
end
html_string[0..-2]
end
def argument_list_item(string)
if string =~ /^(\S+)(.*)/
string = "*#{$1}* - #{$2}"
end
htmlify("* #{string}")
end
def options_list(command)
OptionsListMarkdownizer.new.call command
end
filename = "command-reference.erb"
erbio = ERB.new File.read(filename), trim_mode: '-'
content = erbio.result(binding).gsub(ENV["HOME"], "~")
File.write 'command-reference.md', content
end
desc "serve documentation on http://localhost:4000"
task :server do
pids = [
spawn('jekyll', 'serve', '4000'),
spawn('sass', '--watch', 'stylesheets:stylesheets'),
]
trap "INT" do
Process.kill "INT", *pids
exit 1
end
trap "TERM" do
Process.kill "TERM", *pids
exit 1
end
pids.each do |pid|
Process.waitpid pid
end
end
desc 'build documentation and display it on http://localhost:4000'
task default: %w[spec_guide command_guide server]
desc "Recreate data/known_plugins.yml from RubyGems.org data."
task :regenerate_known_plugins_yml do
require "json"
require "rubygems/package"
require "rubygems/remote_fetcher"
require "yaml"
known_plugins = %w[
bootboot
extended_bundler-errors
]
skipped_gems = %w[
bundler-explain
bundler-fast_git
bundler-interactive source-does-not-exist yanked-all-but-last
bundler-next
bundler-security
bundler-shellsplit-plugin
]
rubygems = Gem::Source.new("https://rubygems.org")
known_plugins = rubygems.load_specs(:latest).filter_map do |name_tuple|
next unless name_tuple.name.start_with?("bundler-") ||
known_plugins.include?(name_tuple.name)
next if skipped_gems.include?(name_tuple.name)
spec = rubygems.fetch_spec(name_tuple)
path = rubygems.download(spec, Gem.dir)
gem = Gem::Package.new(path)
# make sure it's actually a Bundler plugin
next unless gem.contents.include?("plugins.rb")
next unless spec.homepage
next unless spec.summary
{
name: spec.name,
summary: spec.summary,
uri: spec.homepage
}
end
File.write(File.expand_path("_data/known_plugins.yml", __dir__), YAML.dump(known_plugins))
puts "Saved #{known_plugins.size} plugins as data/known_plugins.yml"
puts "Done."
end