DEV: Log duration of ember-cli asset build (#13980)

This commit is contained in:
Rafael dos Santos Silva 2021-08-10 23:43:08 -03:00 committed by GitHub
parent 683712fae7
commit 8e45fdfbb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -190,6 +190,17 @@ def concurrent?
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
@geolite_dbs ||= %w{
GeoLite2-City
@ -229,17 +240,22 @@ def copy_ember_cli_assets
assets = {}
files = {}
log_task_duration('yarn install') {
unless system("yarn --cwd #{ember_dir} install")
STDERR.puts "Error running yarn install"
exit 1
end
}
log_task_duration('ember build -prod') {
unless system("yarn --cwd #{ember_dir} run ember build -prod")
STDERR.puts "Error running ember build"
exit 1
end
}
# 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)
rel_file = f.sub(ember_cli_assets, "")
@ -272,8 +288,10 @@ def copy_ember_cli_assets
}
end
end
}
# Update manifest file
log_task_duration('Update manifest file') {
manifest_result = Dir["public/assets/.sprockets-manifest-*.json"]
if manifest_result && manifest_result.size == 1
json = JSON.parse(File.read(manifest_result[0]))
@ -281,6 +299,7 @@ def copy_ember_cli_assets
json['assets'].merge!(assets)
File.write(manifest_result[0], json.to_json)
end
}
end
task 'test_ember_cli_copy' do
@ -332,7 +351,6 @@ task 'assets:precompile' => 'assets:precompile:before' do
if $bypass_sprockets_uglify
puts "Compressing Javascript and Generating Source Maps"
startAll = Process.clock_gettime(Process::CLOCK_MONOTONIC)
manifest = Sprockets::Manifest.new(assets_path)
locales = Set.new(["en"])
@ -341,6 +359,7 @@ task 'assets:precompile' => 'assets:precompile:before' do
locales.add(SiteSetting.default_locale)
end
log_task_duration('Done compressing all JS files') {
concurrent? do |proc|
manifest.files
.select { |k, v| k =~ /\.js$/ }
@ -356,8 +375,8 @@ task 'assets:precompile' => 'assets:precompile:before' do
STDERR.puts "Skipping: #{file}"
else
proc.call do
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
STDERR.puts "#{start} Compressing: #{file}"
log_task_duration(file) {
STDERR.puts "Compressing: #{file}"
if max_compress
FileUtils.mv(path, _path)
@ -368,16 +387,12 @@ task 'assets:precompile' => 'assets:precompile:before' do
info["mtime"] = File.mtime(path).iso8601
gzip(path)
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
STDERR.puts "Done compressing all JS files : #{(Process.clock_gettime(Process::CLOCK_MONOTONIC) - startAll).round(2)} secs"
STDERR.puts
}
# protected
manifest.send :save