aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-05-09 19:58:53 +0200
committerlonkaars <loek@pipeframe.xyz>2023-05-09 19:58:53 +0200
commit67e7e2eee2c4a09b35470711fe5ac10453841d8c (patch)
tree47c3af60cf3c7161620dc7f97a499e3af06d16b2
parent60810d7c048102825ac656e6f840afc0e2c04835 (diff)
move posix js/css minifier to scripts dir
-rw-r--r--common.mk12
-rwxr-xr-xscripts/css2min9
-rwxr-xr-xscripts/filters/remove_double_slash_comments2
-rwxr-xr-xscripts/filters/remove_slash_star_comments2
-rwxr-xr-xscripts/filters/remove_tabs2
-rwxr-xr-xscripts/filters/remove_whitespace2
-rwxr-xr-xscripts/filters/to_single_line2
-rwxr-xr-xscripts/filters/trim_whitespace2
-rwxr-xr-xscripts/js2min10
9 files changed, 35 insertions, 8 deletions
diff --git a/common.mk b/common.mk
index efbe3c4..9a3a5c3 100644
--- a/common.mk
+++ b/common.mk
@@ -1,17 +1,13 @@
M4FLAGS += -I..
-TO_SINGLE_LINE:=tr '\n' ' '
-REMOVE_DOUBLE_SLASH_COMMENTS:=sed 's/\/\/.*$$//g'
-REMOVE_SLASH_STAR_COMMENTS:=sed 's/\/\*[^\*]*\*\///g'
-REMOVE_TABS:=sed 's/\t//g'
-REMOVE_WHITESPACE:=sed 's/ */ /g'
-TRIM_WHITESPACE:=sed -E 's/^\s*(.*)\s+$$/\1/g'
+JSMIN ?= ../scripts/js2min
+CSSMIN ?= ../scripts/css2min
%.min.js: %.js
- cat $< | $(REMOVE_DOUBLE_SLASH_COMMENTS) | $(TO_SINGLE_LINE) | $(REMOVE_SLASH_STAR_COMMENTS) | $(REMOVE_TABS) | $(REMOVE_WHITESPACE) | $(TRIM_WHITESPACE) > $@
+ $(JSMIN) < $< > $@
%.min.css: %.css
- cat $< | $(TO_SINGLE_LINE) | $(REMOVE_SLASH_STAR_COMMENTS) | $(REMOVE_TABS) | $(REMOVE_WHITESPACE) | $(TRIM_WHITESPACE) > $@
+ $(CSSMIN) < $< > $@
%: %.m4
m4 $(M4FLAGS) $< > $@
diff --git a/scripts/css2min b/scripts/css2min
new file mode 100755
index 0000000..0357e41
--- /dev/null
+++ b/scripts/css2min
@@ -0,0 +1,9 @@
+#!/bin/sh
+export PATH="$PATH:`dirname $0`/filters"
+cat $@ |\
+ to_single_line |\
+ remove_slash_star_comments |\
+ remove_tabs |\
+ remove_whitespace |\
+ trim_whitespace
+
diff --git a/scripts/filters/remove_double_slash_comments b/scripts/filters/remove_double_slash_comments
new file mode 100755
index 0000000..97e5e91
--- /dev/null
+++ b/scripts/filters/remove_double_slash_comments
@@ -0,0 +1,2 @@
+#!/bin/sh
+sed 's/\/\/.*$//g'
diff --git a/scripts/filters/remove_slash_star_comments b/scripts/filters/remove_slash_star_comments
new file mode 100755
index 0000000..6203b6a
--- /dev/null
+++ b/scripts/filters/remove_slash_star_comments
@@ -0,0 +1,2 @@
+#!/bin/sh
+sed -r ':a; s%(.*)/\*.*\*/%\1%; ta; /\/\*/ !b; N; ba'
diff --git a/scripts/filters/remove_tabs b/scripts/filters/remove_tabs
new file mode 100755
index 0000000..ffa9bf9
--- /dev/null
+++ b/scripts/filters/remove_tabs
@@ -0,0 +1,2 @@
+#!/bin/sh
+sed 's/\t//g'
diff --git a/scripts/filters/remove_whitespace b/scripts/filters/remove_whitespace
new file mode 100755
index 0000000..d453fea
--- /dev/null
+++ b/scripts/filters/remove_whitespace
@@ -0,0 +1,2 @@
+#!/bin/sh
+sed 's/ */ /g'
diff --git a/scripts/filters/to_single_line b/scripts/filters/to_single_line
new file mode 100755
index 0000000..3b20f24
--- /dev/null
+++ b/scripts/filters/to_single_line
@@ -0,0 +1,2 @@
+#!/bin/sh
+tr '\n' ' '
diff --git a/scripts/filters/trim_whitespace b/scripts/filters/trim_whitespace
new file mode 100755
index 0000000..8663abc
--- /dev/null
+++ b/scripts/filters/trim_whitespace
@@ -0,0 +1,2 @@
+#!/bin/sh
+sed -E 's/^\s*(.*)\s+$/\1/g'
diff --git a/scripts/js2min b/scripts/js2min
new file mode 100755
index 0000000..bd14e81
--- /dev/null
+++ b/scripts/js2min
@@ -0,0 +1,10 @@
+#!/bin/sh
+export PATH="$PATH:`dirname $0`/filters"
+cat $@ |\
+ remove_double_slash_comments |\
+ to_single_line |\
+ remove_slash_star_comments |\
+ remove_tabs |\
+ remove_whitespace |\
+ trim_whitespace
+