From c4253cc49bdd81e2138ed8a0e1bf3b031401370e Mon Sep 17 00:00:00 2001 From: Patrick Cartlidge Date: Tue, 14 Nov 2023 10:01:43 +0000 Subject: [PATCH] Audit now checks if component uses govuk-frontend If a component being used in an application is uses govuk-frontend ES6 JS, then a tag will be added to indicate this in the Component Audit view. This is useful to determine which components are using ES6 JS and need to have their JS be loaded in a different file. --- app/models/govuk_publishing_components/audit_comparer.rb | 1 + .../govuk_publishing_components/audit_components.rb | 9 +++++++++ .../audit/_items_in_applications.html.erb | 3 +++ 3 files changed, 13 insertions(+) diff --git a/app/models/govuk_publishing_components/audit_comparer.rb b/app/models/govuk_publishing_components/audit_comparer.rb index dab85cbfc7..868ba9bf61 100644 --- a/app/models/govuk_publishing_components/audit_comparer.rb +++ b/app/models/govuk_publishing_components/audit_comparer.rb @@ -279,6 +279,7 @@ def get_components_by_application results << { name: component_name, + govuk_frontend: component[:uses_govuk_frontend], count: locations.length, locations:, } diff --git a/app/models/govuk_publishing_components/audit_components.rb b/app/models/govuk_publishing_components/audit_components.rb index d72196bd9c..df2ca7a5b7 100644 --- a/app/models/govuk_publishing_components/audit_components.rb +++ b/app/models/govuk_publishing_components/audit_components.rb @@ -118,6 +118,11 @@ def get_component_asset_detail(detail, component) else @component_numbers[type.to_sym] += 1 details["#{type}_exists".to_sym] = true + + if type == "javascript" && uses_govuk_frontend?(file) + details[:uses_govuk_frontend] = true + end + details["#{type}_lines".to_sym] = count_lines_in(file) details["#{type}_link".to_sym] = get_asset_link(type, component) end @@ -130,6 +135,10 @@ def count_lines_in(file) File.read(file).each_line.count end + def uses_govuk_frontend?(file) + File.read(file).match(/require govuk\/components/) + end + def clean_files(files, replace) files.map { |file| clean_file_name(file.gsub(replace, "")) }.sort end diff --git a/app/views/govuk_publishing_components/audit/_items_in_applications.html.erb b/app/views/govuk_publishing_components/audit/_items_in_applications.html.erb index a3fbea2fd0..e5139ca76f 100644 --- a/app/views/govuk_publishing_components/audit/_items_in_applications.html.erb +++ b/app/views/govuk_publishing_components/audit/_items_in_applications.html.erb @@ -6,6 +6,9 @@
<%= item[:name] %> (<%= pluralize(item[:count], 'use') %>) + <% if item[:govuk_frontend] %> + ES6 JS + <% end %>
<% item[:locations].each do |application| %>