2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-10-22 21:55:09 -04:00
|
|
|
task "assets:precompile:prereqs" do
|
2013-12-18 20:33:17 -05:00
|
|
|
unless %w[profile production].include? Rails.env
|
|
|
|
raise "rake assets:precompile should only be run in RAILS_ENV=production, you are risking unminified assets"
|
2013-11-03 17:58:34 -05:00
|
|
|
end
|
2023-10-22 21:55:09 -04:00
|
|
|
end
|
2013-12-18 20:33:17 -05:00
|
|
|
|
2023-10-22 21:55:09 -04:00
|
|
|
task "assets:precompile:build" do
|
|
|
|
if ENV["SKIP_EMBER_CLI_COMPILE"] != "1"
|
2024-01-10 07:12:36 -05:00
|
|
|
ember_version = ENV["EMBER_VERSION"] || "5"
|
DEV: Introduce feature-flag for Ember 5 upgrade
This commit introduces the scaffolding for us to easily switch between Ember 3.28 and Ember 5 on the `main` branch of Discourse. Unfortunately, there is no built-in system to apply this kind of flagging within yarn / ember-cli. There are projects like `ember-try` which are designed for running against multiple version of a dependency, but they do not allow us to 'lock' dependency/sub-dependency versions, and are therefore unsuitable for our use in production.
Instead, we will be maintaining two root `package.json` files, and two `yarn.lock` files. For ember-3, they remain as-is. For ember5, we use a yarn 'resolution' to override the version for ember-source across the entire yarn workspace.
To allow for easy switching with minimal diff against the repository, `package.json` and `yarn.lock` are symlinks which point to `package-ember3.json` and `yarn-ember3.lock` by default. To switch to Ember 5, we can run `script/switch ember version 5` to update the symlinks to point to `package-ember5.json` and `package-ember3.json` respectively. In production, and when using `bin/ember-cli` for development, the ember version can also be upgraded using the `EMBER_VERSION=5` environment variable.
When making changes to dependencies, these should be made against the default `ember3` versions, and then `script/regen_ember_5_lockfile` should be used to regenerate `yarn-ember5.lock` accordingly. A new 'Ember Version Lockfiles' GitHub workflow will automate this process on Dependabot PRs.
When running a local environment against Ember 5, the two symlink changes will show up as git diffs. To avoid us accidentally committing/pushing that change, another GitHub workflow is introduced which checks the default Ember version and raises an error if it is greater than v3.
Supporting two ember versions simultaneously obviously carries significant overhead, so our aim will be to get themes/plugins updated as quickly as possible, and then drop this flag.
2023-11-27 10:52:17 -05:00
|
|
|
|
2024-02-26 05:53:32 -05:00
|
|
|
raise "Unknown ember version '#{ember_version}'" if !%w[5].include?(ember_version)
|
DEV: Introduce feature-flag for Ember 5 upgrade
This commit introduces the scaffolding for us to easily switch between Ember 3.28 and Ember 5 on the `main` branch of Discourse. Unfortunately, there is no built-in system to apply this kind of flagging within yarn / ember-cli. There are projects like `ember-try` which are designed for running against multiple version of a dependency, but they do not allow us to 'lock' dependency/sub-dependency versions, and are therefore unsuitable for our use in production.
Instead, we will be maintaining two root `package.json` files, and two `yarn.lock` files. For ember-3, they remain as-is. For ember5, we use a yarn 'resolution' to override the version for ember-source across the entire yarn workspace.
To allow for easy switching with minimal diff against the repository, `package.json` and `yarn.lock` are symlinks which point to `package-ember3.json` and `yarn-ember3.lock` by default. To switch to Ember 5, we can run `script/switch ember version 5` to update the symlinks to point to `package-ember5.json` and `package-ember3.json` respectively. In production, and when using `bin/ember-cli` for development, the ember version can also be upgraded using the `EMBER_VERSION=5` environment variable.
When making changes to dependencies, these should be made against the default `ember3` versions, and then `script/regen_ember_5_lockfile` should be used to regenerate `yarn-ember5.lock` accordingly. A new 'Ember Version Lockfiles' GitHub workflow will automate this process on Dependabot PRs.
When running a local environment against Ember 5, the two symlink changes will show up as git diffs. To avoid us accidentally committing/pushing that change, another GitHub workflow is introduced which checks the default Ember version and raises an error if it is greater than v3.
Supporting two ember versions simultaneously obviously carries significant overhead, so our aim will be to get themes/plugins updated as quickly as possible, and then drop this flag.
2023-11-27 10:52:17 -05:00
|
|
|
|
2023-12-04 10:49:50 -05:00
|
|
|
compile_command = "CI=1 yarn --cwd app/assets/javascripts/discourse run ember build"
|
2022-11-15 17:02:13 -05:00
|
|
|
|
2023-09-11 04:32:37 -04:00
|
|
|
heap_size_limit = check_node_heap_size_limit
|
|
|
|
|
|
|
|
if heap_size_limit < 2048
|
2023-12-12 12:05:20 -05:00
|
|
|
STDERR.puts "Node.js heap_size_limit (#{heap_size_limit}) is less than 2048MB. Setting --max-old-space-size=2048."
|
|
|
|
compile_command = "NODE_OPTIONS='--max-old-space-size=2048' #{compile_command}"
|
2023-09-11 04:32:37 -04:00
|
|
|
end
|
|
|
|
|
2024-03-25 12:56:28 -04:00
|
|
|
ember_env = ENV["EMBER_ENV"] || "production"
|
|
|
|
compile_command = "#{compile_command} -prod" if ember_env == "production"
|
2023-09-11 04:12:37 -04:00
|
|
|
|
2023-10-22 21:55:09 -04:00
|
|
|
only_ember_precompile_build_remaining = (ARGV.last == "assets:precompile:build")
|
2022-03-16 08:02:21 -04:00
|
|
|
only_assets_precompile_remaining = (ARGV.last == "assets:precompile")
|
|
|
|
|
2023-10-22 21:55:09 -04:00
|
|
|
# Using exec to free up Rails app memory during ember build
|
|
|
|
if only_ember_precompile_build_remaining
|
2023-10-22 22:23:55 -04:00
|
|
|
exec "#{compile_command}"
|
2023-10-22 21:55:09 -04:00
|
|
|
elsif only_assets_precompile_remaining
|
2023-10-22 22:23:55 -04:00
|
|
|
exec "#{compile_command} && SKIP_EMBER_CLI_COMPILE=1 bin/rake assets:precompile"
|
2022-03-16 08:02:21 -04:00
|
|
|
else
|
2022-11-15 17:02:13 -05:00
|
|
|
system compile_command, exception: true
|
2023-10-26 12:29:53 -04:00
|
|
|
EmberCli.clear_cache!
|
2022-03-16 08:02:21 -04:00
|
|
|
end
|
2022-02-14 06:49:46 -05:00
|
|
|
end
|
2023-10-22 21:55:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
task "assets:precompile:before": %w[
|
|
|
|
environment
|
|
|
|
assets:precompile:prereqs
|
|
|
|
assets:precompile:build
|
|
|
|
] do
|
|
|
|
require "uglifier"
|
|
|
|
require "open3"
|
2022-02-14 06:49:46 -05:00
|
|
|
|
2014-02-06 19:36:44 -05:00
|
|
|
# Ensure we ALWAYS do a clean build
|
|
|
|
# We use many .erbs that get out of date quickly, especially with plugins
|
2019-05-08 13:31:13 -04:00
|
|
|
STDERR.puts "Purging temp files"
|
2014-02-06 19:36:44 -05:00
|
|
|
`rm -fr #{Rails.root}/tmp/cache`
|
|
|
|
|
2017-07-05 04:36:06 -04:00
|
|
|
# Ensure we clear emoji cache before pretty-text/emoji/data.js.es6.erb
|
|
|
|
# is recompiled
|
|
|
|
Emoji.clear_cache
|
|
|
|
|
2021-05-05 09:02:48 -04:00
|
|
|
$node_compress = `which terser`.present? && !ENV["SKIP_NODE_UGLIFY"]
|
2014-12-12 02:53:26 -05:00
|
|
|
|
2017-03-09 16:44:50 -05:00
|
|
|
unless ENV["USE_SPROCKETS_UGLIFY"]
|
|
|
|
$bypass_sprockets_uglify = true
|
2019-05-08 13:31:13 -04:00
|
|
|
Rails.configuration.assets.js_compressor = nil
|
|
|
|
Rails.configuration.assets.gzip = false
|
2017-03-09 16:44:50 -05:00
|
|
|
end
|
|
|
|
|
2019-05-08 13:31:13 -04:00
|
|
|
STDERR.puts "Bundling assets"
|
2014-12-12 02:53:26 -05:00
|
|
|
|
2013-12-18 20:33:17 -05:00
|
|
|
# in the past we applied a patch that removed asset postfixes, but it is terrible practice
|
|
|
|
# leaving very complicated build issues
|
|
|
|
# https://github.com/rails/sprockets-rails/issues/49
|
2014-02-06 00:55:53 -05:00
|
|
|
|
|
|
|
require "sprockets"
|
|
|
|
require "digest/sha1"
|
2013-11-03 17:58:34 -05:00
|
|
|
end
|
2013-12-18 20:33:17 -05:00
|
|
|
|
2014-05-02 17:46:03 -04:00
|
|
|
task "assets:precompile:css" => "environment" do
|
2023-08-24 10:36:22 -04:00
|
|
|
class Sprockets::Manifest
|
|
|
|
def reload
|
|
|
|
@filename = find_directory_manifest(@directory)
|
|
|
|
@data = json_decode(File.read(@filename))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# cause on boot we loaded a blank manifest,
|
|
|
|
# we need to know where all the assets are to precompile CSS
|
|
|
|
# cause CSS uses asset_path
|
|
|
|
Rails.application.assets_manifest.reload
|
|
|
|
|
2015-10-12 19:48:21 -04:00
|
|
|
if ENV["DONT_PRECOMPILE_CSS"] == "1"
|
|
|
|
STDERR.puts "Skipping CSS precompilation, ensure CSS lives in a shared directory across hosts"
|
|
|
|
else
|
|
|
|
STDERR.puts "Start compiling CSS: #{Time.zone.now}"
|
|
|
|
|
|
|
|
RailsMultisite::ConnectionManagement.each_connection do |db|
|
2021-07-06 13:11:10 -04:00
|
|
|
# CSS will get precompiled during first request if tables do not exist.
|
2017-04-14 10:33:35 -04:00
|
|
|
if ActiveRecord::Base.connection.table_exists?(Theme.table_name)
|
2021-07-06 13:11:10 -04:00
|
|
|
STDERR.puts "-------------"
|
|
|
|
STDERR.puts "Compiling CSS for #{db} #{Time.zone.now}"
|
2017-05-05 13:50:48 -04:00
|
|
|
begin
|
2022-11-07 11:13:35 -05:00
|
|
|
Stylesheet::Manager.recalculate_fs_asset_cachebuster!
|
2021-07-06 13:11:10 -04:00
|
|
|
Stylesheet::Manager.precompile_css if db == "default"
|
|
|
|
Stylesheet::Manager.precompile_theme_css
|
2020-06-02 01:18:03 -04:00
|
|
|
rescue PG::UndefinedColumn, ActiveModel::MissingAttributeError, NoMethodError => e
|
2019-02-07 09:27:42 -05:00
|
|
|
STDERR.puts "#{e.class} #{e.message}: #{e.backtrace.join("\n")}"
|
2017-05-05 13:50:48 -04:00
|
|
|
STDERR.puts "Skipping precompilation of CSS cause schema is old, you are precompiling prior to running migrations."
|
|
|
|
end
|
2014-06-12 14:41:37 -04:00
|
|
|
end
|
2014-05-02 17:46:03 -04:00
|
|
|
end
|
2015-10-12 02:31:37 -04:00
|
|
|
|
2015-10-12 19:48:21 -04:00
|
|
|
STDERR.puts "Done compiling CSS: #{Time.zone.now}"
|
|
|
|
end
|
2014-05-02 17:46:03 -04:00
|
|
|
end
|
2020-06-10 16:07:37 -04:00
|
|
|
|
|
|
|
task "assets:flush_sw" => "environment" do
|
|
|
|
begin
|
2021-05-25 18:39:31 -04:00
|
|
|
hostname = Discourse.current_hostname
|
|
|
|
default_port = SiteSetting.force_https? ? 443 : 80
|
|
|
|
port = SiteSetting.port.to_i > 0 ? SiteSetting.port : default_port
|
|
|
|
STDERR.puts "Flushing service worker script"
|
|
|
|
`curl -s -m 1 --resolve '#{hostname}:#{port}:127.0.0.1' #{Discourse.base_url}/service-worker.js > /dev/null`
|
|
|
|
STDERR.puts "done"
|
2020-06-10 16:07:37 -04:00
|
|
|
rescue StandardError
|
|
|
|
STDERR.puts "Warning: unable to flush service worker script"
|
|
|
|
end
|
|
|
|
end
|
2014-05-02 17:46:03 -04:00
|
|
|
|
2022-11-15 17:02:13 -05:00
|
|
|
def check_node_heap_size_limit
|
|
|
|
output, status =
|
|
|
|
Open3.capture2("node", "-e", "console.log(v8.getHeapStatistics().heap_size_limit/1024/1024)")
|
|
|
|
raise "Failed to fetch node memory limit" if status != 0
|
|
|
|
output.to_f
|
|
|
|
end
|
|
|
|
|
2014-12-12 02:53:26 -05:00
|
|
|
def assets_path
|
|
|
|
"#{Rails.root}/public/assets"
|
|
|
|
end
|
|
|
|
|
2020-11-22 20:59:45 -05:00
|
|
|
def global_path_klass
|
|
|
|
@global_path_klass ||= Class.new { extend GlobalPath }
|
|
|
|
end
|
|
|
|
|
|
|
|
def cdn_path(p)
|
2020-11-22 21:03:49 -05:00
|
|
|
global_path_klass.cdn_path(p)
|
2020-11-22 20:59:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def cdn_relative_path(p)
|
|
|
|
global_path_klass.cdn_relative_path(p)
|
|
|
|
end
|
|
|
|
|
2014-12-12 02:53:26 -05:00
|
|
|
def compress_node(from, to)
|
|
|
|
to_path = "#{assets_path}/#{to}"
|
2016-02-04 21:05:47 -05:00
|
|
|
assets = cdn_relative_path("/assets")
|
2020-01-23 12:44:00 -05:00
|
|
|
assets_additional_path = (d = File.dirname(from)) == "." ? "" : "/#{d}"
|
|
|
|
source_map_root = assets + assets_additional_path
|
2022-02-10 10:37:44 -05:00
|
|
|
source_map_url = "#{File.basename(to)}.map"
|
2020-01-23 12:44:00 -05:00
|
|
|
base_source_map = assets_path + assets_additional_path
|
2014-12-12 02:53:26 -05:00
|
|
|
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
cmd = <<~SH
|
2022-02-11 15:38:53 -05:00
|
|
|
terser '#{assets_path}/#{from}' -m -c -o '#{to_path}' --source-map "base='#{base_source_map}',root='#{source_map_root}',url='#{source_map_url}',includeSources=true"
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
SH
|
2014-12-17 12:14:12 -05:00
|
|
|
|
|
|
|
STDERR.puts cmd
|
2015-09-21 21:28:15 -04:00
|
|
|
result = `#{cmd} 2>&1`
|
|
|
|
unless $?.success?
|
|
|
|
STDERR.puts result
|
|
|
|
exit 1
|
|
|
|
end
|
2014-12-17 12:14:12 -05:00
|
|
|
|
2015-09-21 21:28:15 -04:00
|
|
|
result
|
2014-12-12 02:53:26 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def compress_ruby(from, to)
|
|
|
|
data = File.read("#{assets_path}/#{from}")
|
|
|
|
|
|
|
|
uglified, map =
|
|
|
|
Uglifier.new(
|
|
|
|
comments: :none,
|
2017-03-09 16:44:50 -05:00
|
|
|
source_map: {
|
|
|
|
filename: File.basename(from),
|
|
|
|
output_filename: File.basename(to),
|
|
|
|
},
|
2014-12-12 02:53:26 -05:00
|
|
|
).compile_with_map(data)
|
|
|
|
dest = "#{assets_path}/#{to}"
|
|
|
|
|
2015-07-21 14:52:54 -04:00
|
|
|
File.write(dest, uglified << "\n//# sourceMappingURL=#{cdn_path "/assets/#{to}.map"}")
|
2014-12-12 02:53:26 -05:00
|
|
|
File.write(dest + ".map", map)
|
2017-03-10 11:35:54 -05:00
|
|
|
|
|
|
|
GC.start
|
2014-12-12 02:53:26 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def gzip(path)
|
2017-11-24 09:52:08 -05:00
|
|
|
STDERR.puts "gzip -f -c -9 #{path} > #{path}.gz"
|
2018-07-03 19:42:21 -04:00
|
|
|
STDERR.puts `gzip -f -c -9 #{path} > #{path}.gz`.strip
|
2017-11-24 09:52:08 -05:00
|
|
|
raise "gzip compression failed: exit code #{$?.exitstatus}" if $?.exitstatus != 0
|
2016-06-07 02:55:57 -04:00
|
|
|
end
|
|
|
|
|
2019-04-10 22:36:02 -04:00
|
|
|
# different brotli versions use different parameters
|
2019-05-08 13:31:13 -04:00
|
|
|
def brotli_command(path, max_compress)
|
2024-03-21 07:07:35 -04:00
|
|
|
compression_quality =
|
|
|
|
max_compress ? "11" : (ENV["DISCOURSE_ASSETS_PRECOMPILE_DEFAULT_BROTLI_QUALITY"] || "6")
|
2019-05-08 13:31:13 -04:00
|
|
|
"brotli -f --quality=#{compression_quality} #{path} --output=#{path}.br"
|
2017-11-24 10:40:49 -05:00
|
|
|
end
|
|
|
|
|
2019-05-08 13:31:13 -04:00
|
|
|
def brotli(path, max_compress)
|
|
|
|
STDERR.puts brotli_command(path, max_compress)
|
|
|
|
STDERR.puts `#{brotli_command(path, max_compress)}`
|
2019-04-10 22:36:02 -04:00
|
|
|
raise "brotli compression failed: exit code #{$?.exitstatus}" if $?.exitstatus != 0
|
|
|
|
STDERR.puts `chmod +r #{path}.br`.strip
|
|
|
|
raise "chmod failed: exit code #{$?.exitstatus}" if $?.exitstatus != 0
|
2014-12-12 02:53:26 -05:00
|
|
|
end
|
|
|
|
|
2019-05-08 13:31:13 -04:00
|
|
|
def max_compress?(path, locales)
|
2019-05-08 13:26:28 -04:00
|
|
|
return false if Rails.configuration.assets.skip_minification.include? path
|
2022-05-11 05:23:32 -04:00
|
|
|
return false if EmberCli.is_ember_cli_asset?(path)
|
2019-05-08 13:26:28 -04:00
|
|
|
return true unless path.include? "locales/"
|
|
|
|
|
|
|
|
path_locale = path.delete_prefix("locales/").delete_suffix(".js")
|
|
|
|
return true if locales.include? path_locale
|
|
|
|
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2014-12-12 02:53:26 -05:00
|
|
|
def compress(from, to)
|
2023-10-22 21:55:09 -04:00
|
|
|
$node_compress ? compress_node(from, to) : compress_ruby(from, to)
|
2014-12-12 02:53:26 -05:00
|
|
|
end
|
|
|
|
|
2016-04-19 21:34:30 -04:00
|
|
|
def concurrent?
|
2016-06-07 03:03:05 -04:00
|
|
|
if ENV["SPROCKETS_CONCURRENT"] == "1"
|
2016-04-19 21:34:30 -04:00
|
|
|
concurrent_compressors = []
|
2021-06-02 21:37:06 -04:00
|
|
|
executor = Concurrent::FixedThreadPool.new(Concurrent.processor_count)
|
2018-10-03 04:43:18 -04:00
|
|
|
yield(
|
|
|
|
Proc.new do |&block|
|
|
|
|
concurrent_compressors << Concurrent::Future.execute(executor: executor) { block.call }
|
2023-01-09 07:10:19 -05:00
|
|
|
end
|
2018-10-03 04:43:18 -04:00
|
|
|
)
|
2016-04-19 21:34:30 -04:00
|
|
|
concurrent_compressors.each(&:wait!)
|
|
|
|
else
|
|
|
|
yield(Proc.new { |&block| block.call })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-10 22:43:08 -04:00
|
|
|
def current_timestamp
|
|
|
|
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
|
|
end
|
|
|
|
|
|
|
|
def log_task_duration(task_description, &task)
|
|
|
|
task_start = current_timestamp
|
|
|
|
task.call
|
|
|
|
STDERR.puts "Done '#{task_description}' : #{(current_timestamp - task_start).round(2)} secs"
|
|
|
|
STDERR.puts
|
|
|
|
end
|
|
|
|
|
2023-08-24 10:36:22 -04:00
|
|
|
task "assets:precompile:compress_js": "environment" do
|
2017-03-09 16:44:50 -05:00
|
|
|
if $bypass_sprockets_uglify
|
2014-12-12 02:53:26 -05:00
|
|
|
puts "Compressing Javascript and Generating Source Maps"
|
|
|
|
manifest = Sprockets::Manifest.new(assets_path)
|
2021-05-05 09:02:48 -04:00
|
|
|
|
2019-05-08 13:26:28 -04:00
|
|
|
locales = Set.new(["en"])
|
|
|
|
|
|
|
|
RailsMultisite::ConnectionManagement.each_connection do |db|
|
|
|
|
locales.add(SiteSetting.default_locale)
|
|
|
|
end
|
2015-02-20 15:48:45 -05:00
|
|
|
|
2021-08-10 22:43:08 -04:00
|
|
|
log_task_duration("Done compressing all JS files") do
|
|
|
|
concurrent? do |proc|
|
|
|
|
manifest
|
|
|
|
.files
|
2023-01-20 13:52:49 -05:00
|
|
|
.select { |k, v| k =~ /\.js\z/ }
|
2023-06-09 06:14:11 -04:00
|
|
|
.reject { |k, v| k =~ %r{/workbox-.*'/} }
|
2021-08-10 22:43:08 -04:00
|
|
|
.each do |file, info|
|
|
|
|
path = "#{assets_path}/#{file}"
|
2023-10-22 21:55:09 -04:00
|
|
|
_file =
|
|
|
|
(
|
|
|
|
if (d = File.dirname(file)) == "."
|
|
|
|
"_#{file}"
|
|
|
|
else
|
|
|
|
"#{d}/_#{File.basename(file)}"
|
|
|
|
end
|
|
|
|
)
|
2021-08-10 22:43:08 -04:00
|
|
|
_path = "#{assets_path}/#{_file}"
|
|
|
|
max_compress = max_compress?(info["logical_path"], locales)
|
2022-01-05 12:45:08 -05:00
|
|
|
if File.exist?(_path)
|
2021-08-10 22:43:08 -04:00
|
|
|
STDERR.puts "Skipping: #{file} already compressed"
|
|
|
|
elsif file.include? "discourse/tests"
|
|
|
|
STDERR.puts "Skipping: #{file}"
|
|
|
|
else
|
|
|
|
proc.call do
|
|
|
|
log_task_duration(file) do
|
|
|
|
STDERR.puts "Compressing: #{file}"
|
|
|
|
|
|
|
|
if max_compress
|
|
|
|
FileUtils.mv(path, _path)
|
|
|
|
compress(_file, file)
|
|
|
|
end
|
|
|
|
|
|
|
|
info["size"] = File.size(path)
|
|
|
|
info["mtime"] = File.mtime(path).iso8601
|
|
|
|
gzip(path)
|
|
|
|
brotli(path, max_compress)
|
2023-01-09 07:10:19 -05:00
|
|
|
end
|
2016-04-19 21:34:30 -04:00
|
|
|
end
|
|
|
|
end
|
2021-08-10 22:43:08 -04:00
|
|
|
end
|
2016-04-19 21:34:30 -04:00
|
|
|
end
|
2023-01-09 07:10:19 -05:00
|
|
|
end
|
2019-05-08 13:26:28 -04:00
|
|
|
|
2014-12-12 02:53:26 -05:00
|
|
|
# protected
|
|
|
|
manifest.send :save
|
2017-03-20 13:05:39 -04:00
|
|
|
|
2017-03-20 15:59:06 -04:00
|
|
|
if GlobalSetting.fallback_assets_path.present?
|
2017-03-20 13:43:59 -04:00
|
|
|
begin
|
2017-03-20 15:59:06 -04:00
|
|
|
FileUtils.cp_r("#{Rails.root}/public/assets/.", GlobalSetting.fallback_assets_path)
|
2017-03-20 13:43:59 -04:00
|
|
|
rescue => e
|
2017-03-20 15:59:06 -04:00
|
|
|
STDERR.puts "Failed to backup assets to #{GlobalSetting.fallback_assets_path}"
|
2017-03-20 13:43:59 -04:00
|
|
|
STDERR.puts e
|
|
|
|
STDERR.puts e.backtrace
|
|
|
|
end
|
2017-03-20 13:05:39 -04:00
|
|
|
end
|
2017-04-14 10:30:19 -04:00
|
|
|
end
|
2023-08-24 08:25:44 -04:00
|
|
|
end
|
2017-03-20 13:05:39 -04:00
|
|
|
|
2023-10-02 06:36:06 -04:00
|
|
|
task "assets:precompile:theme_transpiler": "environment" do
|
2023-10-18 19:00:15 -04:00
|
|
|
DiscourseJsProcessor::Transpiler.build_theme_transpiler
|
2023-08-24 10:36:22 -04:00
|
|
|
end
|
2017-04-14 15:06:52 -04:00
|
|
|
|
2023-08-24 10:36:22 -04:00
|
|
|
# Run these tasks **before** Rails' "assets:precompile" task
|
|
|
|
task "assets:precompile": %w[
|
|
|
|
assets:precompile:before
|
|
|
|
maxminddb:refresh
|
2023-10-02 06:36:06 -04:00
|
|
|
assets:precompile:theme_transpiler
|
2023-08-24 10:36:22 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
# Run these tasks **after** Rails' "assets:precompile" task
|
|
|
|
Rake::Task["assets:precompile"].enhance do
|
|
|
|
Rake::Task["assets:precompile:compress_js"].invoke
|
2023-08-24 08:25:44 -04:00
|
|
|
Rake::Task["assets:precompile:css"].invoke
|
2014-05-02 17:46:03 -04:00
|
|
|
end
|