mirror of
https://github.com/discourse/discourse.git
synced 2025-07-07 01:32:28 +00:00
DEV: Log duration of ember-cli asset build (#13980)
This commit is contained in:
parent
683712fae7
commit
8e45fdfbb1
@ -190,6 +190,17 @@ def concurrent?
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
def geolite_dbs
|
def geolite_dbs
|
||||||
@geolite_dbs ||= %w{
|
@geolite_dbs ||= %w{
|
||||||
GeoLite2-City
|
GeoLite2-City
|
||||||
@ -229,17 +240,22 @@ def copy_ember_cli_assets
|
|||||||
assets = {}
|
assets = {}
|
||||||
files = {}
|
files = {}
|
||||||
|
|
||||||
|
log_task_duration('yarn install') {
|
||||||
unless system("yarn --cwd #{ember_dir} install")
|
unless system("yarn --cwd #{ember_dir} install")
|
||||||
STDERR.puts "Error running yarn install"
|
STDERR.puts "Error running yarn install"
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
log_task_duration('ember build -prod') {
|
||||||
unless system("yarn --cwd #{ember_dir} run ember build -prod")
|
unless system("yarn --cwd #{ember_dir} run ember build -prod")
|
||||||
STDERR.puts "Error running ember build"
|
STDERR.puts "Error running ember build"
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
}
|
||||||
|
|
||||||
# Copy assets and generate manifest data
|
# Copy assets and generate manifest data
|
||||||
|
log_task_duration('Copy assets and generate manifest data') {
|
||||||
Dir["#{ember_cli_assets}**/*"].each do |f|
|
Dir["#{ember_cli_assets}**/*"].each do |f|
|
||||||
if f !~ /test/ && File.file?(f)
|
if f !~ /test/ && File.file?(f)
|
||||||
rel_file = f.sub(ember_cli_assets, "")
|
rel_file = f.sub(ember_cli_assets, "")
|
||||||
@ -272,8 +288,10 @@ def copy_ember_cli_assets
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
}
|
||||||
|
|
||||||
# Update manifest file
|
# Update manifest file
|
||||||
|
log_task_duration('Update manifest file') {
|
||||||
manifest_result = Dir["public/assets/.sprockets-manifest-*.json"]
|
manifest_result = Dir["public/assets/.sprockets-manifest-*.json"]
|
||||||
if manifest_result && manifest_result.size == 1
|
if manifest_result && manifest_result.size == 1
|
||||||
json = JSON.parse(File.read(manifest_result[0]))
|
json = JSON.parse(File.read(manifest_result[0]))
|
||||||
@ -281,6 +299,7 @@ def copy_ember_cli_assets
|
|||||||
json['assets'].merge!(assets)
|
json['assets'].merge!(assets)
|
||||||
File.write(manifest_result[0], json.to_json)
|
File.write(manifest_result[0], json.to_json)
|
||||||
end
|
end
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
task 'test_ember_cli_copy' do
|
task 'test_ember_cli_copy' do
|
||||||
@ -332,7 +351,6 @@ task 'assets:precompile' => 'assets:precompile:before' do
|
|||||||
|
|
||||||
if $bypass_sprockets_uglify
|
if $bypass_sprockets_uglify
|
||||||
puts "Compressing Javascript and Generating Source Maps"
|
puts "Compressing Javascript and Generating Source Maps"
|
||||||
startAll = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
||||||
manifest = Sprockets::Manifest.new(assets_path)
|
manifest = Sprockets::Manifest.new(assets_path)
|
||||||
|
|
||||||
locales = Set.new(["en"])
|
locales = Set.new(["en"])
|
||||||
@ -341,6 +359,7 @@ task 'assets:precompile' => 'assets:precompile:before' do
|
|||||||
locales.add(SiteSetting.default_locale)
|
locales.add(SiteSetting.default_locale)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
log_task_duration('Done compressing all JS files') {
|
||||||
concurrent? do |proc|
|
concurrent? do |proc|
|
||||||
manifest.files
|
manifest.files
|
||||||
.select { |k, v| k =~ /\.js$/ }
|
.select { |k, v| k =~ /\.js$/ }
|
||||||
@ -356,8 +375,8 @@ task 'assets:precompile' => 'assets:precompile:before' do
|
|||||||
STDERR.puts "Skipping: #{file}"
|
STDERR.puts "Skipping: #{file}"
|
||||||
else
|
else
|
||||||
proc.call do
|
proc.call do
|
||||||
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
log_task_duration(file) {
|
||||||
STDERR.puts "#{start} Compressing: #{file}"
|
STDERR.puts "Compressing: #{file}"
|
||||||
|
|
||||||
if max_compress
|
if max_compress
|
||||||
FileUtils.mv(path, _path)
|
FileUtils.mv(path, _path)
|
||||||
@ -368,16 +387,12 @@ task 'assets:precompile' => 'assets:precompile:before' do
|
|||||||
info["mtime"] = File.mtime(path).iso8601
|
info["mtime"] = File.mtime(path).iso8601
|
||||||
gzip(path)
|
gzip(path)
|
||||||
brotli(path, max_compress)
|
brotli(path, max_compress)
|
||||||
|
}
|
||||||
STDERR.puts "Done compressing #{file} : #{(Process.clock_gettime(Process::CLOCK_MONOTONIC) - start).round(2)} secs"
|
|
||||||
STDERR.puts
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
}
|
||||||
STDERR.puts "Done compressing all JS files : #{(Process.clock_gettime(Process::CLOCK_MONOTONIC) - startAll).round(2)} secs"
|
|
||||||
STDERR.puts
|
|
||||||
|
|
||||||
# protected
|
# protected
|
||||||
manifest.send :save
|
manifest.send :save
|
||||||
|
Loading…
x
Reference in New Issue
Block a user