Add make help target (#19)

* Add make help target

* Move documentation to previous line
This commit is contained in:
Hanzei 2018-11-08 22:30:58 +01:00 committed by Joram Wilander
parent 8bbec359c7
commit b303e8da00

View file

@ -10,14 +10,15 @@ include build/setup.mk
BUNDLE_NAME ?= $(PLUGIN_ID)-$(PLUGIN_VERSION).tar.gz BUNDLE_NAME ?= $(PLUGIN_ID)-$(PLUGIN_VERSION).tar.gz
# all, the default target, tests, builds and bundles the plugin. ## Checks the code style, tests, builds and bundles the plugin.
all: check-style test dist all: check-style test dist
# apply propagates the plugin id into the server/ and webapp/ folders as required. ## Propagates plugin manifest information into the server/ and webapp/ folders as required.
.PHONY: apply .PHONY: apply
apply: apply:
./build/bin/manifest apply ./build/bin/manifest apply
## Runs govet and gofmt against all packages.
.PHONY: check-style .PHONY: check-style
check-style: server/.depensure webapp/.npminstall gofmt govet check-style: server/.depensure webapp/.npminstall gofmt govet
@echo Checking for style guide compliance @echo Checking for style guide compliance
@ -26,6 +27,7 @@ ifneq ($(HAS_WEBAPP),)
cd webapp && npm run lint cd webapp && npm run lint
endif endif
## Runs gofmt against all packages.
.PHONY: gofmt .PHONY: gofmt
gofmt: gofmt:
ifneq ($(HAS_SERVER),) ifneq ($(HAS_SERVER),)
@ -45,6 +47,7 @@ ifneq ($(HAS_SERVER),)
@echo Gofmt success @echo Gofmt success
endif endif
## Runs govet against all packages.
.PHONY: govet .PHONY: govet
govet: govet:
ifneq ($(HAS_SERVER),) ifneq ($(HAS_SERVER),)
@ -53,14 +56,14 @@ ifneq ($(HAS_SERVER),)
@echo Govet success @echo Govet success
endif endif
# server/.depensure ensures the server dependencies are installed ## Ensures the server dependencies are installed.
server/.depensure: server/.depensure:
ifneq ($(HAS_SERVER),) ifneq ($(HAS_SERVER),)
cd server && $(DEP) ensure cd server && $(DEP) ensure
touch $@ touch $@
endif endif
# server builds the server, if it exists, including support for multiple architectures ## Builds the server, if it exists, including support for multiple architectures.
.PHONY: server .PHONY: server
server: server/.depensure server: server/.depensure
ifneq ($(HAS_SERVER),) ifneq ($(HAS_SERVER),)
@ -70,21 +73,21 @@ ifneq ($(HAS_SERVER),)
cd server && env GOOS=windows GOARCH=amd64 $(GO) build -o dist/plugin-windows-amd64.exe; cd server && env GOOS=windows GOARCH=amd64 $(GO) build -o dist/plugin-windows-amd64.exe;
endif endif
# webapp/.npminstall ensures NPM dependencies are installed without having to run this all the time ## Ensures NPM dependencies are installed without having to run this all the time.
webapp/.npminstall: webapp/.npminstall:
ifneq ($(HAS_WEBAPP),) ifneq ($(HAS_WEBAPP),)
cd webapp && $(NPM) install cd webapp && $(NPM) install
touch $@ touch $@
endif endif
# webapp builds the webapp, if it exists ## Builds the webapp, if it exists.
.PHONY: webapp .PHONY: webapp
webapp: webapp/.npminstall webapp: webapp/.npminstall
ifneq ($(HAS_WEBAPP),) ifneq ($(HAS_WEBAPP),)
cd webapp && $(NPM) run build; cd webapp && $(NPM) run build;
endif endif
# bundle generates a tar bundle of the plugin for install ## Generates a tar bundle of the plugin for install.
.PHONY: bundle .PHONY: bundle
bundle: bundle:
rm -rf dist/ rm -rf dist/
@ -102,17 +105,15 @@ endif
@echo plugin built at: dist/$(BUNDLE_NAME) @echo plugin built at: dist/$(BUNDLE_NAME)
# dist builds and bundles the plugin ## Builds and bundles the plugin.
.PHONY: dist .PHONY: dist
dist: apply \ dist: apply server webapp bundle
server \
webapp \
bundle
# deploy installs the plugin to a (development) server, using the API if appropriate environment ## Installs the plugin to a (development) server.
# variables are defined, or copying the files directly to a sibling mattermost-server directory
.PHONY: deploy .PHONY: deploy
deploy: dist deploy: dist
## It uses the API if appropriate environment variables are defined,
## or copying the files directly to a sibling mattermost-server directory.
ifneq ($(and $(MM_SERVICESETTINGS_SITEURL),$(MM_ADMIN_USERNAME),$(MM_ADMIN_PASSWORD),$(HTTP)),) ifneq ($(and $(MM_SERVICESETTINGS_SITEURL),$(MM_ADMIN_USERNAME),$(MM_ADMIN_PASSWORD),$(HTTP)),)
@echo "Installing plugin via API" @echo "Installing plugin via API"
(TOKEN=`http --print h POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/users/login login_id=$(MM_ADMIN_USERNAME) password=$(MM_ADMIN_PASSWORD) | grep Token | cut -f2 -d' '` && \ (TOKEN=`http --print h POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/users/login login_id=$(MM_ADMIN_USERNAME) password=$(MM_ADMIN_PASSWORD) | grep Token | cut -f2 -d' '` && \
@ -137,7 +138,7 @@ else
@echo "No supported deployment method available. Install plugin manually." @echo "No supported deployment method available. Install plugin manually."
endif endif
# test runs any lints and unit tests defined for the server and webapp, if they exist ## Runs any lints and unit tests defined for the server and webapp, if they exist.
.PHONY: test .PHONY: test
test: server/.depensure webapp/.npminstall test: server/.depensure webapp/.npminstall
ifneq ($(HAS_SERVER),) ifneq ($(HAS_SERVER),)
@ -147,7 +148,7 @@ ifneq ($(HAS_WEBAPP),)
cd webapp && $(NPM) run fix; cd webapp && $(NPM) run fix;
endif endif
# clean removes all build artifacts ## Clean removes all build artifacts.
.PHONY: clean .PHONY: clean
clean: clean:
rm -fr dist/ rm -fr dist/
@ -161,3 +162,7 @@ ifneq ($(HAS_WEBAPP),)
rm -fr webapp/node_modules rm -fr webapp/node_modules
endif endif
rm -fr build/bin/ rm -fr build/bin/
# Help documentatin à la https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help:
@cat Makefile | grep -v '\.PHONY' | grep -v '\help:' | grep -B1 -E '^[a-zA-Z_.-]+:.*' | sed -e "s/:.*//" | sed -e "s/^## //" | grep -v '\-\-' | tac | awk 'NR%2{printf "\033[36m%-30s\033[0m",$$0;next;}1' | sort