DEV: Faster SCSS refresh locally for plugins

Only updates the targeted stylesheet when available
This commit is contained in:
Penar Musaraj 2020-09-01 13:56:40 -04:00
parent 5e66d7d082
commit 899b841554
No known key found for this signature in database
GPG Key ID: E390435D881FF0F7
1 changed files with 11 additions and 10 deletions

View File

@ -68,11 +68,9 @@ module Stylesheet
end end
target = nil target = nil
if !plugin_name target_match = long.match(/admin|desktop|mobile|publish/)
target_match = long.match(/admin|desktop|mobile|publish/) if target_match&.length
if target_match&.length target = target_match[0]
target = target_match[0]
end
end end
{ {
@ -106,11 +104,14 @@ module Stylesheet
MessageBus.publish '/file-change', message MessageBus.publish '/file-change', message
end end
def plugin_assets_refresh(plugin_name) def plugin_assets_refresh(plugin_name, target)
Stylesheet::Manager.clear_plugin_cache!(plugin_name) Stylesheet::Manager.clear_plugin_cache!(plugin_name)
targets = [plugin_name] targets = []
targets.push("#{plugin_name}_mobile") if DiscoursePluginRegistry.stylesheets_exists?(plugin_name, :mobile) if target.present?
targets.push("#{plugin_name}_desktop") if DiscoursePluginRegistry.stylesheets_exists?(plugin_name, :desktop) targets.push("#{plugin_name}_#{target.to_s}") if DiscoursePluginRegistry.stylesheets_exists?(plugin_name, target.to_sym)
else
targets.push(plugin_name)
end
message = targets.map! do |name| message = targets.map! do |name|
msgs = [] msgs = []
active_themes.each do |theme_id| active_themes.each do |theme_id|
@ -129,7 +130,7 @@ module Stylesheet
end end
if path[:plugin_name] if path[:plugin_name]
plugin_assets_refresh(path[:plugin_name]) plugin_assets_refresh(path[:plugin_name], path[:target])
else else
core_assets_refresh(path[:target]) core_assets_refresh(path[:target])
end end