mirror of
https://github.com/discourse/discourse.git
synced 2026-08-13 06:25:11 -05:00
DEV: Support for running theme test with Ember CLI (second attempt)
This PR includes support for running theme tests in legacy ember production envrionments.
This commit is contained in:
+18
-7
@@ -39,8 +39,7 @@ task 'assets:precompile:before' do
|
||||
# Remove the assets that Ember CLI will handle for us
|
||||
Rails.configuration.assets.precompile.reject! do |asset|
|
||||
asset.is_a?(String) &&
|
||||
(%w(application.js admin.js ember_jquery.js pretty-text-bundle.js start-discourse.js vendor.js).include?(asset) ||
|
||||
asset.start_with?("discourse/tests"))
|
||||
(%w(application.js admin.js ember_jquery.js pretty-text-bundle.js start-discourse.js vendor.js).include?(asset))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -250,9 +249,14 @@ def copy_ember_cli_assets
|
||||
# Copy assets and generate manifest data
|
||||
log_task_duration('Copy assets and generate manifest data') {
|
||||
Dir["#{ember_cli_assets}**/*"].each do |f|
|
||||
if f !~ /test/ && File.file?(f)
|
||||
if File.file?(f)
|
||||
rel_file = f.sub(ember_cli_assets, "")
|
||||
digest = f.scan(/\-([a-f0-9]+)\./)[0][0]
|
||||
file_digest = Digest::SHA384.digest(File.read(f))
|
||||
digest = if f =~ /\-([a-f0-9]+)\./
|
||||
Regexp.last_match[1]
|
||||
else
|
||||
Digest.hexencode(file_digest)[0...32]
|
||||
end
|
||||
|
||||
dest = "public/assets"
|
||||
dest_sub = dest
|
||||
@@ -263,10 +267,17 @@ def copy_ember_cli_assets
|
||||
FileUtils.mkdir_p(dest_sub) unless Dir.exist?(dest_sub)
|
||||
log_file = File.basename(rel_file).sub("-#{digest}", "")
|
||||
|
||||
# It's simpler to serve the file as `application.js`
|
||||
if log_file == "discourse.js"
|
||||
# We need a few hacks here to move what Ember uses to what Rails wants
|
||||
case log_file
|
||||
when "discourse.js"
|
||||
log_file = "application.js"
|
||||
rel_file.sub!(/^discourse/, "application")
|
||||
when "test-support.js"
|
||||
log_file = "discourse/tests/test-support-rails.js"
|
||||
rel_file = "discourse/tests/test-support-rails-#{digest}.js"
|
||||
when "test-helpers.js"
|
||||
log_file = "discourse/tests/test-helpers-rails.js"
|
||||
rel_file = "discourse/tests/test-helpers-rails-#{digest}.js"
|
||||
end
|
||||
|
||||
res = FileUtils.cp(f, "#{dest}/#{rel_file}")
|
||||
@@ -277,7 +288,7 @@ def copy_ember_cli_assets
|
||||
"mtime" => File.mtime(f).iso8601(9),
|
||||
"size" => File.size(f),
|
||||
"digest" => digest,
|
||||
"integrity" => "sha384-#{Base64.encode64(Digest::SHA384.digest(File.read(f))).chomp}"
|
||||
"integrity" => "sha384-#{Base64.encode64(file_digest).chomp}"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user