From 2a8de58809f12f0e125dfb08160d39cd03bb18df Mon Sep 17 00:00:00 2001 From: Ethan P Date: Fri, 11 Oct 2019 12:30:06 -0700 Subject: [PATCH] Add unimplemented extra minification --- build.sh | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index 51a108e..459adf7 100755 --- a/build.sh +++ b/build.sh @@ -88,7 +88,7 @@ step_preprocess() { echo "# --- BEGIN LIBRARY FILE: ${BASH_REMATCH[1]} ---" cat "$LIB/${BASH_REMATCH[1]}" | { if [[ "$OPT_MINIFY" = "lib" ]]; then - pp_strip_comments | pp_minify + pp_strip_comments | pp_minify | pp_minify_unsafe else cat fi @@ -111,7 +111,7 @@ step_preprocess() { # Output: # The minified file contents. step_minify() { - if [[ "$OPT_MINIFY" != "all" ]]; then + if [[ "$OPT_MINIFY" =~ ^all($|+.*) ]]; then smsg "Minifying" "SKIP" cat return 0 @@ -119,7 +119,7 @@ step_minify() { smsg "Minifying" printf "#!/usr/bin/env bash\n" - pp_minify + pp_minify | pp_minify_unsafe } # Build step: write @@ -172,11 +172,24 @@ pp_strip_comments() { } # Minify a Bash source file. -# https://github.com/precious/bash_minifier +# https://github.com/mvdan/sh pp_minify() { shfmt -mn } + +# Minifies the output script (unsafely). +# Right now, this doesn't do anything. +# This should be applied after shfmt minification. +pp_minify_unsafe() { + if ! [[ "$OPT_MINIFY" =~ ^.*+unsafe(+.*)*$ ]]; then + cat + return 0 + fi + + cat +} + # ----------------------------------------------------------------------------- # Options. OPT_INSTALL=false