From 51ddcedf2e476ec1bc0e83589f896b68609697d8 Mon Sep 17 00:00:00 2001 From: Bill ZHANG <36790218+Lutra-Fs@users.noreply.github.com> Date: Sun, 27 Oct 2024 16:01:18 +1100 Subject: [PATCH] Update run.sh --- run.sh | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/run.sh b/run.sh index 83532a7d..076964f9 100644 --- a/run.sh +++ b/run.sh @@ -22,8 +22,65 @@ sed -i "s|{{CheckTime}}|$DATE|g" tmp/chrome.xml ./util/generator.sh stable-x86 stable-x64 beta-x86 beta-x64 dev-x86 dev-x64 canary-x86 canary-x64 -xmllint --format tmp/chrome.xml > tmp/api/chrome.xml -xmllint --noblanks tmp/chrome.xml > tmp/api/chrome.min.xml +# Function to format XML +format_xml() { + local input=$1 + local output=$2 + + # Read input file and process it + sed ' + # Add newline after elements that end with > + s/>/>\n/g + # Remove empty lines + /^[[:space:]]*$/d + ' "$input" | awk ' + # Initialize indent level + BEGIN { indent = 0 } + + # Processing each line + { + # Remove leading/trailing whitespace + gsub(/^[ \t]+|[ \t]+$/, "") + + # Decrease indent for closing tags + if (match($0, "^$")) { + indent += 2 + } + } + ' > "$output" +} + +# Function to minify XML +minify_xml() { + local input=$1 + local output=$2 + + # Remove newlines, leading/trailing whitespace, and consolidate spaces + tr -d '\n' < "$input" | \ + sed -E ' + # Remove spaces between tags + s/>[[:space:]]+ "$output" +} + +# Format XML +format_xml "tmp/chrome.xml" "tmp/api/chrome.xml" + +# Minify XML +minify_xml "tmp/chrome.xml" "tmp/api/chrome.min.xml" cp -rf tmp/index.html public/index.html cp -rf tmp/api/chrome.xml public/api/chrome.xml