Last active
December 16, 2021 06:33
-
-
Save haliphax/3315112 to your computer and use it in GitHub Desktop.
WordPress plugin reducisaurus Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# WordPress plugin reducisaurus Makefile | |
# Author: haliphax <https://haliphax.dev> | |
# current directory - used when zipping | |
CWD := $(shell pwd) | |
# get project base name from directory name | |
PROJ := $(word $(words $(subst /, ,$(CWD))), $(subst /, ,$(CWD))) | |
# pull version from main project file | |
VER := $(shell egrep "^Version:" $(PROJ).php | cut -d" " -f2) | |
# css minification | |
CSS_URL = http://reducisaurus.appspot.com/css | |
CSS_FILES = $(filter-out %.min.css, $(wildcard css/*.css)) | |
CSS_MINI = $(CSS_FILES:.css=.min.css) | |
# uses php to urlencode the files | |
CSS_ENC = $(shell php -r "echo urlencode(file_get_contents('$<'));") | |
# javascript minification | |
JS_URL = http://reducisaurus.appspot.com/js | |
JS_FILES = $(filter-out %.min.js, $(wildcard js/*.js)) | |
JS_MINI = $(JS_FILES:.js=.min.js) | |
# uses php to urlencode the files | |
JS_ENC = $(shell php -r "echo urlencode(file_get_contents('$<'));") | |
# target: minify - Minify Javascript and CSS files | |
minify: js css | |
# target: js - minify Javascript files | |
js: $(JS_FILES) $(JS_MINI) | |
# target: css - minify CSS files | |
css: $(CSS_FILES) $(CSS_MINI) | |
# recipe: build minified stylesheets | |
%.min.css: %.css | |
@echo "==> Minifying stylesheet: $<" | |
$(shell curl -sd "file=$(CSS_ENC)" $(CSS_URL) -o $@) | |
# recipe: build minified scripts | |
%.min.js: %.js | |
@echo "==> Minifying script: $<" | |
$(shell curl -sd "file=$(JS_ENC)" $(JS_URL) -o $@) | |
# target: zip - Build *.zip archive of project | |
zip: | |
@echo "==> Creating $(PROJ).$(VER).zip" | |
$(shell \ | |
cd $(CWD)/.. ; \ | |
zip -qr $(CWD)/$(PROJ).$(VER).zip $(PROJ)/* -i \*.php \*.js \*.css ; \ | |
cd $(CWD) \ | |
) | |
# target: all - Run all scenarios | |
all: minify zip | |
# target: clean - Removes *.zip file and minified Javascript files | |
clean: | |
@echo "==> Cleaning project" | |
$(shell rm -f $(JS_MINI) $(CSS_MINI) $(PROJ).*.zip) | |
# target: help - Displays help | |
help: | |
@egrep "^# target:" Makefile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment