mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 00:11:30 +08:00
DEV: refactor rake asset precompile tasks (#24045)
* DEV: refactor rake asset precompile tasks add a separate ember build task that does not depend on rails env allowing us to compile assets without db+redis connections rename EMBER_CLI_COMPILE_DONE to SKIP_EMBER_CLI_COMPILE better semantics in build steps
This commit is contained in:
@ -1,14 +1,13 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
task "assets:precompile:before": "environment" do
|
task "assets:precompile:prereqs" do
|
||||||
require "uglifier"
|
|
||||||
require "open3"
|
|
||||||
|
|
||||||
unless %w[profile production].include? Rails.env
|
unless %w[profile production].include? Rails.env
|
||||||
raise "rake assets:precompile should only be run in RAILS_ENV=production, you are risking unminified assets"
|
raise "rake assets:precompile should only be run in RAILS_ENV=production, you are risking unminified assets"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if ENV["EMBER_CLI_COMPILE_DONE"] != "1"
|
task "assets:precompile:build" do
|
||||||
|
if ENV["SKIP_EMBER_CLI_COMPILE"] != "1"
|
||||||
compile_command = "yarn --cwd app/assets/javascripts/discourse run ember build"
|
compile_command = "yarn --cwd app/assets/javascripts/discourse run ember build"
|
||||||
|
|
||||||
heap_size_limit = check_node_heap_size_limit
|
heap_size_limit = check_node_heap_size_limit
|
||||||
@ -25,15 +24,27 @@ task "assets:precompile:before": "environment" do
|
|||||||
|
|
||||||
compile_command = "EMBER_ENV=production #{compile_command}" if ENV["EMBER_ENV"].nil?
|
compile_command = "EMBER_ENV=production #{compile_command}" if ENV["EMBER_ENV"].nil?
|
||||||
|
|
||||||
|
only_ember_precompile_build_remaining = (ARGV.last == "assets:precompile:build")
|
||||||
only_assets_precompile_remaining = (ARGV.last == "assets:precompile")
|
only_assets_precompile_remaining = (ARGV.last == "assets:precompile")
|
||||||
|
|
||||||
if only_assets_precompile_remaining
|
|
||||||
# Using exec to free up Rails app memory during ember build
|
# Using exec to free up Rails app memory during ember build
|
||||||
exec "#{compile_command} && EMBER_CLI_COMPILE_DONE=1 bin/rake assets:precompile"
|
if only_ember_precompile_build_remaining
|
||||||
|
exec "#{compile_command}
|
||||||
|
elsif only_assets_precompile_remaining
|
||||||
|
exec " #{compile_command} && SKIP_EMBER_CLI_COMPILE=1 bin/rake assets:precompile"
|
||||||
else
|
else
|
||||||
system compile_command, exception: true
|
system compile_command, exception: true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
task "assets:precompile:before": %w[
|
||||||
|
environment
|
||||||
|
assets:precompile:prereqs
|
||||||
|
assets:precompile:build
|
||||||
|
] do
|
||||||
|
require "uglifier"
|
||||||
|
require "open3"
|
||||||
|
|
||||||
# Ensure we ALWAYS do a clean build
|
# Ensure we ALWAYS do a clean build
|
||||||
# We use many .erbs that get out of date quickly, especially with plugins
|
# We use many .erbs that get out of date quickly, especially with plugins
|
||||||
@ -214,11 +225,7 @@ def max_compress?(path, locales)
|
|||||||
end
|
end
|
||||||
|
|
||||||
def compress(from, to)
|
def compress(from, to)
|
||||||
if $node_compress
|
$node_compress ? compress_node(from, to) : compress_ruby(from, to)
|
||||||
compress_node(from, to)
|
|
||||||
else
|
|
||||||
compress_ruby(from, to)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def concurrent?
|
def concurrent?
|
||||||
@ -266,7 +273,14 @@ task "assets:precompile:compress_js": "environment" do
|
|||||||
.reject { |k, v| k =~ %r{/workbox-.*'/} }
|
.reject { |k, v| k =~ %r{/workbox-.*'/} }
|
||||||
.each do |file, info|
|
.each do |file, info|
|
||||||
path = "#{assets_path}/#{file}"
|
path = "#{assets_path}/#{file}"
|
||||||
_file = (d = File.dirname(file)) == "." ? "_#{file}" : "#{d}/_#{File.basename(file)}"
|
_file =
|
||||||
|
(
|
||||||
|
if (d = File.dirname(file)) == "."
|
||||||
|
"_#{file}"
|
||||||
|
else
|
||||||
|
"#{d}/_#{File.basename(file)}"
|
||||||
|
end
|
||||||
|
)
|
||||||
_path = "#{assets_path}/#{_file}"
|
_path = "#{assets_path}/#{_file}"
|
||||||
max_compress = max_compress?(info["logical_path"], locales)
|
max_compress = max_compress?(info["logical_path"], locales)
|
||||||
if File.exist?(_path)
|
if File.exist?(_path)
|
||||||
|
Reference in New Issue
Block a user