-
Notifications
You must be signed in to change notification settings - Fork 65
/
Rakefile
122 lines (99 loc) · 3.57 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
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
# frozen_string_literal: true
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
require 'rdoc/task'
RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Spotlight'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end
Bundler::GemHelper.install_tasks
require 'solr_wrapper'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
require 'rubocop/rake_task'
RuboCop::RakeTask.new(:rubocop)
require 'engine_cart/rake_task'
require 'spotlight/version'
# Build with our opinionated defaults if none are provided.
rails_options = ENV.fetch('ENGINE_CART_RAILS_OPTIONS', '')
rails_options = "#{rails_options} -a propshaft" unless rails_options.match?(/-a\s|--asset-pipeline/)
rails_options = "#{rails_options} -j importmap" unless rails_options.match?(/-j\s|--javascript/)
ENV['ENGINE_CART_RAILS_OPTIONS'] = rails_options
task ci: ['engine_cart:generate'] do
ENV['environment'] = 'test'
SolrWrapper.wrap(port: '8983') do |solr|
solr.with_collection(name: 'blacklight-core', dir: 'lib/generators/spotlight/templates/solr/conf') do
Rake::Task['spotlight:fixtures'].invoke
within_test_app do
system 'bin/rake spec:prepare'
end
# run the tests
Rake::Task['spec'].invoke
end
end
end
namespace :spotlight do
desc 'Load fixtures'
task fixtures: ['engine_cart:generate'] do
within_test_app do
system 'rake spotlight_test:solr:seed RAILS_ENV=test'
abort 'Error running fixtures' unless $?.success?
end
end
desc 'Start the test application for Spotlight'
task :server do
Rake::Task['engine_cart:generate'].invoke
SolrWrapper.wrap(port: '8983') do |solr|
solr.with_collection(name: 'blacklight-core', dir: 'lib/generators/spotlight/templates/solr/conf') do
within_test_app do
unless File.exist? '.initialized'
system 'bin/rails spotlight:initialize spotlight_test:solr:seed'
File.open('.initialized', 'w') {}
end
system 'bin/dev'
end
end
end
end
namespace :template do
desc 'Start a brand new Spotlight application using the Rails template'
task :server do
require 'tmpdir'
require 'fileutils'
template_path = File.expand_path(File.join(File.dirname(__FILE__), 'template.rb'))
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
Bundler.with_unbundled_env do
version = "_#{Gem.loaded_specs['rails'].version}_" if Gem.loaded_specs['rails']
Bundler.with_unbundled_env do
IO.popen({ 'SPOTLIGHT_GEM' => File.dirname(__FILE__) },
['rails', version, 'new', 'internal', '--skip-spring', '-m', template_path] +
[err: %i[child out]]) do |io|
IO.copy_stream(io, $stderr)
_, exit_status = Process.wait2(io.pid)
raise 'Failed to generate spotlight' if exit_status.nonzero?
end
end
Bundler.with_unbundled_env do
Dir.chdir('internal') do
APP_ROOT = Dir.pwd
SolrWrapper.wrap(port: '8983') do |solr|
solr.with_collection(name: 'blacklight-core', dir: File.join(File.expand_path('..', File.dirname(__FILE__)), 'solr', 'conf')) do
system 'bin/rails s'
end
end
end
end
end
end
end
end
end
end
task default: %i[rubocop ci]