Browse Source

Submakefile

Volodymyr Tkach 2 years ago
parent
commit
99fc01dbb0
3 changed files with 35 additions and 2 deletions
  1. 1 0
      Makefile
  2. 28 0
      assets.makefile
  3. 6 2
      assets.sh

+ 1 - 0
Makefile

@@ -0,0 +1 @@
+include assets.makefile

+ 28 - 0
assets.makefile

@@ -0,0 +1,28 @@
+# .assets.makefile:
+#	curl -fsSL -o $@ https://raw.githubusercontent.com/vladimirok5959/assets/main/assets.makefile
+# include .assets.makefile
+
+.PHONY: assets
+
+CHECK_YUI_COMPRESSOR := $(shell command -v yui-compressor 2> /dev/null)
+CURRENT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
+FILES_CSS := $(shell find ${CURRENT_DIR} -type f -name '*.dev.css')
+FILES_JS := $(shell find ${CURRENT_DIR} -type f -name '*.dev.js')
+
+--check-yui-compressor:
+ifndef CHECK_YUI_COMPRESSOR
+	# sudo apt-get install yui-compressor
+    $(error "yui-compressor is not installed")
+endif
+
+--assets-css: --check-yui-compressor
+	@for file in ${FILES_CSS}; do \
+		${CURRENT_DIR}/assets.sh $${file}; \
+	done
+
+--assets-js: --check-yui-compressor
+	@for file in ${FILES_JS}; do \
+		${CURRENT_DIR}/assets.sh $${file}; \
+	done
+
+assets: --assets-css --assets-js

+ 6 - 2
assets.sh

@@ -11,8 +11,12 @@ fi
 
 # Check if target file is set
 if [[ "${TARGET_FILE}" = "" ]]; then
-    echo "Target file is not set"
-    exit 1
+    # Try to generate from source file name
+    TARGET_FILE=$(echo "${SOURCE_FILE}" | sed 's/\.dev\.\(css\|js\)$/.\1/')
+    if [[ "${TARGET_FILE}" = "" ]]; then
+        echo "Target file is not set"
+        exit 1
+    fi
 fi
 
 # Check if source file exists