Skip to content

Commit

Permalink
Add checking what components use govuk-frontend
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
patrickpatrickpatrick committed Nov 15, 2023
1 parent 095d526 commit 94db499
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/govuk_publishing_components/audit_comparer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ def get_components_by_application

results << {
name: component_name,
govuk_frontend: component[:uses_govuk_frontend],
count: locations.length,
locations:,
}
Expand Down
9 changes: 9 additions & 0 deletions app/models/govuk_publishing_components/audit_components.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= item[:name] %> (<%= pluralize(item[:count], 'use') %>)
<% if item[:govuk_frontend] %>
<span class="govuk-tag">ES6 JS</span>
<% end %>
</dt>
<dd class="govuk-summary-list__value">
<% item[:locations].each do |application| %>
Expand Down

0 comments on commit 94db499

Please sign in to comment.