feat: Complete PlatformServiceMixin migration and enhance tooling

- Update migration assessment: All database operations now migrated (60/60 components)
- Enhance validate-migration.sh: Improved pattern detection and reporting
- Upgrade format-markdown.sh: Add parallel processing and CI-friendly output
- Clean up legacy logging patterns in ContactImportView.vue
- Remove unused imports and optimize PlatformServiceMixin
- Streamline deep links service and utility functions

Migration Status: 100% database operations complete, only 4 logging cleanup files remain
This commit is contained in:
Matthew Raymer
2025-07-16 12:28:17 +00:00
parent 5f2ab5f913
commit cc0ae015bc
8 changed files with 463 additions and 42 deletions

View File

@@ -4,34 +4,181 @@
# Author: Matthew Raymer
# Date: 2025-07-09
# Description: Format markdown files to comply with project markdown ruleset
# Enhanced: Auto-fix, parallel lint, summary, CI-friendly, multi-linter support
# Always fixes missing blank lines around headings.
set -e
if [ $# -eq 0 ]; then
echo "Usage: $0 <file-or-directory> [more files...]"
# Fix missing blank lines above and below headings in a Markdown file
fix_blank_lines_around_headings() {
local file="$1"
awk '
BEGIN { prev=""; }
{
if ($0 ~ /^#{1,6} /) {
if (NR > 1 && prev != "") print "";
print $0;
getline nextline;
if (nextline != "") print "";
print nextline;
prev = nextline;
next;
}
print $0;
prev = $0;
}
' "$file" > "$file.tmp" && mv "$file.tmp" "$file"
}
show_help() {
echo "Usage: $0 [--fix] [--ci] [--linter <markdownlint|prettier|both>] <file-or-directory> [more files...]"
echo "Formats and lints markdown files."
echo "Options:"
echo " -h, --help Show this help message"
echo " --fix Auto-fix lint errors (if supported)"
echo " --ci CI-friendly output (machine-readable)"
echo " --linter <type> Choose linter: markdownlint, prettier, or both (default: both)"
echo " <file-or-directory> Markdown files or directories to process"
exit 0
}
# Default options
fix=0
ci=0
linter="both"
args=()
# Parse flags
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help) show_help ;;
--fix) fix=1 ; shift ;;
--ci) ci=1 ; shift ;;
--linter) linter="$2" ; shift 2 ;;
--) shift ; break ;;
-*) echo "Unknown option: $1"; show_help ;;
*) args+=("$1"); shift ;;
esac
done
if [ ${#args[@]} -eq 0 ]; then
show_help
fi
# Tool checks
for tool in awk sed; do
if ! command -v $tool >/dev/null 2>&1; then
echo "$tool is required but not installed. Exiting."
exit 1
fi
done
if ! command -v npx >/dev/null 2>&1; then
echo "npx is required for linting. Exiting."
exit 1
fi
for target in "$@"; do
# Check for prettier and markdownlint availability
has_prettier=0
has_markdownlint=0
if npx prettier --version >/dev/null 2>&1; then
has_prettier=1
fi
if npx markdownlint --version >/dev/null 2>&1; then
has_markdownlint=1
fi
# Respect .markdownlintignore if present
mlint_ignore=""
if [ -f .markdownlintignore ]; then
mlint_ignore="--ignore-path .markdownlintignore"
fi
# Gather files
all_files=()
for target in "${args[@]}"; do
if [ -d "$target" ]; then
files=$(find "$target" -type f -name "*.md")
while IFS= read -r -d $'\0' file; do
all_files+=("$file")
done < <(find "$target" -type f -name "*.md" -print0)
else
files="$target"
all_files+=("$target")
fi
for file in $files; do
# Remove trailing spaces
sed -i 's/[[:space:]]*$//' "$file"
# Remove multiple consecutive blank lines
awk 'NF{blank=0} !NF{blank++} blank<2' "$file" > "$file.tmp" && mv "$file.tmp" "$file"
# Ensure file ends with a single newline
awk '1; END{if (NR && $0!="") print ""}' "$file" > "$file.tmp" && mv "$file.tmp" "$file"
# Optionally run markdownlint (requires npx and markdownlint-cli)
if command -v npx >/dev/null 2>&1; then
npx markdownlint "$file"
else
echo "npx/markdownlint not found, skipping lint check for $file"
fi
done
done
# Remove duplicates
all_files=( $(printf "%s\n" "${all_files[@]}" | sort -u) )
# Format and lint files
lint_errors=0
failed_files=()
passed_files=()
format_and_lint() {
file="$1"
# Fix missing blank lines around headings
fix_blank_lines_around_headings "$file"
# Basic formatting
sed -i 's/[[:space:]]*$//' "$file"
awk 'NF{blank=0} !NF{blank++} blank<2' "$file" > "$file.tmp" && mv "$file.tmp" "$file"
awk '1; END{if (NR && $0!="") print ""}' "$file" > "$file.tmp" && mv "$file.tmp" "$file"
# Auto-fix with prettier
if [[ $fix -eq 1 && ( "$linter" == "prettier" || "$linter" == "both" ) && $has_prettier -eq 1 ]]; then
npx prettier --write "$file" >/dev/null 2>&1 && echo "Auto-fixed with prettier: $file"
fi
# Auto-fix with markdownlint
if [[ $fix -eq 1 && ( "$linter" == "markdownlint" || "$linter" == "both" ) && $has_markdownlint -eq 1 ]]; then
npx markdownlint --fix $mlint_ignore "$file" >/dev/null 2>&1 && echo "Auto-fixed with markdownlint: $file"
fi
# Linting
lint_ok=1
if [[ "$linter" == "prettier" || "$linter" == "both" ]] && [[ $has_prettier -eq 1 ]]; then
if ! npx prettier --check "$file" >/dev/null 2>&1; then
lint_ok=0
echo "Prettier lint errors in $file"
fi
fi
if [[ "$linter" == "markdownlint" || "$linter" == "both" ]] && [[ $has_markdownlint -eq 1 ]]; then
if ! npx markdownlint $mlint_ignore "$file"; then
lint_ok=0
echo "Markdownlint errors in $file"
fi
fi
if [[ $lint_ok -eq 1 ]]; then
passed_files+=("$file")
[[ $ci -eq 0 ]] && echo "PASS: $file"
else
failed_files+=("$file")
lint_errors=1
[[ $ci -eq 0 ]] && echo "FAIL: $file"
[[ $ci -eq 1 ]] && echo "$file"
fi
}
# Export for xargs
export -f format_and_lint
export fix linter has_prettier has_markdownlint mlint_ignore ci
# Run in parallel (4 at a time)
printf "%s\n" "${all_files[@]}" | xargs -n 1 -P 4 -I {} bash -c 'format_and_lint "$@"' _ {}
# Summary
if [[ $ci -eq 0 ]]; then
echo
echo "Lint summary:"
echo "Passed: ${#passed_files[@]}"
echo "Failed: ${#failed_files[@]}"
if [ ${#failed_files[@]} -gt 0 ]; then
printf '%s\n' "${failed_files[@]}"
fi
fi
if [ $lint_errors -ne 0 ]; then
echo "Some files have markdownlint or prettier errors. Please fix them."
exit 1
fi
echo "Markdown formatting complete."

View File

@@ -24,6 +24,10 @@ legacy_db_imports=0
legacy_log_imports=0
direct_platform_usage=0
mixin_usage=0
mixed_pattern_count=0
technically_compliant_count=0
needs_human_testing_count=0
human_tested_count=0
# Function to log with timestamp
log_with_timestamp() {
@@ -37,7 +41,11 @@ check_legacy_patterns() {
# Check for legacy databaseUtil imports
echo -n " Checking databaseUtil imports... "
legacy_db_files=$(find src -name "*.vue" -o -name "*.ts" | xargs grep -l "import.*databaseUtil" 2>/dev/null || true)
legacy_db_imports=$(echo "$legacy_db_files" | grep -c . 2>/dev/null || echo "0")
if [ -n "$legacy_db_files" ]; then
legacy_db_imports=$(echo "$legacy_db_files" | wc -l)
else
legacy_db_imports=0
fi
if [ "$legacy_db_imports" -gt 0 ]; then
echo -e "${RED}Found $legacy_db_imports files${NC}"
@@ -51,7 +59,11 @@ check_legacy_patterns() {
# Check for legacy logging imports
echo -n " Checking logConsoleAndDb imports... "
legacy_log_files=$(find src -name "*.vue" -o -name "*.ts" | xargs grep -l "logConsoleAndDb" 2>/dev/null || true)
legacy_log_imports=$(echo "$legacy_log_files" | grep -c . 2>/dev/null || echo "0")
if [ -n "$legacy_log_files" ]; then
legacy_log_imports=$(echo "$legacy_log_files" | wc -l)
else
legacy_log_imports=0
fi
if [ "$legacy_log_imports" -gt 0 ]; then
echo -e "${RED}Found $legacy_log_imports files${NC}"
@@ -65,7 +77,11 @@ check_legacy_patterns() {
# Check for direct PlatformServiceFactory usage
echo -n " Checking direct PlatformServiceFactory usage... "
direct_platform_files=$(find src -name "*.vue" -o -name "*.ts" | xargs grep -l "PlatformServiceFactory.getInstance" 2>/dev/null || true)
direct_platform_usage=$(echo "$direct_platform_files" | grep -c . 2>/dev/null || echo "0")
if [ -n "$direct_platform_files" ]; then
direct_platform_usage=$(echo "$direct_platform_files" | wc -l)
else
direct_platform_usage=0
fi
if [ "$direct_platform_usage" -gt 0 ]; then
echo -e "${YELLOW}Found $direct_platform_usage files${NC}"
@@ -83,7 +99,11 @@ check_positive_patterns() {
# Check for PlatformServiceMixin usage
echo -n " Checking PlatformServiceMixin usage... "
mixin_files=$(find src -name "*.vue" | xargs grep -l "PlatformServiceMixin" 2>/dev/null || true)
mixin_usage=$(echo "$mixin_files" | grep -c . 2>/dev/null || echo "0")
if [ -n "$mixin_files" ]; then
mixin_usage=$(echo "$mixin_files" | wc -l)
else
mixin_usage=0
fi
if [ "$mixin_usage" -gt 0 ]; then
echo -e "${GREEN}Found $mixin_usage files${NC}"
@@ -116,7 +136,11 @@ analyze_migration_patterns() {
fi
' _ {} \;)
db_components_no_mixin_count=$(echo "$db_components_no_mixin" | grep -c . 2>/dev/null || echo "0")
if [ -n "$db_components_no_mixin" ]; then
db_components_no_mixin_count=$(echo "$db_components_no_mixin" | wc -l)
else
db_components_no_mixin_count=0
fi
if [ "$db_components_no_mixin_count" -gt 0 ]; then
echo -e "${RED}Found $db_components_no_mixin_count components${NC}"
@@ -138,7 +162,11 @@ analyze_migration_patterns() {
fi
' _ {} \;)
mixed_pattern_count=$(echo "$mixed_pattern_files" | grep -c . 2>/dev/null || echo "0")
if [ -n "$mixed_pattern_files" ]; then
mixed_pattern_count=$(echo "$mixed_pattern_files" | wc -l)
else
mixed_pattern_count=0
fi
if [ "$mixed_pattern_count" -gt 0 ]; then
echo -e "${YELLOW}Found $mixed_pattern_count files${NC}"
@@ -156,7 +184,11 @@ analyze_migration_patterns() {
fi
' _ {} \;)
technically_compliant_count=$(echo "$technically_compliant_files" | grep -c . 2>/dev/null || echo "0")
if [ -n "$technically_compliant_files" ]; then
technically_compliant_count=$(echo "$technically_compliant_files" | wc -l)
else
technically_compliant_count=0
fi
if [ "$technically_compliant_count" -gt 0 ]; then
echo -e "${GREEN}Found $technically_compliant_count files${NC}"
@@ -181,7 +213,11 @@ check_human_testing_status() {
# Files requiring human testing (technically compliant but not tested)
echo -n " Files requiring human testing... "
needs_human_testing=$(echo "$technically_compliant_files" | grep -v -F "$human_tested_files" | grep -v "^[[:space:]]*$" || true)
needs_human_testing_count=$(echo "$needs_human_testing" | grep -v "^[[:space:]]*$" | wc -l 2>/dev/null || echo "0")
if [ -n "$needs_human_testing" ]; then
needs_human_testing_count=$(echo "$needs_human_testing" | grep -v "^[[:space:]]*$" | wc -l)
else
needs_human_testing_count=0
fi
if [ "$needs_human_testing_count" -gt 0 ]; then
echo -e "${YELLOW}Found $needs_human_testing_count files${NC}"
@@ -193,7 +229,11 @@ check_human_testing_status() {
# Files with confirmed human testing
echo -n " Human tested files... "
human_tested_count=$(echo "$human_tested_files" | grep -v "^[[:space:]]*$" | wc -l 2>/dev/null || echo "0")
if [ -n "$human_tested_files" ]; then
human_tested_count=$(echo "$human_tested_files" | grep -v "^[[:space:]]*$" | wc -l)
else
human_tested_count=0
fi
if [ "$human_tested_count" -gt 0 ]; then
echo -e "${GREEN}Found $human_tested_count files${NC}"
@@ -210,7 +250,12 @@ generate_report() {
echo "=============================="
total_vue_files=$(find src -name "*.vue" | wc -l)
migration_percentage=$((mixin_usage * 100 / total_vue_files))
# Handle division by zero
if [ "$total_vue_files" -gt 0 ]; then
migration_percentage=$((mixin_usage * 100 / total_vue_files))
else
migration_percentage=0
fi
echo "Total Vue components: $total_vue_files"
echo "Components using PlatformServiceMixin: $mixin_usage"
@@ -219,7 +264,12 @@ generate_report() {
echo "Technical Migration Status:"
echo " - Technically compliant files: $technically_compliant_count"
echo " - Mixed pattern files: $mixed_pattern_count"
echo " - Files needing migration: $((total_vue_files - technically_compliant_count - mixed_pattern_count))"
# Ensure variables are numeric for arithmetic
total_vue_files_num=${total_vue_files:-0}
technically_compliant_num=${technically_compliant_count:-0}
mixed_pattern_num=${mixed_pattern_count:-0}
files_needing_migration=$((total_vue_files_num - technically_compliant_num - mixed_pattern_num))
echo " - Files needing migration: $files_needing_migration"
echo ""
echo "Legacy patterns found:"
echo " - databaseUtil imports: $legacy_db_imports"