DEV: Cleanup old theme-transpiler js files in development

This commit is contained in:
David Taylor 2024-08-01 17:07:49 +01:00
parent 8b61aafe74
commit 4715ef2bb9
No known key found for this signature in database
GPG Key ID: 46904C18B1D3F434

View File

@ -80,7 +80,28 @@ class DiscourseJsProcessor
@mutex
end
def self.prune_old_transpilers!
return if Rails.env.production?
# in development/test, we have one-file-per-process, named by PID
# Clean up the oldest ones to stop the tmp directory from growing indefinitely
Dir["tmp/theme-transpiler/*.js"]
.sort_by do |f|
File.mtime(f)
rescue Errno::ENOENT
0 # Deleted by another process
end
.reverse
.drop(50)
.each do |f|
File.delete(f)
rescue Errno::ENOENT
# Deleted by another process
end
end
def self.build_theme_transpiler
prune_old_transpilers!
Discourse::Utils.execute_command(
"node",
"app/assets/javascripts/theme-transpiler/build.js",