-
-
Notifications
You must be signed in to change notification settings - Fork 157
Expand file tree
/
Copy pathreport_on_fontawesome.sh
More file actions
executable file
·73 lines (57 loc) · 2.4 KB
/
report_on_fontawesome.sh
File metadata and controls
executable file
·73 lines (57 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env bash
# This script identifies which Font Awesome files are required based on your
# source code. It requires 'git' to be installed and run from a git repository.
# It uses git-grep to recursively search all tracked files regardless of nesting.
set -eu
# Helper to write to stdout with flag termination
stdout() {
printf -- '%s\n' "$@"
}
# Helper to write to stderr with flag termination
stderr() {
printf >&2 -- '%s\n' "$@"
}
# 1. Fail fast if git is not installed or the directory is not a repo
if ! command -v git &> /dev/null; then
stderr 'Error: git is not installed or not in PATH.'
exit 1
fi
if ! git rev-parse --is-inside-work-tree &> /dev/null; then
stderr 'Error: This script must be run inside a git repository.'
exit 1
fi
# Function to count occurrences using "$@" to preserve individual pathspecs
count_icons() {
local pattern="$1"
shift # Remove the pattern, leaving only pathspecs
# We use -E for Extended Regex and -i for case-insensitivity
git grep -Ei "$pattern" -- "$@" 2>/dev/null | wc -l
}
# Print header as a single call with multiple arguments
stdout \
'--- Font Awesome Dependency Analysis ---' \
'Foundations: fontawesome.min.css (Always Required)'
# 2. Analyze project source code for Font Awesome style prefixes
# Pathspecs are passed as individual single-quoted arguments
HAS_SOLID=$(count_icons 'fa-solid|fas fa-' '*.html' '*.js' '*.css')
HAS_BRANDS=$(count_icons 'fa-brands|fab fa-' '*.html' '*.js' '*.css')
HAS_REGULAR=$(count_icons 'fa-regular|far fa-' '*.html' '*.js' '*.css')
HAS_LIGHT=$(count_icons 'fa-light|fal fa-' '*.html' '*.js' '*.css')
HAS_THIN=$(count_icons 'fa-thin|fat fa-' '*.html' '*.js' '*.css')
# 3. Map findings to the specific self-hosted files required
if [ "${HAS_SOLID}" -gt 0 ]; then
stdout 'Solid: keep css/solid.min.css and webfonts/fa-solid-900.woff2'
fi
if [ "${HAS_BRANDS}" -gt 0 ]; then
stdout 'Brands: keep css/brands.min.css and webfonts/fa-brands-400.woff2'
fi
if [ "${HAS_REGULAR}" -gt 0 ]; then
stdout 'Regular: keep css/regular.min.css and webfonts/fa-regular-400.woff2'
fi
if [ "${HAS_LIGHT}" -gt 0 ]; then
stdout 'Light: keep css/light.min.css and webfonts/fa-light-300.woff2'
fi
if [ "${HAS_THIN}" -gt 0 ]; then
stdout 'Thin: keep css/thin.min.css and webfonts/fa-thin-100.woff2'
fi
stdout '----------------------------------------'