2019-06-19 23:15:10 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# bat-extras | Copyright (C) 2019 eth-p | MIT License
|
|
|
|
#
|
|
|
|
# Repository: https://github.com/eth-p/bat-extras
|
|
|
|
# Issues: https://github.com/eth-p/bat-extras/issues
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
BIN="$HERE/bin"
|
|
|
|
SRC="$HERE/src"
|
|
|
|
LIB="$HERE/lib"
|
|
|
|
source "${LIB}/print.sh"
|
|
|
|
source "${LIB}/opt.sh"
|
2020-04-08 11:55:44 +02:00
|
|
|
source "${LIB}/constants.sh"
|
2019-06-19 23:15:10 +02:00
|
|
|
# -----------------------------------------------------------------------------
|
2019-06-21 23:55:43 +02:00
|
|
|
set -eo pipefail
|
2019-06-19 23:15:10 +02:00
|
|
|
|
|
|
|
# Runs the next build step.
|
|
|
|
#
|
|
|
|
# Arguments:
|
|
|
|
# 1 -- The build step function name.
|
|
|
|
# @ -- The function arguments.
|
|
|
|
#
|
|
|
|
# Input:
|
|
|
|
# The unprocessed file data.
|
|
|
|
#
|
|
|
|
# Output:
|
|
|
|
# The processed file data.
|
|
|
|
next() {
|
2019-10-11 22:03:47 +02:00
|
|
|
"$@"
|
2019-06-19 23:15:10 +02:00
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
# Prints a build step message.
|
|
|
|
smsg() {
|
2019-10-27 08:14:55 +01:00
|
|
|
case "$2" in
|
2020-03-31 23:51:00 +02:00
|
|
|
"SKIP") printc " %{YELLOW} %{DIM}%s [skipped]%{CLEAR}\n" "$1" 1>&2 ;;
|
2020-04-01 21:47:21 +02:00
|
|
|
*) printc " %{YELLOW} %s...%{CLEAR}\n" "$1" 1>&2 ;;
|
2019-06-19 23:15:10 +02:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2020-04-08 11:55:44 +02:00
|
|
|
# Escapes a sed pattern.
|
|
|
|
# Arguments:
|
|
|
|
# 1 -- The pattern.
|
2020-04-17 08:40:51 +02:00
|
|
|
#
|
2020-04-08 11:55:44 +02:00
|
|
|
# Output:
|
|
|
|
# The escaped string.
|
|
|
|
sed_escape() {
|
|
|
|
sed 's/\([][\\\/\^\$\*\.\-]\)/\\\1/g' <<< "$1"
|
|
|
|
}
|
|
|
|
|
2020-04-17 08:40:51 +02:00
|
|
|
# Checks if the output scripts will be minified.
|
|
|
|
# Arguments:
|
|
|
|
# 1 "all" -- All scripts will be minified.
|
|
|
|
# "any" -- Any scripts will be minified.
|
|
|
|
# "lib" -- Library scripts will be minified.
|
|
|
|
# "unsafe" -- Unsafe minifications will be applied.
|
|
|
|
will_minify() {
|
|
|
|
case "$1" in
|
|
|
|
all)
|
|
|
|
[[ "$OPT_MINIFY" =~ ^all($|\+.*) ]]
|
|
|
|
return $? ;;
|
|
|
|
unsafe)
|
|
|
|
[[ "$OPT_MINIFY" =~ ^.*+unsafe(\+.*)*$ ]]
|
|
|
|
return $? ;;
|
|
|
|
lib)
|
|
|
|
[[ "$OPT_MINIFY" =~ ^lib($|\+.*) ]]
|
|
|
|
return $? ;;
|
|
|
|
any|"")
|
|
|
|
[[ "$OPT_MINIFY" != "none" ]]
|
|
|
|
return $? ;;
|
|
|
|
esac
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Generates the banner for the output files.
|
|
|
|
#
|
|
|
|
# Output:
|
|
|
|
# The contents of banner.txt
|
|
|
|
generate_banner() {
|
|
|
|
local step="$1"
|
|
|
|
if ! "$OPT_BANNER"; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Don't run it unless the comments are removed or hidden.
|
|
|
|
if ! { will_minify all || "$OPT_COMPRESS"; }; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Only run it in the compression step if both minifying and compressing.
|
|
|
|
if will_minify all && "$OPT_COMPRESS" && [[ "$step" != "step_compress" ]]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Write the banner.
|
|
|
|
bat "${HERE}/banner.txt"
|
|
|
|
}
|
|
|
|
|
2019-06-19 23:15:10 +02:00
|
|
|
# Build step: read
|
|
|
|
# Reads the file from its source.
|
|
|
|
#
|
|
|
|
# Arguments:
|
|
|
|
# 1 -- The source file.
|
|
|
|
#
|
|
|
|
# Output:
|
|
|
|
# The file contents.
|
|
|
|
step_read() {
|
|
|
|
cat "$1"
|
2019-10-27 08:14:55 +01:00
|
|
|
smsg "Reading"
|
2019-06-19 23:15:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Build step: preprocess
|
|
|
|
# Preprocesses the script.
|
|
|
|
#
|
2020-04-08 11:55:44 +02:00
|
|
|
# This will embed library scripts and inline constants.
|
2019-06-19 23:15:10 +02:00
|
|
|
#
|
|
|
|
# Input:
|
|
|
|
# The original file contents.
|
2020-03-31 23:51:00 +02:00
|
|
|
#
|
2019-06-19 23:15:10 +02:00
|
|
|
# Output:
|
|
|
|
# The processed file contents.
|
|
|
|
step_preprocess() {
|
|
|
|
local line
|
2020-04-01 21:47:21 +02:00
|
|
|
local docvar
|
2020-04-08 11:55:44 +02:00
|
|
|
pp_consolidate | while IFS='' read -r line; do
|
2019-06-19 23:15:10 +02:00
|
|
|
# Skip certain lines.
|
|
|
|
[[ "$line" =~ ^LIB=.*$ ]] && continue
|
2020-04-08 11:55:44 +02:00
|
|
|
[[ "$line" =~ ^[[:space:]]*source[[:space:]]+[\"\']\$\{?LIB\}/(constants\.sh)[\"\'] ]] && continue
|
2019-06-19 23:15:10 +02:00
|
|
|
|
|
|
|
# Forward data.
|
|
|
|
echo "$line"
|
2020-04-08 11:55:44 +02:00
|
|
|
done | pp_inline_constants
|
2020-03-31 23:51:00 +02:00
|
|
|
|
2019-10-27 08:14:55 +01:00
|
|
|
smsg "Preprocessing"
|
2019-06-19 23:15:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Build step: minify
|
|
|
|
# Minifies the output script.
|
|
|
|
#
|
|
|
|
# Input:
|
|
|
|
# The original file contents.
|
|
|
|
#
|
|
|
|
# Output:
|
|
|
|
# The minified file contents.
|
|
|
|
step_minify() {
|
2020-04-17 08:40:51 +02:00
|
|
|
if ! will_minify all; then
|
2019-06-19 23:15:10 +02:00
|
|
|
cat
|
2019-10-27 08:14:55 +01:00
|
|
|
smsg "Minifying" "SKIP"
|
2019-06-19 23:15:10 +02:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
printf "#!/usr/bin/env bash\n"
|
2020-04-17 08:40:51 +02:00
|
|
|
generate_banner step_minify
|
2019-10-11 21:30:06 +02:00
|
|
|
pp_minify | pp_minify_unsafe
|
2019-10-27 08:14:55 +01:00
|
|
|
smsg "Minifying"
|
2019-06-19 23:15:10 +02:00
|
|
|
}
|
|
|
|
|
2019-10-11 22:03:47 +02:00
|
|
|
# Build step: compress
|
|
|
|
# Compresses the input into a gzipped self-executable script.
|
|
|
|
#
|
|
|
|
# Input:
|
|
|
|
# The original file contents.
|
|
|
|
#
|
|
|
|
# Output:
|
|
|
|
# The compressed self-executable script.
|
|
|
|
step_compress() {
|
|
|
|
if ! "$OPT_COMPRESS"; then
|
|
|
|
cat
|
2019-10-27 08:14:55 +01:00
|
|
|
smsg "Compressing" "SKIP"
|
2019-10-11 22:03:47 +02:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2020-04-01 02:40:55 +02:00
|
|
|
local wrapper
|
|
|
|
wrapper="$({
|
2019-10-11 22:03:47 +02:00
|
|
|
printf '#!/usr/bin/env bash\n'
|
2020-04-17 08:40:51 +02:00
|
|
|
generate_banner step_compress
|
2019-10-11 22:03:47 +02:00
|
|
|
printf "(exec -a \"\$0\" bash -c 'eval \"\$(cat <&3)\"' \"\$0\" \"\$@\" 3< <(dd bs=1 if=\"\$0\" skip=::: 2>/dev/null | gunzip)); exit \$?;\n"
|
|
|
|
})"
|
|
|
|
|
2020-04-01 21:47:21 +02:00
|
|
|
echo "${wrapper/:::/$(wc -c <<<"$wrapper" | sed 's/^[[:space:]]*//')}"
|
2019-10-11 22:03:47 +02:00
|
|
|
gzip
|
2019-10-27 08:14:55 +01:00
|
|
|
smsg "Compressing"
|
2019-10-11 22:03:47 +02:00
|
|
|
}
|
|
|
|
|
2019-06-19 23:15:10 +02:00
|
|
|
# Build step: write
|
|
|
|
# Writes the output script to a file.
|
|
|
|
#
|
|
|
|
# Arguments:
|
|
|
|
# 1 -- The file to write to.
|
|
|
|
#
|
|
|
|
# Input:
|
|
|
|
# The file contents.
|
|
|
|
#
|
|
|
|
# Output:
|
|
|
|
# The file contents.
|
|
|
|
step_write() {
|
|
|
|
tee "$1"
|
|
|
|
chmod +x "$1"
|
2019-10-27 08:14:55 +01:00
|
|
|
smsg "Building"
|
2019-06-19 23:15:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Build step: write
|
|
|
|
# Optionally writes the output script to a file.
|
|
|
|
#
|
|
|
|
# Arguments:
|
|
|
|
# 1 -- The file to write to.
|
|
|
|
#
|
|
|
|
# Input:
|
|
|
|
# The file contents.
|
|
|
|
#
|
|
|
|
# Output:
|
|
|
|
# The file contents.
|
|
|
|
step_write_install() {
|
|
|
|
if [[ "$OPT_INSTALL" != true ]]; then
|
|
|
|
cat
|
2019-10-27 08:14:55 +01:00
|
|
|
smsg "Installing" "SKIP"
|
2019-06-19 23:15:10 +02:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
tee "$1"
|
|
|
|
chmod +x "$1"
|
2019-10-27 08:14:55 +01:00
|
|
|
smsg "Installing"
|
2019-06-19 23:15:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
2020-04-17 08:40:51 +02:00
|
|
|
# Preprocessor:
|
|
|
|
# -----------------------------------------------------------------------------
|
2019-06-19 23:15:10 +02:00
|
|
|
|
2020-04-08 11:55:44 +02:00
|
|
|
# Consolidates all scripts into a single file.
|
|
|
|
# This follows all `source "${LIB}/..."` files and embeds them into the script.
|
|
|
|
pp_consolidate() {
|
|
|
|
PP_CONSOLIDATE_PROCESSED=()
|
|
|
|
pp_consolidate__do 0
|
|
|
|
}
|
|
|
|
|
|
|
|
pp_consolidate__do() {
|
|
|
|
local depth="$1"
|
|
|
|
local indent="$(printf "%-${depth}s" | tr ' ' $'\t')"
|
|
|
|
|
|
|
|
local line
|
|
|
|
while IFS='' read -r line; do
|
|
|
|
# Embed library scripts.
|
|
|
|
if [[ "$line" =~ ^[[:space:]]*source[[:space:]]+[\"\']\$\{?LIB\}/([a-z_-]+\.sh)[\"\'] ]]; then
|
|
|
|
local script_name="${BASH_REMATCH[1]}"
|
|
|
|
local script="$LIB/$script_name"
|
|
|
|
|
|
|
|
# Skip if it's the constants library.
|
|
|
|
[[ "$script_name" = "constants.sh" ]] && continue
|
|
|
|
|
|
|
|
# Skip if it's already embedded.
|
|
|
|
local other
|
|
|
|
for other in "${PP_CONSOLIDATE_PROCESSED[@]}"; do
|
|
|
|
[[ "$script" = "$other" ]] && continue 2
|
|
|
|
done
|
|
|
|
PP_CONSOLIDATE_PROCESSED+=("$script")
|
|
|
|
|
|
|
|
# Embed the script.
|
|
|
|
echo "${indent}# --- BEGIN LIBRARY FILE: ${BASH_REMATCH[1]} ---"
|
|
|
|
{
|
2020-04-17 08:40:51 +02:00
|
|
|
if will_minify lib; then
|
2020-04-08 11:55:44 +02:00
|
|
|
pp_strip_comments | pp_minify | pp_minify_unsafe
|
|
|
|
else
|
2020-05-01 07:06:11 +02:00
|
|
|
pp_strip_copyright | pp_strip_separators
|
2020-04-08 11:55:44 +02:00
|
|
|
fi
|
|
|
|
} < <(pp_consolidate__do "$((depth + 1))" < "$script") | sed "s/^/${indent}/"
|
|
|
|
echo "${indent}# --- END LIBRARY FILE ---"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Forward data.
|
|
|
|
echo "$line"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Inlines constants:
|
2020-05-01 06:57:54 +02:00
|
|
|
# EXECUTABLE_*
|
2020-04-08 11:55:44 +02:00
|
|
|
# PROGRAM_*
|
|
|
|
pp_inline_constants() {
|
2020-05-01 06:57:54 +02:00
|
|
|
local constants=("PROGRAM")
|
2020-04-08 11:55:44 +02:00
|
|
|
|
|
|
|
# Determine the PROGRAM_ constants.
|
2020-05-01 06:57:54 +02:00
|
|
|
local nf_constants="$( ( set -o posix ; set) | grep '^\(PROGRAM_\|EXECUTABLE_\)' | cut -d'=' -f1)"
|
2020-04-08 11:55:44 +02:00
|
|
|
local line
|
|
|
|
while read -r line; do
|
|
|
|
constants+=("$line")
|
|
|
|
done <<< "$nf_constants"
|
|
|
|
|
|
|
|
# Generate a sed replace for the constants.
|
|
|
|
local constants_pattern=''
|
|
|
|
local constant_name
|
|
|
|
local constant_value
|
|
|
|
for constant_name in "${constants[@]}"; do
|
|
|
|
constant_value="$(sed_escape "${!constant_name}")"
|
|
|
|
constant_name="$(sed_escape "$constant_name")"
|
|
|
|
constant_sed="s/\\\$${constant_name}\([^A-Za-z0-9_]\)/${constant_value}\1/; s/\\\${${constant_name}}/${constant_value}/g;"
|
|
|
|
constants_pattern="${constants_pattern}${constant_sed}"
|
|
|
|
done
|
|
|
|
|
|
|
|
sed "${constants_pattern}"
|
|
|
|
}
|
|
|
|
|
2020-05-01 06:57:54 +02:00
|
|
|
|
2019-06-19 23:15:10 +02:00
|
|
|
# Strips comments from a Bash source file.
|
|
|
|
pp_strip_comments() {
|
|
|
|
sed '/^[[:space:]]*#.*$/d'
|
|
|
|
}
|
|
|
|
|
2020-05-01 07:06:11 +02:00
|
|
|
# Strips copyright comments from the start of a Bash source file.
|
|
|
|
pp_strip_copyright() {
|
|
|
|
awk '/^#/ {if(!p){ next }} { p=1; print $0 }'
|
|
|
|
}
|
|
|
|
|
|
|
|
# Strips separator comments from the start of a Bash source file.
|
|
|
|
pp_strip_separators() {
|
|
|
|
awk '/^#\s*-{5,}/ { next; } {print $0}'
|
|
|
|
}
|
|
|
|
|
2019-06-19 23:15:10 +02:00
|
|
|
# Minify a Bash source file.
|
2019-10-11 21:30:06 +02:00
|
|
|
# https://github.com/mvdan/sh
|
2019-06-19 23:15:10 +02:00
|
|
|
pp_minify() {
|
2020-04-17 08:40:51 +02:00
|
|
|
if will_minify none; then
|
2019-10-22 19:51:56 +02:00
|
|
|
cat
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2019-06-22 01:19:31 +02:00
|
|
|
shfmt -mn
|
2019-10-22 19:51:56 +02:00
|
|
|
return $?
|
2019-06-19 23:15:10 +02:00
|
|
|
}
|
|
|
|
|
2019-10-11 21:30:06 +02:00
|
|
|
# Minifies the output script (unsafely).
|
|
|
|
# Right now, this doesn't do anything.
|
|
|
|
# This should be applied after shfmt minification.
|
|
|
|
pp_minify_unsafe() {
|
2020-04-17 08:40:51 +02:00
|
|
|
if ! will_minify unsafe; then
|
2019-10-11 21:30:06 +02:00
|
|
|
cat
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat
|
|
|
|
}
|
|
|
|
|
2019-06-19 23:15:10 +02:00
|
|
|
# -----------------------------------------------------------------------------
|
2020-04-17 08:40:51 +02:00
|
|
|
# Options:
|
|
|
|
# -----------------------------------------------------------------------------
|
2019-06-19 23:15:10 +02:00
|
|
|
OPT_INSTALL=false
|
2019-10-11 22:03:47 +02:00
|
|
|
OPT_COMPRESS=false
|
2019-09-27 00:49:36 +02:00
|
|
|
OPT_VERIFY=true
|
2020-04-17 08:40:51 +02:00
|
|
|
OPT_BANNER=true
|
2019-06-19 23:15:10 +02:00
|
|
|
OPT_MINIFY="lib"
|
|
|
|
OPT_PREFIX="/usr/local"
|
2019-09-09 02:43:29 +02:00
|
|
|
OPT_BAT="bat"
|
2019-06-19 23:15:10 +02:00
|
|
|
|
2019-09-25 23:48:52 +02:00
|
|
|
DOCS_URL="https://github.com/eth-p/bat-extras/blob/master/doc"
|
|
|
|
DOCS_MAINTAINER="eth-p <eth-p@hidden.email>"
|
|
|
|
|
2019-06-19 23:15:10 +02:00
|
|
|
while shiftopt; do
|
2020-04-01 21:47:21 +02:00
|
|
|
# shellcheck disable=SC2034
|
2019-06-19 23:15:10 +02:00
|
|
|
case "$OPT" in
|
2020-04-01 21:47:21 +02:00
|
|
|
--install) OPT_INSTALL=true ;;
|
|
|
|
--compress) OPT_COMPRESS=true ;;
|
2020-04-01 21:53:17 +02:00
|
|
|
--no-verify) OPT_VERIFY=false ;;
|
2020-04-17 08:40:51 +02:00
|
|
|
--no-banner) OPT_BANNER=false ;;
|
2020-04-01 21:47:21 +02:00
|
|
|
--prefix) shiftval; OPT_PREFIX="$OPT_VAL" ;;
|
|
|
|
--alternate-executable) shiftval; OPT_BAT="$OPT_VAL" ;;
|
|
|
|
--minify) shiftval; OPT_MINIFY="$OPT_VAL" ;;
|
2020-03-31 23:51:00 +02:00
|
|
|
|
|
|
|
*)
|
|
|
|
printc "%{RED}%s: unknown option '%s'%{CLEAR}" "$PROGRAM" "$OPT"
|
|
|
|
exit 1
|
|
|
|
;;
|
2019-06-19 23:15:10 +02:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2019-09-09 02:43:29 +02:00
|
|
|
if [[ "$OPT_BAT" != "bat" ]]; then
|
|
|
|
printc "%{YELLOW}Building executable scripts with an alternate bat executable at %{CLEAR}%s%{YELLOW}.%{CLEAR}\n" "$OPT_BAT" 1>&2
|
|
|
|
if ! command -v "$OPT_BAT"; then
|
|
|
|
printc "%{YELLOW}WARNING: Bash cannot execute the specified file.\n" 1>&2
|
|
|
|
printc "%{YELLOW} The finished scripts may not run properly.%{CLEAR}\n" 1>&2
|
|
|
|
fi
|
2020-04-08 12:15:02 +02:00
|
|
|
|
|
|
|
EXECUTABLE_BAT="$OPT_BAT"
|
2019-09-09 02:43:29 +02:00
|
|
|
printc "\n" 1>&2
|
|
|
|
fi
|
|
|
|
|
2019-06-19 23:15:10 +02:00
|
|
|
if [[ "$OPT_INSTALL" = true ]]; then
|
|
|
|
printc "%{YELLOW}Installing to %{MAGENTA}%s%{YELLOW}.%{CLEAR}\n" "$OPT_PREFIX" 1>&2
|
|
|
|
else
|
|
|
|
printc "%{YELLOW}This will not install the script.%{CLEAR}\n" 1>&2
|
|
|
|
printc "%{YELLOW}Use %{BLUE}--install%{YELLOW} for a global install.%{CLEAR}\n\n" 1>&2
|
|
|
|
fi
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
2019-06-22 01:19:31 +02:00
|
|
|
# Check for resources.
|
2019-06-19 23:15:10 +02:00
|
|
|
|
|
|
|
[[ -d "$BIN" ]] || mkdir "$BIN"
|
|
|
|
|
2020-04-17 08:40:51 +02:00
|
|
|
if ! will_minify none && ! command -v shfmt &>/dev/null; then
|
2019-06-22 01:19:31 +02:00
|
|
|
printc "%{RED}Warning: cannot find shfmt. Unable to minify scripts.%{CLEAR}\n"
|
|
|
|
OPT_MINIFY=none
|
2019-06-19 23:15:10 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Find files.
|
|
|
|
|
|
|
|
SOURCES=()
|
|
|
|
|
|
|
|
printc "%{YELLOW}Preparing scripts...%{CLEAR}\n" 1>&2
|
|
|
|
for file in "$SRC"/*.sh; do
|
|
|
|
SOURCES+=("$file")
|
|
|
|
done
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Build files.
|
|
|
|
|
|
|
|
printc "%{YELLOW}Building scripts...%{CLEAR}\n" 1>&2
|
|
|
|
file_i=0
|
|
|
|
file_n="${#SOURCES[@]}"
|
|
|
|
for file in "${SOURCES[@]}"; do
|
2020-03-31 23:51:00 +02:00
|
|
|
((file_i++)) || true
|
2019-06-19 23:15:10 +02:00
|
|
|
|
|
|
|
filename="$(basename "$file" .sh)"
|
2020-04-08 11:55:44 +02:00
|
|
|
PROGRAM="$filename"
|
|
|
|
PROGRAM_VERSION="$(<"${HERE}/version.txt")"
|
2019-06-19 23:15:10 +02:00
|
|
|
|
|
|
|
printc " %{YELLOW}[%s/%s] %{MAGENTA}%s%{CLEAR}\n" "$file_i" "$file_n" "$file" 1>&2
|
2020-03-31 23:51:00 +02:00
|
|
|
step_read "$file" |
|
|
|
|
next step_preprocess |
|
|
|
|
next step_minify |
|
|
|
|
next step_compress |
|
|
|
|
next step_write "${BIN}/${filename}" |
|
|
|
|
next step_write_install "${OPT_PREFIX}/bin/${filename}" |
|
2019-06-19 23:15:10 +02:00
|
|
|
cat >/dev/null
|
|
|
|
done
|
|
|
|
|
2019-09-27 00:49:36 +02:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Verify files by running the tests.
|
|
|
|
|
|
|
|
if "$OPT_VERIFY"; then
|
|
|
|
printc "\n%{YELLOW}Verifying scripts...%{CLEAR}\n" 1>&2
|
2020-04-02 00:35:23 +02:00
|
|
|
|
|
|
|
# Run the tests.
|
|
|
|
FAIL=0
|
2020-04-06 13:55:57 +02:00
|
|
|
SKIP=0
|
2020-04-02 00:35:23 +02:00
|
|
|
while read -r action data1 data2 splat; do
|
|
|
|
[[ "$action" == "result" ]] || continue
|
|
|
|
|
|
|
|
printf "\x1B[G\x1B[K%s" "$data1" 1>&2
|
2020-04-06 13:55:57 +02:00
|
|
|
case "$data2" in
|
|
|
|
fail)
|
|
|
|
printf " failed.\n" 1>&2
|
|
|
|
((FAIL++)) || true
|
|
|
|
;;
|
|
|
|
|
|
|
|
skip)
|
|
|
|
((SKIP++)) || true
|
|
|
|
;;
|
|
|
|
esac
|
2020-04-28 03:48:27 +02:00
|
|
|
done < <("${HERE}/test.sh" --compiled --porcelain --jobs=8)
|
2020-04-02 00:35:23 +02:00
|
|
|
|
|
|
|
# Print the overall result.
|
2020-04-06 13:55:57 +02:00
|
|
|
printf "\x1B[G\x1B[K%s" 1>&2
|
|
|
|
|
2020-04-02 00:35:23 +02:00
|
|
|
if [[ "$FAIL" -ne 0 ]]; then
|
|
|
|
printc "%{RED}One or more tests failed.\n" 1>&2
|
|
|
|
printc "Run ./test.sh for more detailed information.%{CLEAR}\n" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-04-06 13:55:57 +02:00
|
|
|
if [[ "$SKIP" -gt 0 ]]; then
|
|
|
|
printc "%{CYAN}One or more tests were skipped.\n" 1>&2
|
|
|
|
printc "Run ./test.sh for more detailed information.%{CLEAR}\n" 1>&2
|
|
|
|
fi
|
|
|
|
|
|
|
|
printc "%{YELLOW}Verified successfully.%{CLEAR}\n" 1>&2
|
2019-09-27 00:49:36 +02:00
|
|
|
fi
|