Skip to content

Commit

Permalink
Adding empty server part
Browse files Browse the repository at this point in the history
  • Loading branch information
jespino committed Apr 4, 2019
1 parent d36d4f3 commit d469528
Show file tree
Hide file tree
Showing 12 changed files with 639 additions and 33 deletions.
75 changes: 44 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
GO ?= $(shell command -v go 2> /dev/null)
DEP ?= $(shell command -v dep 2> /dev/null)
NPM ?= $(shell command -v npm 2> /dev/null)
HTTP ?= $(shell command -v http 2> /dev/null)
CURL ?= $(shell command -v curl 2> /dev/null)
MANIFEST_FILE ?= plugin.json

# You can include assets this directory into the bundle. This can be e.g. used to include profile pictures.
ASSETS_DIR ?= assets

# Verify environment, and define PLUGIN_ID, PLUGIN_VERSION, HAS_SERVER and HAS_WEBAPP as needed.
include build/setup.mk

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

# 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
apply:
./build/bin/manifest apply

## Runs govet and gofmt against all packages.
.PHONY: check-style
check-style: server/.depensure webapp/.npminstall gofmt govet
@echo Checking for style guide compliance
Expand All @@ -26,6 +29,7 @@ ifneq ($(HAS_WEBAPP),)
cd webapp && npm run lint
endif

## Runs gofmt against all packages.
.PHONY: gofmt
gofmt:
ifneq ($(HAS_SERVER),)
Expand All @@ -45,22 +49,25 @@ ifneq ($(HAS_SERVER),)
@echo Gofmt success
endif

## Runs govet against all packages.
.PHONY: govet
govet:
ifneq ($(HAS_SERVER),)
@echo Running govet
@$(GO) vet $$(go list ./server/...) || exit 1
$(GO) get golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
$(GO) vet $$(go list ./server/...)
$(GO) vet -vettool=$(GOPATH)/bin/shadow $$(go list ./server/...)
@echo Govet success
endif

# server/.depensure ensures the server dependencies are installed
## Ensures the server dependencies are installed.
server/.depensure:
ifneq ($(HAS_SERVER),)
cd server && $(DEP) ensure
touch $@
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
server: server/.depensure
ifneq ($(HAS_SERVER),)
Expand All @@ -70,26 +77,32 @@ ifneq ($(HAS_SERVER),)
cd server && env GOOS=windows GOARCH=amd64 $(GO) build -o dist/plugin-windows-amd64.exe;
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:
ifneq ($(HAS_WEBAPP),)
cd webapp && $(NPM) install
touch $@
endif

# webapp builds the webapp, if it exists
## Builds the webapp, if it exists.
.PHONY: webapp
webapp: webapp/.npminstall
ifneq ($(HAS_WEBAPP),)
cd webapp && $(NPM) run build;
endif

# bundle generates a tar bundle of the plugin for install
## Generates a tar bundle of the plugin for install.
.PHONY: bundle
bundle:
rm -rf dist/
mkdir -p dist/$(PLUGIN_ID)
cp $(MANIFEST_FILE) dist/$(PLUGIN_ID)/
ifneq ($(wildcard $(ASSETS_DIR)/.),)
cp -r $(ASSETS_DIR) dist/$(PLUGIN_ID)/
endif
ifneq ($(HAS_PUBLIC),)
cp -r public/ dist/$(PLUGIN_ID)/
endif
ifneq ($(HAS_SERVER),)
mkdir -p dist/$(PLUGIN_ID)/server/dist;
cp -r server/dist/* dist/$(PLUGIN_ID)/server/dist/;
Expand All @@ -102,31 +115,19 @@ endif

@echo plugin built at: dist/$(BUNDLE_NAME)

# dist builds and bundles the plugin
## Builds and bundles the plugin.
.PHONY: dist
dist: apply \
server \
webapp \
bundle
dist: apply server webapp bundle

# deploy installs the plugin to a (development) server, using the API if appropriate environment
# variables are defined, or copying the files directly to a sibling mattermost-server directory
## Installs the plugin to a (development) server.
.PHONY: deploy
deploy: dist
ifneq ($(and $(MM_SERVICESETTINGS_SITEURL),$(MM_ADMIN_USERNAME),$(MM_ADMIN_PASSWORD),$(HTTP)),)
@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) X-Requested-With:"XMLHttpRequest" | grep Token | cut -f2 -d' '` && \
http --print b GET $(MM_SERVICESETTINGS_SITEURL)/api/v4/users/me Authorization:"Bearer $$TOKEN" && \
http --print b DELETE $(MM_SERVICESETTINGS_SITEURL)/api/v4/plugins/$(PLUGIN_ID) Authorization:"Bearer $$TOKEN" && \
http --print b --check-status --form POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/plugins plugin@dist/$(BUNDLE_NAME) Authorization:"Bearer $$TOKEN" && \
http --print b POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/plugins/$(PLUGIN_ID)/enable Authorization:"Bearer $$TOKEN" && \
http --print b POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/users/logout Authorization:"Bearer $$TOKEN" \
)
else ifneq ($(and $(MM_SERVICESETTINGS_SITEURL),$(MM_ADMIN_USERNAME),$(MM_ADMIN_PASSWORD),$(CURL)),)
## 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),$(CURL)),)
@echo "Installing plugin via API"
$(eval TOKEN := $(shell curl -i -X POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/users/login -d '{"login_id": "$(MM_ADMIN_USERNAME)", "password": "$(MM_ADMIN_PASSWORD)"}' | grep Token | cut -f2 -d' ' 2> /dev/null))
@curl -s -H "Authorization: Bearer $(TOKEN)" -X DELETE $(MM_SERVICESETTINGS_SITEURL)/api/v4/plugins/$(PLUGIN_ID) > /dev/null
@curl -s -H "Authorization: Bearer $(TOKEN)" -X POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/plugins -F "plugin=@dist/$(BUNDLE_NAME)" > /dev/null && \
@curl -s -H "Authorization: Bearer $(TOKEN)" -X POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/plugins -F "plugin=@dist/$(BUNDLE_NAME)" -F "force=true" > /dev/null && \
curl -s -H "Authorization: Bearer $(TOKEN)" -X POST $(MM_SERVICESETTINGS_SITEURL)/api/v4/plugins/$(PLUGIN_ID)/enable > /dev/null && \
echo "OK." || echo "Sorry, something went wrong."
else ifneq ($(wildcard ../mattermost-server/.*),)
Expand All @@ -137,17 +138,25 @@ else
@echo "No supported deployment method available. Install plugin manually."
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
test: server/.depensure webapp/.npminstall
ifneq ($(HAS_SERVER),)
cd server && $(GO) test -race -v -coverprofile=coverage.txt ./...
cd server && $(GO) test -race -v ./...
endif
ifneq ($(HAS_WEBAPP),)
cd webapp && $(NPM) run fix;
endif

# clean removes all build artifacts
## Creates a coverage report for the server code.
.PHONY: coverage
coverage: server/.depensure webapp/.npminstall
ifneq ($(HAS_SERVER),)
cd server && $(GO) test -race -coverprofile=coverage.txt ./...
@cd server && $(GO) tool cover -html=coverage.txt
endif

## Clean removes all build artifacts.
.PHONY: clean
clean:
rm -fr dist/
Expand All @@ -161,3 +170,7 @@ ifneq ($(HAS_WEBAPP),)
rm -fr webapp/node_modules
endif
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 '\-\-' | sed '1!G;h;$$!d' | awk 'NR%2{printf "\033[36m%-30s\033[0m",$$0;next;}1' | sort
Binary file modified build/bin/manifest
Binary file not shown.
14 changes: 13 additions & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@
"id": "com.mattermost.draw-plugin",
"name": "Draw Plugin",
"description": "This plugin allows you to draw directly in the application.",
"version": "0.0.1",
"version": "0.0.2",
"server": {
"executables": {
"linux-amd64": "server/dist/plugin-linux-amd64",
"darwin-amd64": "server/dist/plugin-darwin-amd64",
"windows-amd64": "server/dist/plugin-windows-amd64.exe"
}
},
"webapp": {
"bundle_path": "webapp/dist/main.js"
},
"settings_schema": {
"header": "",
"footer": "",
"settings": []
}
}
3 changes: 3 additions & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage.txt
vendor
.depensure
Loading

0 comments on commit d469528

Please sign in to comment.