2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-07-15 15:29:12 -04:00
|
|
|
def public_root
|
|
|
|
"#{Rails.root}/public"
|
|
|
|
end
|
|
|
|
|
2018-10-03 10:15:43 -04:00
|
|
|
def public_js
|
2020-07-15 15:29:12 -04:00
|
|
|
"#{public_root}/javascripts"
|
2018-10-03 10:15:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def vendor_js
|
|
|
|
"#{Rails.root}/vendor/assets/javascripts"
|
|
|
|
end
|
|
|
|
|
|
|
|
def library_src
|
|
|
|
"#{Rails.root}/node_modules"
|
|
|
|
end
|
|
|
|
|
2020-11-25 10:58:19 -05:00
|
|
|
def html_for_section(group)
|
|
|
|
icons =
|
|
|
|
group["icons"].map do |icon|
|
|
|
|
class_attr = icon["diversity"] ? " class=\"diversity\"" : ""
|
2022-09-22 18:21:34 -04:00
|
|
|
" {{replace-emoji \":#{icon["name"]}:\" (hash lazy=true#{class_attr} tabIndex=\"0\")}}"
|
2020-11-25 10:58:19 -05:00
|
|
|
end
|
|
|
|
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
<<~HTML
|
2020-11-25 10:58:19 -05:00
|
|
|
<div class="section" data-section="#{group["name"]}">
|
|
|
|
<div class="section-header">
|
|
|
|
<span class="title">{{i18n "emoji_picker.#{group["name"]}"}}</span>
|
|
|
|
</div>
|
|
|
|
<div class="section-group">
|
|
|
|
#{icons.join("\n").strip}
|
|
|
|
</div>
|
|
|
|
</div>
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
HTML
|
2020-11-25 10:58:19 -05:00
|
|
|
end
|
|
|
|
|
2020-09-11 13:53:56 -04:00
|
|
|
def write_template(path, task_name, template)
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
header = <<~JS
|
2020-05-08 13:25:25 -04:00
|
|
|
// DO NOT EDIT THIS FILE!!!
|
2020-09-11 13:53:56 -04:00
|
|
|
// Update it by running `rake javascript:#{task_name}`
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
JS
|
2020-05-11 15:29:46 -04:00
|
|
|
|
2020-05-11 15:43:09 -04:00
|
|
|
basename = File.basename(path)
|
|
|
|
output_path = "#{Rails.root}/app/assets/javascripts/#{path}"
|
|
|
|
|
|
|
|
File.write(output_path, "#{header}\n\n#{template}")
|
|
|
|
puts "#{basename} created"
|
|
|
|
`yarn run prettier --write #{output_path}`
|
|
|
|
puts "#{basename} prettified"
|
|
|
|
end
|
2020-05-08 13:25:25 -04:00
|
|
|
|
2020-11-25 10:58:19 -05:00
|
|
|
def write_hbs_template(path, task_name, template)
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
header = <<~HBS
|
2020-11-25 10:58:19 -05:00
|
|
|
{{!-- DO NOT EDIT THIS FILE!!! --}}
|
|
|
|
{{!-- Update it by running `rake javascript:#{task_name}` --}}
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
HBS
|
2020-11-25 10:58:19 -05:00
|
|
|
|
|
|
|
basename = File.basename(path)
|
|
|
|
output_path = "#{Rails.root}/app/assets/javascripts/#{path}"
|
|
|
|
File.write(output_path, "#{header}\n#{template}")
|
2022-12-28 07:25:42 -05:00
|
|
|
`yarn run prettier --write #{output_path}`
|
2020-11-25 10:58:19 -05:00
|
|
|
puts "#{basename} created"
|
|
|
|
end
|
|
|
|
|
2020-09-21 15:06:56 -04:00
|
|
|
def dependencies
|
|
|
|
[
|
2020-08-13 21:53:27 -04:00
|
|
|
{ source: "ace-builds/src-min-noconflict/ace.js", destination: "ace.js", public: true },
|
2018-10-03 10:15:43 -04:00
|
|
|
{
|
2021-03-01 09:15:17 -05:00
|
|
|
source: "@json-editor/json-editor/dist/jsoneditor.js",
|
2019-05-07 23:42:49 -04:00
|
|
|
package_name: "@json-editor/json-editor",
|
2020-09-21 15:06:56 -04:00
|
|
|
public: true,
|
2023-01-09 07:10:19 -05:00
|
|
|
},
|
2022-06-15 13:49:04 -04:00
|
|
|
{ source: "chart.js/dist/chart.min.js", public: true },
|
2020-08-06 11:57:06 -04:00
|
|
|
{ source: "chartjs-plugin-datalabels/dist/chartjs-plugin-datalabels.min.js", public: true },
|
2021-02-18 09:07:26 -05:00
|
|
|
{ source: "diffhtml/dist/diffhtml.min.js", public: true },
|
2018-10-03 10:15:43 -04:00
|
|
|
{ source: "magnific-popup/dist/jquery.magnific-popup.min.js", public: true },
|
|
|
|
{ source: "pikaday/pikaday.js", public: true },
|
2019-02-12 13:57:52 -05:00
|
|
|
{ source: "moment/moment.js" },
|
2022-02-25 20:06:12 -05:00
|
|
|
{ source: "moment/locale/.", destination: "moment-locale" },
|
2023-01-09 07:10:19 -05:00
|
|
|
{
|
2019-05-07 23:42:49 -04:00
|
|
|
source: "moment-timezone/builds/moment-timezone-with-data-10-year-range.js",
|
|
|
|
destination: "moment-timezone-with-data.js",
|
2023-01-09 07:10:19 -05:00
|
|
|
},
|
|
|
|
{
|
2022-02-25 20:06:12 -05:00
|
|
|
source: "@discourse/moment-timezone-names-translations/locales/.",
|
2019-02-25 14:40:02 -05:00
|
|
|
destination: "moment-timezone-names-locale",
|
2023-01-09 07:10:19 -05:00
|
|
|
},
|
2021-06-23 11:31:12 -04:00
|
|
|
{
|
|
|
|
source: "squoosh/codecs/mozjpeg/enc/mozjpeg_enc.js",
|
|
|
|
destination: "squoosh",
|
|
|
|
public: true,
|
|
|
|
skip_versioning: true,
|
2023-01-09 07:10:19 -05:00
|
|
|
},
|
|
|
|
{
|
2021-06-23 11:31:12 -04:00
|
|
|
source: "squoosh/codecs/mozjpeg/enc/mozjpeg_enc.wasm",
|
|
|
|
destination: "squoosh",
|
2020-09-21 15:06:56 -04:00
|
|
|
public: true,
|
2021-03-01 09:15:17 -05:00
|
|
|
skip_versioning: true,
|
2021-06-23 11:31:12 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
source: "squoosh/codecs/resize/pkg/squoosh_resize.js",
|
|
|
|
destination: "squoosh",
|
|
|
|
public: true,
|
|
|
|
skip_versioning: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
source: "squoosh/codecs/resize/pkg/squoosh_resize_bg.wasm",
|
|
|
|
destination: "squoosh",
|
|
|
|
public: true,
|
|
|
|
skip_versioning: true,
|
2021-07-06 20:39:33 -04:00
|
|
|
},
|
2018-10-03 10:15:43 -04:00
|
|
|
]
|
2020-09-21 15:06:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def node_package_name(f)
|
2021-03-01 09:15:17 -05:00
|
|
|
f[:package_name] || f[:source].split("/").first
|
2020-09-21 15:06:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def public_path_name(f)
|
|
|
|
f[:destination] || node_package_name(f)
|
|
|
|
end
|
|
|
|
|
2022-05-02 11:10:26 -04:00
|
|
|
def absolute_sourcemap(dest)
|
|
|
|
File.open(dest) do |file|
|
|
|
|
contents = file.read
|
|
|
|
contents.gsub!(/sourceMappingURL=(.*)/, 'sourceMappingURL=/\1')
|
|
|
|
File.open(dest, "w+") { |d| d.write(contents) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-11-01 20:34:37 -04:00
|
|
|
def generate_admin_sidebar_nav_map
|
|
|
|
vague_categories = { "root" => [] }
|
|
|
|
|
|
|
|
admin_routes =
|
|
|
|
Rails
|
|
|
|
.application
|
|
|
|
.routes
|
|
|
|
.routes
|
|
|
|
.map do |route|
|
|
|
|
next if route.verb != "GET"
|
|
|
|
path = route.path.spec.to_s.gsub("(.:format)", "")
|
|
|
|
next if !path.include?("admin")
|
|
|
|
next if path.include?("/:") || path.include?("admin-login")
|
|
|
|
path
|
|
|
|
end
|
|
|
|
.compact
|
|
|
|
|
2023-11-01 22:13:20 -04:00
|
|
|
# TODO (martin): This will generate the engine routes based on installed plugins,
|
|
|
|
# so it is not generic enough to use here. Need to think of another way to do
|
|
|
|
# this and reconcile with the Ember routes from the client; maybe some button
|
|
|
|
# that does it at runtime for this experiment?
|
|
|
|
engine_routes = []
|
|
|
|
# engine_routes = Rails::Engine
|
|
|
|
# .subclasses
|
|
|
|
# .map do |engine|
|
|
|
|
# engine
|
|
|
|
# .routes
|
|
|
|
# .routes
|
|
|
|
# .map do |route|
|
|
|
|
# next if route.verb != "GET"
|
|
|
|
# path = route.path.spec.to_s.gsub("(.:format)", "")
|
|
|
|
# next if !path.include?("admin")
|
|
|
|
# next if path.include?("/:") || path.include?("admin-login")
|
|
|
|
# path
|
|
|
|
# end
|
|
|
|
# .compact
|
|
|
|
# end
|
|
|
|
# .flatten
|
2023-11-01 20:34:37 -04:00
|
|
|
|
|
|
|
admin_routes = admin_routes.concat(engine_routes)
|
|
|
|
|
|
|
|
admin_routes.each do |path|
|
|
|
|
split_path = path.split("/")
|
|
|
|
if split_path.length >= 3
|
|
|
|
vague_categories[split_path[2]] ||= []
|
|
|
|
vague_categories[split_path[2]] << { path: path }
|
|
|
|
else
|
|
|
|
vague_categories["root"] << { path: path }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Copy this JS to your browser to get the Ember routes.
|
|
|
|
#
|
|
|
|
<<~JS
|
|
|
|
let routeMap = {}
|
|
|
|
for (const [key, value] of Object.entries(
|
|
|
|
Object.fromEntries(
|
|
|
|
Object.entries(
|
|
|
|
Discourse.__container__.lookup("service:router")._router._routerMicrolib
|
|
|
|
.recognizer.names
|
|
|
|
).filter(([key]) => key.includes("admin"))
|
|
|
|
)
|
|
|
|
)) {
|
|
|
|
let route = value.segments
|
|
|
|
.map((s) => s.value)
|
|
|
|
.join("/")
|
|
|
|
.replace("//", "/");
|
|
|
|
if (
|
|
|
|
route.includes("dummy") ||
|
|
|
|
route.includes("loading") ||
|
|
|
|
route.includes("_id") ||
|
|
|
|
route.includes("admin-invite")
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
routeMap[key] = route;
|
|
|
|
}
|
|
|
|
console.log(JSON.stringify(routeMap));
|
|
|
|
JS
|
|
|
|
|
|
|
|
# Paste the output below between ROUTE_MAP.
|
|
|
|
#
|
|
|
|
ember_route_map = <<~ROUTE_MAP
|
2023-11-01 22:13:20 -04:00
|
|
|
{"admin.dashboard.general":"/admin/","admin.dashboard":"/admin/","admin":"/admin/","admin.dashboardModeration":"/admin/dashboard/moderation","admin.dashboardSecurity":"/admin/dashboard/security","admin.dashboardReports":"/admin/dashboard/reports","adminSiteSettings.index":"/admin/site_settings/","adminSiteSettings":"/admin/site_settings/","adminEmail.sent":"/admin/email/sent","adminEmail.skipped":"/admin/email/skipped","adminEmail.bounced":"/admin/email/bounced","adminEmail.received":"/admin/email/received","adminEmail.rejected":"/admin/email/rejected","adminEmail.previewDigest":"/admin/email/preview-digest","adminEmail.advancedTest":"/admin/email/advanced-test","adminEmail.index":"/admin/email/","adminEmail":"/admin/email/","adminCustomize.colors.index":"/admin/customize/colors/","adminCustomize.colors":"/admin/customize/colors/","adminCustomizeThemes.index":"/admin/customize/themes/","adminCustomizeThemes":"/admin/customize/themes/","adminSiteText.edit":"/admin/customize/site_texts/id","adminSiteText.index":"/admin/customize/site_texts/","adminSiteText":"/admin/customize/site_texts/","adminUserFields":"/admin/customize/user_fields","adminEmojis":"/admin/customize/emojis","adminPermalinks":"/admin/customize/permalinks","adminEmbedding":"/admin/customize/embedding","adminCustomizeEmailTemplates.edit":"/admin/customize/email_templates/id","adminCustomizeEmailTemplates.index":"/admin/customize/email_templates/","adminCustomizeEmailTemplates":"/admin/customize/email_templates/","adminCustomizeRobotsTxt":"/admin/customize/robots","adminCustomizeEmailStyle.edit":"/admin/customize/email_style/field_name","adminCustomizeEmailStyle.index":"/admin/customize/email_style/","adminCustomizeEmailStyle":"/admin/customize/email_style/","adminCustomizeFormTemplates.new":"/admin/customize/form-templates/new","adminCustomizeFormTemplates.edit":"/admin/customize/form-templates/id","adminCustomizeFormTemplates.index":"/admin/customize/form-templates/","adminCustomizeFormTemplates":"/admin/customize/form-templates/","adminWatchedWords.index":"/admin/customize/watched_words/","adminWatchedWords":"/admin/customize/watched_words/","adminCustomize.index":"/admin/customize/","adminCustomize":"/admin/customize/","adminApiKeys.new":"/admin/api/keys/new","adminApiKeys.index":"/admin/api/keys/","adminApiKeys":"/admin/api/keys/","adminWebHooks.index":"/admin/api/web_hooks/","adminWebHooks":"/admin/api/web_hooks/","adminApi.index":"/admin/api/","adminApi":"/admin/api/","admin.backups.logs":"/admin/backups/logs","admin.backups.index":"/admin/backups/","admin.backups":"/admin/backups/","adminReports.show":"/admin/reports/type","adminReports.index":"/admin/reports/","adminReports":"/admin/reports/","adminLogs.staffActionLogs":"/admin/logs/staff_action_logs","adminLogs.screenedEmails":"/admin/logs/screened_emails","adminLogs.screenedIpAddresses":"/admin/logs/screened_ip_addresses","adminLogs.screenedUrls":"/admin/logs/screened_urls","adminSearchLogs.index":"/admin/logs/search_logs/","adminSearchLogs":"/admin/logs/search_logs/","adminSearchLogs.term":"/admin/logs/search_logs/term","adminLogs.index":"/admin/logs/","adminLogs":"/admin/logs/","adminUsersList.show":"/admin/users/list/filter","adminUsersList.index":"/admin/users/list/","adminUsersList":"/admin/users/list/","adminUsers.index":"/admin/users/","adminUsers":"/admin/users/","adminBadges.index":"/admin/badges/","adminBadges":"/admin/badges/","adminPlugins.index":"/admin/plugins/","adminPlugins":"/admin/plugins/","admin-revamp.lobby":"/admin-revamp/","admin-revamp":"/admin-revamp/","admin-revamp.config.area":"/admin-revamp/config/area","admin-revamp.config.index":"/admin-revamp/config/","admin-revamp.config":"/admin-revamp/config/"}
|
2023-11-01 20:34:37 -04:00
|
|
|
ROUTE_MAP
|
|
|
|
ember_route_map = JSON.parse(ember_route_map)
|
|
|
|
|
|
|
|
# Match the Ember routes to the rails routes.
|
|
|
|
vague_categories.each do |category, route_data|
|
|
|
|
route_data.each do |rails_route|
|
|
|
|
ember_route_map.each do |ember_route_name, ember_path|
|
|
|
|
rails_route[:ember_route] = ember_route_name if ember_path == rails_route[:path] ||
|
|
|
|
ember_path == rails_route[:path] + "/"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Remove all rails routes that don't have an Ember equivalent.
|
|
|
|
vague_categories.each do |category, route_data|
|
|
|
|
vague_categories[category] = route_data.reject { |rails_route| !rails_route.key?(:ember_route) }
|
|
|
|
end
|
|
|
|
|
|
|
|
# Remove all categories that don't have any routes (meaning they are all rails-only).
|
|
|
|
vague_categories.each do |category, route_data|
|
|
|
|
vague_categories.delete(category) if route_data.length == 0
|
|
|
|
end
|
|
|
|
|
|
|
|
# Output in the format needed for sidebar sections and links.
|
|
|
|
vague_categories.map do |category, route_data|
|
|
|
|
category_text = category.titleize.gsub("Admin ", "")
|
|
|
|
{
|
|
|
|
name: category,
|
|
|
|
text: category_text,
|
|
|
|
links:
|
|
|
|
route_data.map do |rails_route|
|
|
|
|
{
|
|
|
|
name: rails_route[:path].split("/").compact_blank.join("_").chomp,
|
|
|
|
route: rails_route[:ember_route],
|
|
|
|
text:
|
|
|
|
rails_route[:path]
|
|
|
|
.split("/")
|
|
|
|
.compact_blank
|
|
|
|
.join(" ")
|
|
|
|
.chomp
|
|
|
|
.titleize
|
|
|
|
.gsub("Admin ", "")
|
|
|
|
.gsub("#{category_text} ", ""),
|
|
|
|
}
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-21 15:06:56 -04:00
|
|
|
task "javascript:update_constants" => :environment do
|
|
|
|
task_name = "update_constants"
|
|
|
|
|
2023-10-24 21:45:10 -04:00
|
|
|
auto_groups =
|
|
|
|
Group::AUTO_GROUPS.inject({}) do |result, (group_name, group_id)|
|
|
|
|
result.merge(
|
|
|
|
group_name => {
|
|
|
|
id: group_id,
|
|
|
|
automatic: true,
|
|
|
|
name: group_name,
|
|
|
|
display_name: group_name,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2020-09-21 15:06:56 -04:00
|
|
|
write_template("discourse/app/lib/constants.js", task_name, <<~JS)
|
|
|
|
export const SEARCH_PRIORITIES = #{Searchable::PRIORITIES.to_json};
|
|
|
|
|
|
|
|
export const SEARCH_PHRASE_REGEXP = '#{Search::PHRASE_MATCH_REGEXP_PATTERN}';
|
2023-03-26 22:03:16 -04:00
|
|
|
|
|
|
|
export const SIDEBAR_URL = {
|
|
|
|
max_icon_length: #{SidebarUrl::MAX_ICON_LENGTH},
|
|
|
|
max_name_length: #{SidebarUrl::MAX_NAME_LENGTH},
|
|
|
|
max_value_length: #{SidebarUrl::MAX_VALUE_LENGTH}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const SIDEBAR_SECTION = {
|
|
|
|
max_title_length: #{SidebarSection::MAX_TITLE_LENGTH},
|
|
|
|
}
|
2023-10-24 21:45:10 -04:00
|
|
|
|
|
|
|
export const AUTO_GROUPS = #{auto_groups.to_json};
|
2020-09-21 15:06:56 -04:00
|
|
|
JS
|
|
|
|
|
2023-11-01 20:34:37 -04:00
|
|
|
write_template("discourse/app/lib/sidebar/admin-nav-map.js", task_name, <<~JS)
|
|
|
|
export const ADMIN_NAV_MAP = #{generate_admin_sidebar_nav_map.to_json}
|
|
|
|
JS
|
|
|
|
|
2020-10-08 15:40:06 -04:00
|
|
|
pretty_notifications = Notification.types.map { |n| " #{n[0]}: #{n[1]}," }.join("\n")
|
|
|
|
|
|
|
|
write_template("discourse/tests/fixtures/concerns/notification-types.js", task_name, <<~JS)
|
|
|
|
export const NOTIFICATION_TYPES = {
|
|
|
|
#{pretty_notifications}
|
|
|
|
};
|
|
|
|
JS
|
|
|
|
|
2020-09-21 15:06:56 -04:00
|
|
|
write_template("pretty-text/addon/emoji/data.js", task_name, <<~JS)
|
|
|
|
export const emojis = #{Emoji.standard.map(&:name).flatten.inspect};
|
|
|
|
export const tonableEmojis = #{Emoji.tonable_emojis.flatten.inspect};
|
|
|
|
export const aliases = #{Emoji.aliases.inspect.gsub("=>", ":")};
|
|
|
|
export const searchAliases = #{Emoji.search_aliases.inspect.gsub("=>", ":")};
|
|
|
|
export const translations = #{Emoji.translations.inspect.gsub("=>", ":")};
|
|
|
|
export const replacements = #{Emoji.unicode_replacements_json};
|
|
|
|
JS
|
|
|
|
|
|
|
|
write_template("pretty-text/addon/emoji/version.js", task_name, <<~JS)
|
|
|
|
export const IMAGE_VERSION = "#{Emoji::EMOJI_VERSION}";
|
|
|
|
JS
|
2020-11-25 10:58:19 -05:00
|
|
|
|
|
|
|
groups_json = JSON.parse(File.read("lib/emoji/groups.json"))
|
|
|
|
|
|
|
|
emoji_buttons = groups_json.map { |group| <<~HTML }
|
DEV: Remove usage of {{action}} modifiers - Take 2 (#18476)
This PR enables the [`no-action-modifiers`](https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/no-action-modifiers.md) template lint rule and removes all usages of the `{{action}}` modifier in core.
In general, instances of `{{action "x"}}` have been replaced with `{{on "click" (action "x")}}`.
In many cases, such as for `a` elements, we also need to prevent default event handling to avoid unwanted side effects. While the `{{action}}` modifier internally calls `event.preventDefault()`, we need to handle these cases more explicitly. For this purpose, this PR also adds the [ember-event-helpers](https://github.com/buschtoens/ember-event-helpers) dependency so we can use the `prevent-default` handler. For instance:
```
<a href {{on "click" (prevent-default (action "x"))}}>Do X</a>
```
Note that `action` has not in general been refactored away as a helper yet. In general, all event handlers should be methods on the corresponding component and referenced directly (e.g. `{{on "click" this.doSomething}}`). However, the `action` helper is used extensively throughout the codebase and often references methods in the `actions` hash on controllers or routes. Thus this refactor will also be extensive and probably deserves a separate PR.
Note: This work was done to complement #17767 by minimizing the potential impact of the `action` modifier override, which uses private API and arguably should be replaced with an AST transform.
This is a followup to #18333, which had to be reverted because it did not account for the default treatment of modifier keys by the {{action}} modifier.
Commits:
* Enable `no-action-modifiers` template lint rule
* Replace {{action "x"}} with {{on "click" (action "x")}}
* Remove unnecessary action helper usage
* Remove ctl+click tests for user-menu
These tests now break in Chrome when used with addEventListener. As per the comment, they can probably be safely removed.
* Prevent default event handlers to avoid unwanted side effects
Uses `event.preventDefault()` in event handlers to prevent default event handling. This had been done automatically by the `action` modifier, but is not always desirable or necessary.
* Restore UserCardContents#showUser action to avoid regression
By keeping the `showUser` action, we can avoid a breaking change for plugins that rely upon it, while not interfering with the `showUser` argument that's been passed.
* Revert EditCategoryTab#selectTab -> EditCategoryTab#select
Avoid potential breaking change in themes / plugins
* Restore GroupCardContents#showGroup action to avoid regression
By keeping the `showGroup` action, we can avoid a breaking change for plugins that rely upon it, while not interfering with the `showGroup` argument that's been passed.
* Restore SecondFactorAddTotp#showSecondFactorKey action to avoid regression
By keeping the `showSecondFactorKey` action, we can avoid a breaking change for plugins that rely upon it, while not interfering with the `showSecondFactorKey` property that's maintained on the controller.
* Refactor away from `actions` hash in ChooseMessage component
* Modernize EmojiPicker#onCategorySelection usage
* Modernize SearchResultEntry#logClick usage
* Modernize Discovery::Categories#showInserted usage
* Modernize Preferences::Account#resendConfirmationEmail usage
* Modernize MultiSelect::SelectedCategory#onSelectedNameClick usage
* Favor fn over action in SelectedChoice component
* Modernize WizardStep event handlers
* Favor fn over action usage in buttons
* Restore Login#forgotPassword action to avoid possible regression
* Introduce modKeysPressed utility
Returns an array of modifier keys that are pressed during a given `MouseEvent` or `KeyboardEvent`.
* Don't interfere with click events on links with `href` values when modifier keys are pressed
2022-10-05 08:08:54 -04:00
|
|
|
<button type="button" data-section="#{group["name"]}" {{on "click" (fn this.onCategorySelection "#{group["name"]}")}} class="btn btn-default category-button emoji">
|
2020-11-25 10:58:19 -05:00
|
|
|
{{replace-emoji ":#{group["tabicon"]}:"}}
|
|
|
|
</button>
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
HTML
|
2020-11-25 10:58:19 -05:00
|
|
|
|
|
|
|
emoji_sections = groups_json.map { |group| html_for_section(group) }
|
|
|
|
|
2023-02-19 22:20:47 -05:00
|
|
|
components_dir = "discourse/app/components"
|
2020-11-25 10:58:19 -05:00
|
|
|
write_hbs_template("#{components_dir}/emoji-group-buttons.hbs", task_name, emoji_buttons.join)
|
|
|
|
write_hbs_template("#{components_dir}/emoji-group-sections.hbs", task_name, emoji_sections.join)
|
2020-09-21 15:06:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
task "javascript:update" => "clean_up" do
|
|
|
|
require "uglifier"
|
|
|
|
|
|
|
|
yarn = system("yarn install")
|
|
|
|
abort('Unable to run "yarn install"') unless yarn
|
2018-10-03 10:15:43 -04:00
|
|
|
|
2020-09-11 13:53:56 -04:00
|
|
|
versions = {}
|
2018-10-03 10:15:43 -04:00
|
|
|
start = Time.now
|
|
|
|
|
|
|
|
dependencies.each do |f|
|
|
|
|
src = "#{library_src}/#{f[:source]}"
|
|
|
|
|
2023-02-16 04:40:11 -05:00
|
|
|
if f[:destination]
|
2018-10-03 10:15:43 -04:00
|
|
|
filename = f[:destination]
|
2023-02-16 04:40:11 -05:00
|
|
|
else
|
|
|
|
filename = f[:source].split("/").last
|
2018-10-03 10:15:43 -04:00
|
|
|
end
|
|
|
|
|
2020-07-15 15:29:12 -04:00
|
|
|
if f[:public_root]
|
|
|
|
dest = "#{public_root}/#{filename}"
|
|
|
|
elsif f[:public]
|
2020-09-21 15:06:56 -04:00
|
|
|
if f[:skip_versioning]
|
|
|
|
dest = "#{public_js}/#{filename}"
|
|
|
|
else
|
|
|
|
package_dir_name = public_path_name(f)
|
|
|
|
package_version =
|
|
|
|
JSON.parse(File.read("#{library_src}/#{node_package_name(f)}/package.json"))["version"]
|
2022-06-15 13:49:04 -04:00
|
|
|
versions[filename.downcase] = "#{package_dir_name}/#{package_version}/#{filename}"
|
2020-09-21 15:06:56 -04:00
|
|
|
|
|
|
|
path = "#{public_js}/#{package_dir_name}/#{package_version}"
|
|
|
|
dest = "#{path}/#{filename}"
|
2020-09-11 13:53:56 -04:00
|
|
|
|
2022-01-05 12:45:08 -05:00
|
|
|
FileUtils.mkdir_p(path) unless File.exist?(path)
|
2020-09-21 15:06:56 -04:00
|
|
|
end
|
2018-10-03 10:15:43 -04:00
|
|
|
else
|
|
|
|
dest = "#{vendor_js}/#{filename}"
|
|
|
|
end
|
|
|
|
|
2020-08-13 21:53:27 -04:00
|
|
|
if src.include? "ace.js"
|
2020-09-21 15:06:56 -04:00
|
|
|
versions["ace/ace.js"] = versions.delete("ace.js")
|
2020-08-13 21:53:27 -04:00
|
|
|
ace_root = "#{library_src}/ace-builds/src-min-noconflict/"
|
2021-12-29 11:02:37 -05:00
|
|
|
addtl_files = %w[
|
|
|
|
ext-searchbox
|
|
|
|
mode-html
|
|
|
|
mode-scss
|
|
|
|
mode-sql
|
2023-02-07 15:49:12 -05:00
|
|
|
mode-yaml
|
2021-12-29 11:02:37 -05:00
|
|
|
theme-chrome
|
|
|
|
theme-chaos
|
|
|
|
worker-html
|
|
|
|
]
|
2020-09-21 15:06:56 -04:00
|
|
|
dest_path = dest.split("/")[0..-2].join("/")
|
|
|
|
addtl_files.each { |file| FileUtils.cp_r("#{ace_root}#{file}.js", dest_path) }
|
2020-08-13 21:53:27 -04:00
|
|
|
end
|
|
|
|
|
2018-10-03 10:15:43 -04:00
|
|
|
STDERR.puts "New dependency added: #{dest}" unless File.exist?(dest)
|
|
|
|
|
2023-06-29 06:23:46 -04:00
|
|
|
FileUtils.cp_r(src, dest)
|
2018-10-03 10:15:43 -04:00
|
|
|
end
|
|
|
|
|
2020-09-11 13:53:56 -04:00
|
|
|
write_template("discourse/app/lib/public-js-versions.js", "update", <<~JS)
|
|
|
|
export const PUBLIC_JS_VERSIONS = #{versions.to_json};
|
|
|
|
JS
|
|
|
|
|
2018-10-03 10:15:43 -04:00
|
|
|
STDERR.puts "Completed copying dependencies: #{(Time.now - start).round(2)} secs"
|
|
|
|
end
|
2020-09-21 15:06:56 -04:00
|
|
|
|
|
|
|
task "javascript:clean_up" do
|
|
|
|
processed = []
|
|
|
|
dependencies.each do |f|
|
|
|
|
next unless f[:public] && !f[:skip_versioning]
|
|
|
|
|
|
|
|
package_dir_name = public_path_name(f)
|
|
|
|
next if processed.include?(package_dir_name)
|
|
|
|
|
|
|
|
versions = Dir["#{File.join(public_js, package_dir_name)}/*"].collect { |p| p.split("/").last }
|
|
|
|
next unless versions.present?
|
|
|
|
|
|
|
|
versions = versions.sort { |a, b| Gem::Version.new(a) <=> Gem::Version.new(b) }
|
|
|
|
puts "Keeping #{package_dir_name} version: #{versions[-1]}"
|
|
|
|
|
|
|
|
# Keep the most recent version
|
|
|
|
versions[0..-2].each do |version|
|
|
|
|
remove_path = File.join(public_js, package_dir_name, version)
|
|
|
|
puts "Removing: #{remove_path}"
|
|
|
|
FileUtils.remove_dir(remove_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
processed << package_dir_name
|
|
|
|
end
|
|
|
|
end
|