Skip to content

Instantly share code, notes, and snippets.

@luggage66
Forked from ssube/Makefile
Created September 8, 2017 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luggage66/7012d90eae8aa112825e6f07c17f18a0 to your computer and use it in GitHub Desktop.
Save luggage66/7012d90eae8aa112825e6f07c17f18a0 to your computer and use it in GitHub Desktop.
webpack makefile
# Git
GIT_REF = $(shell git rev-parse --abbrev-ref HEAD)
GIT_REV = $(shell git rev-parse HEAD)
# CI
CI_COMMIT_REF_SLUG ?= $(GIT_REF)
CI_ENVIRONMENT_SLUG ?= local
CI_RUNNER_DESCRIPTION ?= $(shell hostname)
# Debug
DEBUG_BIND ?= 127.0.0.1
DEBUG_PORT ?= 9229
# Paths
CONFIG_PATH ?= ./config
SCRIPT_PATH ?= ./scripts
TARGET_PATH ?= ./target
TARGET_MAIN ?= $(TARGET_PATH)/main-bundle.js
# Node options
NODE_BIN := ./node_modules/.bin
NODE_DBG ?= --inspect-brk=$(DEBUG_BIND):$(DEBUG_PORT) --nolazy
# Tool options
BUNDLE_OPTS ?= --config "config/webpack.js" --display-optimization-bailout --display-error-details
COVER_CHECK ?= --check-coverage --branches 70 --functions 75 --lines 80 --statements 80 # increase this every so often
COVER_OPTS ?= --reporter=text-summary --reporter=html --report-dir="target/coverage"
DOCS_OPTS ?= --exclude "test.+" --tsconfig "config/tsconfig.json" --out "$(TARGET_PATH)/docs"
MOCHA_MULTI ?= --reporter mocha-multi --reporter-options json="$(TARGET_PATH)/mocha.json",spec
MOCHA_OPTS ?= --check-leaks --colors --sort --ui bdd
all: configure version bundle test docs ## builds, bundles, and tests the application
@echo Success! make run-terminal to launch
strict: configure version bundle-check test-check docs ## builds, bundles, and tests the application with type checks and extra warnings (slow)
@echo Success! make run-terminal to launch
# from https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help: ## print this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort \
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
bundle: bundle-cover ## build the distributable version of the application
bundle-check: ## bundle the application with full type checking (stricter)
TEST_CHECK=true $(NODE_BIN)/webpack $(BUNDLE_OPTS)
bundle-cover: ## bundle the application without type checking (faster)
TEST_CHECK=false $(NODE_BIN)/webpack $(BUNDLE_OPTS)
bundle-stats: ## bundle the application and emit statistics
TEST_CHECK=false $(NODE_BIN)/webpack $(BUNDLE_OPTS) --json --profile > "$(TARGET_PATH)/webpack.json"
bundle-watch: ## bundle the application and watch for changes
TEST_CHECK=false $(NODE_BIN)/webpack $(BUNDLE_OPTS) --watch
clean: ## clean up the target directory
rm -rf $(TARGET_PATH)
configure: ## create the target directory and other files not in git
mkdir -p $(TARGET_PATH)
docs: ## generate html docs
$(NODE_BIN)/typedoc $(DOCS_OPTS)
push: ## push to both gitlab and github (this assumes you have both remotes set up)
git push gitlab
git push github
test: test-cover ## run mocha unit tests
test-check: ## run mocha unit tests with type checks and coverage checks
$(NODE_BIN)/nyc $(COVER_OPTS) $(COVER_CHECK) $(NODE_BIN)/mocha $(MOCHA_OPTS) target/test-bundle.js
test-cover: ## run mocha unit tests with coverage reports
$(NODE_BIN)/nyc $(COVER_OPTS) $(NODE_BIN)/mocha $(MOCHA_OPTS) target/test-bundle.js
todo:
@echo "Remaining tasks:"
@echo ""
@grep "todo" -r src/
@echo ""
@echo "Pending tests:"
@echo ""
@grep "[[:space:]]xit" -r src/test/
update: ## check yarn for outdated packages
yarn outdated
version: ## print the friendly version
$(SCRIPT_PATH)/friendly-version.js \
--branch "$(GIT_REF)" --commit "$(GIT_REV)" \
--friendly "$(CONFIG_PATH)/friendly-version.yml" --package "./package.json" > $(TARGET_PATH)/version.json
# debug logs and reporting
search-log: ## pretty print warn/error and messages containing the SEARCH string (requires jq)
cat reference.log | jq -c '. | select((.level > 30) or (.msg | contains("${SEARCH}")))' \
| $(NODE_BIN)/bunyan --pager -o short
tail-log: ## tail and pretty print the reference log file
tail -f reference.log | $(NODE_BIN)/bunyan
view-log: ## pretty print the reference log file
cat reference.log | $(NODE_BIN)/bunyan --pager -o short
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment