Skip to content

Instantly share code, notes, and snippets.

@starzonmyarmz
Last active May 2, 2023 17:42
Show Gist options
  • Save starzonmyarmz/204fbabbbe586788db2649e7181443d5 to your computer and use it in GitHub Desktop.
Save starzonmyarmz/204fbabbbe586788db2649e7181443d5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Usage
#
# ❯ ./bin/porchlight_coverage
#
# Outputs a MySQL query for each Porchlight utility/component that can be pasted
# into Google BigQuery which will update the porchlight.coverage_harvestapp table.
# You can make your life a little easier by automatically coping the MySQL query
# to your clipboard:
#
# ❯ ./bin/porchlight_coverage |pbcopy
#
# Output a table of Porchlight components to the console only:
#
# ❯ ./bin/porchlight_coverage -t
#
# Note that these RegExs use "lookaheads" and "lookbehinds" which isn't supported
# by grep in macOS. You'll need to install GNU grep with Homebrew:
#
# ❯ brew install grep
#
# By default the commands are installed with the prefix "g", which this script
# takes into account.
table_only=false
while getopts "t" opt; do
case $opt in
t)
table_only=true
;;
esac
done
directories="../harvestapp/app/views ../harvestapp/app/helpers ../harvestapp/app/assets/javascripts ../harvestapp/app/javascript"
cwidth=20
if $table_only
then
printf "\n"
printf "%-${cwidth}s %-${cwidth}s %-${cwidth}s %-${cwidth}s %-${cwidth}s\n" ID Section Name Completed Remaining
printf "%-${cwidth}s %-${cwidth}s %-${cwidth}s %-${cwidth}s %-${cwidth}s\n" -- ------- ---- --------- ---------
else
echo DELETE FROM \`harvesthq-production.porchlight.coverage_harvestapp\` WHERE 1=1\;
fi
for pattern in \
'utility:color:Color:pds-color:(?<!-)text-(inherit|default|medium|light|lighter|success|error|blue|orange)' \
'utility:flexbox:Flexbox:pds-flex|pds-inline-flex:(?<!-)flex(?!-)' \
'utility:layout:Layout:pds-block|pds-inline-block|pds-fl|pds-valign:(?<!-)valign(?!=)' \
'utility:margin:Margin:pds-(m|ml|mr|mb|mt|mx|my)-(xs|sm|md|lg|xl|xxl):(?<!-)(m|ml|mr|mb|mt)-[0-9]([0-9]*)' \
'utility:padding:Padding:pds-(p|pl|pr|pb|pt|px|py)-(xs|sm|md|lg|xl|xxl):(?<!-)(p|pl|pr|pb|pt)-[0-9]([0-9]*)' \
'utility:print:Print:pds-screen-only|pds-print-only:do-not-print|(?<!-)print-only' \
'utility:typography:Typography:pds-((h1|h2|h3|h4|h5)|weight-(bold|semi|normal)|style-(italic|normal)|text-(xl|lg|md|sm|left|center|right|top|middle|bottom)|no-wrap):(?<!-)((text-(400|500|600|12|13|14|15|16))|(valign-(top|middle|bottom))nowrap)' \
'component:alerts:Alerts:pds-alert(?!-)|<Alert:hui-alert(?!-)' \
'component:avatars:Avatars:pds-avatar:hui-avatar' \
'component:badges:Badges:pds-badge(?!-)|<Badge:text-label' \
'component:buttons:Buttons:pds-button(?!-)|<Button:hui-button(?!-)|hui-spinner|form-loading' \
'component:cards:Cards:pds-card(?!-)|<Card:hui-well(?!-)|company-plan(?!-)' \
'component:chosen:Chosen:<Chosen:' \
'component:dialogs:Dialogs:pds-dialog(?!-)|<Dialog:hui-dialog(?!-)' \
'component:empty:Empty:pds-empty(?!-):hui-empty(?!-)' \
'component:forms:Forms:pds-(input|label|checkbox|radio|choice)(?!-):hui-(input|label|checkbox|radio|choice|form|form-field)(?!-)' \
'component:menus:Menus:<Menu(?!Link|Button):(class="dropdown|className="dropdown)(?!-)' \
'component:meter:Meter:pds-meter(?!-):hui-budget-meter-back|watermelon-graph(?!-)|(?<!-)capacity-meter(?!-)|tasks-bar-graph|sbg-graph(?!-)|graph-total' \
'component:pagination:Pagination:pds-pagination(?!-)|<Pagination:will-paginate|pagination-wrapper' \
'component:popover:Popover:pds-popover:(class="popover|className="popover)(?!-)' \
'component:slats:Slats:pds-slat:' \
'component:stats:Stats:pds-stat-(block|inline)(?!-):' \
'component:tables:Tables:pds-table|pds-tr-child:(class="table|className="table)(?!-)|opened-row' \
'component:tabs:Tabs:pds-tabs(?!-):hui-tabs(?!-)' \
'component:toast:Toast:(?<!\.)pds-toast(?!-)|<Toast:hui-toast(?!-)' \
'component:tooltips:Tooltips:pds-tooltip:(class="|className=")tooltip(?!-)' \
'layout:grid:Grid:pds-row|pds-container:hui-row' \
'layout:flexlist:Flex List:pds-flex-list:' \
; do
id=$(echo $pattern | cut -f2 -d:)
section=$(echo $pattern | cut -f1 -d:)
name=$(echo $pattern | cut -f3 -d:)
completed=$(echo $pattern | cut -f4 -d:)
remaining=$(echo $pattern | cut -f5 -d:)
completed_count=$(ggrep -rwP --exclude-dir="admin" --exclude="admin.html.erb" $completed -- $directories | wc -l)
remaining_count=$(ggrep -rwP --exclude-dir="admin" --exclude="admin.html.erb" $remaining -- $directories | wc -l)
if $table_only
then
printf "%-${cwidth}s %-${cwidth}s %-${cwidth}s %-${cwidth}s %-${cwidth}s\n" "$id" "$section" "$name" "$completed_count" "$remaining_count"
else
cat <<- SQL
INSERT INTO \`harvesthq-production.porchlight.coverage_harvestapp\` (id, section, name, completed, remaining) VALUES ("$id", "$section", "$name", $completed_count, $remaining_count);
SQL
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment