martin-damien
3/8/2016 - 2:17 PM

My makefile for Symfony projects

My makefile for Symfony projects

.PHONY: help build build-css build-js clear watch install-dependencies download-dependencies populate-static deploy-static init
.DEFAULT_GOAL := help

#############
# VARIABLES #
#############

WD := ${shell pwd}
RUNNABLE := "${WD}/node_modules/.bin/"

########
# HELP #
########

help:
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

################
# DEPENDENCIES #
################

install-wkhtml64: ## Install wkhtml 64bits on the host (LINUX ONLY!!!)
	@sudo cp bin/wkhtml/wkhtmltopdf_amd64 /usr/bin/wkhtmltopdf

install-wkhtml32: ## Install wkhtml 64bits on the host (LINUX ONLY!!!)
	@sudo cp bin/wkhtml/wkhtmltopdf_x86 /usr/bin/wkhtmltopdf

install-dependencies: ## Install dependencies using 'npm' and 'composer'
	npm install
	composer global require vinkla/climb

download-libraries: ## Download CSS/JS librairies using 'bower'
	@echo "Download libraries using Bower..."
	@${RUNNABLE}bower install

populate-static: ## Copy the files (grabbed by download-libraries) into the 'static/dist' folder
	@echo "Copy files from Bower's distribution to static..."
	@mkdir static/dist/css static/dist/js static/dist/fonts 2>/dev/null; true

	# Bootstrap (without fonts)
	@cp bower_components/bootstrap/dist/css/bootstrap.min.css static/dist/css
	@cp bower_components/bootstrap/dist/js/bootstrap.min.js static/dist/js
	@cp bower_components/bootstrap/dist/fonts/* static/dist/fonts

	# jQuery
	@cp bower_components/jquery/dist/jquery.min.js static/dist/js/000-jquery.min.js

	# Font Awesome
	@cp bower_components/fontawesome/css/font-awesome.min.css static/dist/css
	@cp bower_components/fontawesome/fonts/* static/dist/fonts

	# DateTimePicker
	@cp bower_components/moment/min/moment-with-locales.min.js static/dist/js/010-moment.js
	@cp bower_components/moment-timezone/builds/moment-timezone-with-data-2010-2020.min.js static/dist/js/011-moment-tz.js
	@cp bower_components/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css static/dist/css
	@cp bower_components/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js static/dist/js/012-datetimepicker.js

	# Calendar
	@cp bower_components/fullcalendar/dist/fullcalendar.min.css static/dist/css
	@cp bower_components/fullcalendar/dist/fullcalendar.min.js static/dist/js
	@cp -R bower_components/fullcalendar/dist/lang static/dist/js

	# CookieBar
	@cp bower_components/jquery.cookieBar/jquery.cookieBar.min.js static/dist/js

deploy-static: ## Deploy the static files into 'web'
	@echo "Create folders in web and link content in them..."
	@mkdir web/css web/js							2>/dev/null; true
	@ln -s ${WD}/static/build/app.all.css ${WD}/web/css/app.css	2>/dev/null; true
	@ln -s ${WD}/static/build/app.all.js ${WD}/web/js/app.js	2>/dev/null; true
	@ln -s ${WD}/static/dist/js/lang ${WD}/web/js/lang			2>/dev/null; true
	@ln -s ${WD}/static/dist/fonts ${WD}/web/				2>/dev/null; true
	@ln -s ${WD}/static/src/images ${WD}/web/				2>/dev/null; true

##################
# BUILDING FILES #
##################

build: build-css build-js ## Build CSS and JS

build-css:
	@echo "Build CSS from LESS..."
	@${RUNNABLE}lessc static/src/less/main.less | ${RUNNABLE}cleancss > static/build/app.css
	@cat static/dist/css/*.css static/build/app.css > static/build/app.all.css

build-js:
	@echo "Build JS"
	@cat static/src/js/*.js | ${RUNNABLE}uglifyjs > static/build/app.js
	@cat static/dist/js/*.js static/build/app.js > static/build/app.all.js

######################
# INITIALIZE PROJECT #
######################

init: clean download-libraries populate-static build deploy-static ## Initialize project running al necessary make commands

###########
# CLEANUP #
###########

clean: ## Cleanup dist and web folders
	@rm -Rf ${WD}/static/dist/*
	@rm -Rf ${WD}/web/css ${WD}/web/js ${WD}/web/fonts ${WD}/web/images

#######################
# WATCH MODIFICATIONS #
#######################

watch: build ## Automatically run 'make build' when files are modified in 'static/src'
	@echo "Looking for changes on LESS and JS files..."
	@${RUNNABLE}onchange "static/src/less/**/*.less" "static/src/js/**/*.js" -- make build

###############
# MAINTENANCE #
###############

check-dependencies: ## Verifiy dependencies using 'climb'
	@climb 2>/dev/null; true