mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:23:25 +08:00
12980418ae
Anyone still using `EMBER_CLI_PROD_ASSETS=0` in development or production will be gracefully switched to Ember CLI. In development, a repeated message will be logged to STDERR. Similarly, passing `QUNIT_EMBER_CLI=0` to the qunit rake task will now do nothing. A warning will be printed, and ember-cli mode will be used. Note that we've chosen not to fail the task, so that existing plugin/theme CI jobs don't immediately start failing. We may switch to a hard fail in the coming days/weeks.
57 lines
1.6 KiB
Ruby
57 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module EmberCli
|
|
ASSETS = %w(
|
|
discourse.js
|
|
admin.js
|
|
ember_jquery.js
|
|
pretty-text-bundle.js
|
|
start-discourse.js
|
|
vendor.js
|
|
)
|
|
|
|
ALIASES ||= {
|
|
"application" => "discourse",
|
|
"discourse/tests/test-support-rails" => "test-support",
|
|
"discourse/tests/test-helpers-rails" => "test-helpers"
|
|
}
|
|
|
|
def self.enabled?
|
|
if !Rails.env.production? && ENV["EMBER_CLI_PROD_ASSETS"] == "0"
|
|
STDERR.puts "The 'legacy' ember environment is discontinued. Running with ember-cli assets. Remove the EMBER_CLI_PROD_ASSETS=0 flag."
|
|
end
|
|
true
|
|
end
|
|
|
|
def self.script_chunks
|
|
return @@chunk_infos if defined? @@chunk_infos
|
|
|
|
raw_chunk_infos = JSON.parse(File.read("#{Rails.configuration.root}/app/assets/javascripts/discourse/dist/chunks.json"))
|
|
|
|
chunk_infos = raw_chunk_infos["scripts"].map do |info|
|
|
logical_name = info["afterFile"][/\Aassets\/(.*)\.js\z/, 1]
|
|
chunks = info["scriptChunks"].map { |filename| filename[/\Aassets\/(.*)\.js\z/, 1] }
|
|
[logical_name, chunks]
|
|
end.to_h
|
|
|
|
@@chunk_infos = chunk_infos if Rails.env.production?
|
|
chunk_infos
|
|
rescue Errno::ENOENT
|
|
{}
|
|
end
|
|
|
|
# Some assets have changed name following the switch
|
|
# to ember-cli. When the switch is complete, we can
|
|
# drop this method and update all the references
|
|
# to use the new names
|
|
def self.transform_name(name)
|
|
return name if !enabled?
|
|
ALIASES[name] || name
|
|
end
|
|
|
|
def self.is_ember_cli_asset?(name)
|
|
return false if !enabled?
|
|
ASSETS.include?(name) || name.start_with?("chunk.")
|
|
end
|
|
end
|