diff options
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 116 |
1 files changed, 81 insertions, 35 deletions
@@ -2,45 +2,69 @@ include .default.env include .env export +build_dir := build + +# Misc variables. PATH := vendor/bin:node_modules/.bin:$(PATH) override GIT_VERSION := $(shell git --no-pager describe --always --tags) override CUR_VERSION := $(strip $(shell cat VERSION 2>/dev/null)) -PREV_ENV_FILE := /tmp/wcms_prev_env -PREV_ENV=$(strip $(shell cat $(PREV_ENV_FILE) 2>/dev/null)) - -js_sources := $(wildcard src/*.js) -js_bundles := $(js_sources:src/%.js=assets/js/%.bundle.js) -js_srcmaps := $(js_sources:src/%.js=assets/js/%.bundle.js.map) +override WEBPACK_FLAGS += $(if $(filter $(ENV),dist),-p) +override COMPOSER_FLAGS += $(if $(filter $(ENV),dist),--no-dev --prefer-dist) +PREV_ENV_FILE := $(build_dir)/prev_env +PREV_ENV := $(strip $(shell cat $(PREV_ENV_FILE) 2>/dev/null)) + +# Files variables. +js_src_dir := src +js_sources := $(wildcard $(js_src_dir)/*.js) +js_bundles := $(js_sources:$(js_src_dir)/%.js=assets/js/%.bundle.js) +js_srcmaps := $(js_sources:$(js_src_dir)/%.js=assets/js/%.bundle.js.map) zip_release := dist/w_cms_$(GIT_VERSION).zip -all: vendor build +# Default target. This executes everything targets needed to get a fully +# working development environment. +.PHONY: all +all: $(PREV_ENV_FILE) vendor build +# Build generated files. +.PHONY: build build: VERSION $(PREV_ENV_FILE) $(js_bundles) +# Run webpack in watch mode. +.PHONY: watch watch: node_modules webpack --env dev --watch +# Create a new release and upload it on GitHub. +.PHONY: release release: node_modules release-it +# Inform Sentry of a new release. +.PHONY: sentryrelease +sentryrelease: ENV := dist sentryrelease: - $(MAKE) .sentryrelease ENV=prod + $(MAKE) .sentryrelease ENV=$(ENV) -.sentryrelease: build +.PHONY: .sentryrelease +.sentryrelease: $(PREV_ENV_FILE) build $(js_srcmaps) sentry-cli releases new $(GIT_VERSION) sentry-cli releases set-commits $(GIT_VERSION) --auto sentry-cli releases files $(GIT_VERSION) upload-sourcemaps assets/js --url-prefix '~/assets/js' --rewrite sentry-cli releases finalize $(GIT_VERSION) +# Generate the distribution files. +.PHONY: dist +dist: ENV := dist dist: - $(MAKE) .dist ENV=prod + $(MAKE) .dist ENV=$(ENV) +.PHONY: .dist .dist: distclean $(zip_release) $(js_srcmaps) dist/w_cms_%.zip: all - @echo "Building Zip release..." + @echo Building Zip release... mkdir -p $(dir $@) -# Include git tracked files (everything except ignored) + needed files +# Include git tracked files (everything except ignored) + needed files. zip -r $@ \ $(shell git ls-tree -r HEAD --name-only) \ VERSION \ @@ -48,11 +72,11 @@ dist/w_cms_%.zip: all vendor \ -x "*test*" \ -x "*docs*" -# Include non-empty git tracked directories (to keep dir permissions) +# Include non-empty git tracked directories (to keep dir permissions). zip $@ $(shell git ls-tree -r HEAD --name-only -d) -# Remove non-useful files +# Remove non-useful files. zip -d $@ \ - $(js_sources) \ + "$(js_src_dir)/*" \ $(js_srcmaps) \ .default.env \ .gitignore \ @@ -62,52 +86,74 @@ dist/w_cms_%.zip: all "package*" \ webpack.config.js -assets/js/%.bundle.js assets/js/%.bundle.js.map: src/%.js node_modules - @echo "Building JS Bundles..." +# Generate the js bundles (and sourcemaps). +assets/js/%.bundle.js assets/js/%.bundle.js.map: $(js_src_dir)/%.js node_modules + @echo Building JS Bundles... mkdir -p $(dir $@) - webpack $< -o $@ $(if $(filter $(ENV),prod),--env prod -p,--env dev) + webpack $< -o $@ --env $(ENV) $(WEBPACK_FLAGS) +# Generate a .env file if none is present. .env: - cp .default.env .env + cp .default.env $@ -# use a force (fake) target to always rebuild this file but have Make -# consider this updated if it was actually rewritten (a .PHONY target -# is always considered new) +# Generate the VERSION file. VERSION: .FORCE ifneq ($(CUR_VERSION),$(GIT_VERSION)) - @echo $(GIT_VERSION) > $@ + echo $(GIT_VERSION) > $@ endif -$(PREV_ENV_FILE): .FORCE +# Trick to force rebuild if the build environment has changed. ifneq ($(PREV_ENV),$(ENV)) +$(PREV_ENV_FILE): touch +ifdef PREV_ENV @echo Build env has changed ! - $(MAKE) buildclean - @echo $(ENV) > $@ +else + @echo New build env. +endif + mkdir -p $(dir $@) + echo $(ENV) > $@ endif +# Install PHP dependencies. vendor: composer.json composer.lock - @echo "Installing PHP dependencies..." - composer install $(if $(filter $(ENV),prod),--no-dev --prefer-dist,) + @echo Installing PHP dependencies... + composer install $(COMPOSER_FLAGS) +# Install JS dependencies. node_modules: package.json package-lock.json - @echo "Installing JS dependencies..." + @echo Installing JS dependencies... npm install --loglevel=error +# Clean files generated by `make all`. +.PHONY: clean clean: buildclean - @echo "Cleaning make artifacts..." + @echo Cleaning make artifacts... rm -rf vendor rm -rf node_modules rm -rf VERSION +# Clean files generated by `make dist`. +.PHONY: distclean distclean: - @echo "Cleaning dist artifacts..." + @echo Cleaning dist artifacts... rm -rf dist +# Clean files generated by `make build`. +.PHONY: buildclean buildclean: - @echo "Cleaning build artifacts..." + @echo Cleaning build artifacts... rm -rf $(js_bundles) rm -rf $(js_srcmaps) - + rm -rf $(build_dir) + +# Touch files affected by the build environment to force the execution +# of the corresponding targets. +.PHONY: touch +touch: + touch $(js_sources) + touch composer.json + +# Special (fake) target to always run a target but have Make consider +# this updated if it was actually rewritten (a .PHONY target is always +# considered new). .FORCE: ; - -.PHONY: all build watch release sentryrelease .sentryrelease dist .dist clean distclean buildclean |