Skip to content

Commit 9f5b9ac

Browse files
committed
Add examples:seed Rake task.
I got tired of trying to do a make-shift system like this, so I threw together a little Rake task to do it for me. This task will clone some git repos for gems that have YARD docs and then run sord and generate the rbi files for each. This also includes an examples:reset Rake task to delete the sord_examples directory.
1 parent ca95d77 commit 9f5b9ac

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
.rspec_status
1212
.vscode/
1313
Gemfile.lock
14+
15+
sord_examples/

Rakefile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,56 @@ require "rspec/core/rake_task"
44
RSpec::Core::RakeTask.new(:spec)
55

66
task :default => :spec
7+
8+
namespace :examples do
9+
desc "Clone git repositories and run Sord on them as examples"
10+
task :seed do
11+
require 'fileutils'
12+
require 'colorize'
13+
14+
if File.directory?('sord_examples')
15+
puts 'sord_examples directory already exists, please delete the directory before seeding!'.red
16+
exit
17+
end
18+
19+
FileUtils.mkdir 'sord_examples'
20+
FileUtils.cd 'sord_examples'
21+
repos = {
22+
discordrb: 'https://github.com/meew0/discordrb',
23+
rouge: 'https://github.com/rouge-ruby/rouge',
24+
yard: 'https://github.com/lsegal/yard',
25+
addressable: 'https://github.com/sporkmonger/addressable',
26+
zeitwerk: 'https://github.com/fxn/zeitwerk',
27+
'rspec-core': 'https://github.com/rspec/rspec-core',
28+
bundler: 'https://github.com/bundler/bundler',
29+
haml: 'https://github.com/haml/haml',
30+
gitlab: 'https://github.com/NARKOZ/gitlab'
31+
}
32+
33+
# Shallow clone each of the repositories and then bundle install and run sord.
34+
repos.each do |name, url|
35+
puts "Cloning #{name}..."
36+
`git clone #{url} --depth=1`
37+
FileUtils.cd name.to_s
38+
# Add sord to gemfile.
39+
`echo "gem 'sord', path: '../../'" >> Gemfile`
40+
# Run bundle install.
41+
`bundle install`
42+
# Generate sri
43+
puts "Generating rbi for #{name}..."
44+
`bundle exec sord ../#{name}.rbi`
45+
puts "#{name}.rbi generated!"
46+
FileUtils.cd '..'
47+
end
48+
49+
puts "Seeding complete!"
50+
end
51+
52+
desc 'Delete the sord_examples directory to allow the seeder to run again.'
53+
task :reset do
54+
require 'fileutils'
55+
56+
FileUtils.rm_rf 'sord_examples' if File.directory?('sord_examples')
57+
end
58+
end
59+

0 commit comments

Comments
 (0)