aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2019-12-05 04:41:38 +0100
committerLunny Xiao <xiaolunwen@gmail.com>2019-12-05 11:41:38 +0800
commitd9c67a8c903fa9927bad28f5fcb816f89f8200eb (patch)
treeb652427ec0da37baf13ea27fd5e0a99ed5c656ec /Makefile
parente80fe201c0e7b1f7a73aa932d4a02068e044f0ce (diff)
downloadgitea-d9c67a8c903fa9927bad28f5fcb816f89f8200eb.tar.gz
gitea-d9c67a8c903fa9927bad28f5fcb816f89f8200eb.zip
Add Node.js build dep, remove built js/css files (#9114)
- Added Node.js as build dependency and removes build files from git. - Added version checks for both Go and Node.js. - Overhauled the js/css make target to only run when needed. - Merged the `generate` make target into `build` as per suggestion. Fixes: https://github.com/go-gitea/gitea/issues/6782 Fixes: https://github.com/go-gitea/gitea/issues/9216
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile91
1 files changed, 60 insertions, 31 deletions
diff --git a/Makefile b/Makefile
index 9f15daa312..e5a691fcab 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,6 @@ else
endif
endif
-BINDATA := modules/{options,public,templates}/bindata.go
GOFILES := $(shell find . -name "*.go" -type f ! -path "./vendor/*" ! -path "*/bindata.go")
GOFMT ?= gofmt -s
@@ -42,7 +41,17 @@ endif
LDFLAGS := $(LDFLAGS) -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(GITEA_VERSION)" -X "main.Tags=$(TAGS)"
PACKAGES ?= $(filter-out code.gitea.io/gitea/integrations/migration-test,$(filter-out code.gitea.io/gitea/integrations,$(shell GO111MODULE=on $(GO) list -mod=vendor ./... | grep -v /vendor/)))
-SOURCES ?= $(shell find . -name "*.go" -type f)
+
+GO_SOURCES ?= $(shell find . -name "*.go" -type f)
+JS_SOURCES ?= $(shell find web_src/js web_src/css -type f)
+CSS_SOURCES ?= $(shell find web_src/less -type f)
+
+JS_DEST := public/js/index.js
+CSS_DEST := public/css/index.css
+BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
+
+JS_DEST_DIR := public/js
+CSS_DEST_DIR := public/css
TAGS ?=
@@ -80,10 +89,31 @@ all: build
include docker/Makefile
+.PHONY: go-check
+go-check:
+ $(eval GO_VERSION := $(shell printf "%03d%03d%03d" $(shell go version | grep -Eo '[0-9]+\.?[0-9]+?\.?[0-9]?\s' | tr '.' ' ');))
+ @if [ "$(GO_VERSION)" -lt "001011000" ]; then \
+ echo "Gitea requires Go 1.11.0 or greater to build. You can get it at https://golang.org/dl/"; \
+ exit 1; \
+ fi
+
+.PHONY: node-check
+node-check:
+ $(eval NODE_VERSION := $(shell printf "%03d%03d%03d" $(shell node -v | grep -Eo '[0-9]+\.?[0-9]+?\.?[0-9]?' | tr '.' ' ');))
+ $(eval NPM_MISSING := $(shell hash npm > /dev/null 2>&1 || echo 1))
+ @if [ "$(NODE_VERSION)" -lt "010000000" -o "$(NPM_MISSING)" = "1" ]; then \
+ echo "Gitea requires Node.js 10.0.0 or greater and npm to build. You can get it at https://nodejs.org/en/download/"; \
+ exit 1; \
+ fi
+
+.PHONY: clean-all
+clean-all: clean
+ rm -rf $(JS_DEST_DIR) $(CSS_DEST_DIR)
+
.PHONY: clean
clean:
$(GO) clean -i ./...
- rm -rf $(EXECUTABLE) $(DIST) $(BINDATA) \
+ rm -rf $(EXECUTABLE) $(DIST) $(BINDATA_DEST) \
integrations*.test \
integrations/gitea-integration-pgsql/ integrations/gitea-integration-mysql/ integrations/gitea-integration-mysql8/ integrations/gitea-integration-sqlite/ \
integrations/gitea-integration-mssql/ integrations/indexers-mysql/ integrations/indexers-mysql8/ integrations/indexers-pgsql integrations/indexers-sqlite \
@@ -309,42 +339,42 @@ bench-pgsql: integrations.pgsql.test generate-ini-pgsql
integration-test-coverage: integrations.cover.test generate-ini-mysql
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.cover.test -test.coverprofile=integration.coverage.out
-integrations.mysql.test: $(SOURCES)
+integrations.mysql.test: $(GO_SOURCES)
GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mysql.test
-integrations.mysql8.test: $(SOURCES)
+integrations.mysql8.test: $(GO_SOURCES)
GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mysql8.test
-integrations.pgsql.test: $(SOURCES)
+integrations.pgsql.test: $(GO_SOURCES)
GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.pgsql.test
-integrations.mssql.test: $(SOURCES)
+integrations.mssql.test: $(GO_SOURCES)
GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mssql.test
-integrations.sqlite.test: $(SOURCES)
+integrations.sqlite.test: $(GO_SOURCES)
GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
-integrations.cover.test: $(SOURCES)
+integrations.cover.test: $(GO_SOURCES)
GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -coverpkg $(shell echo $(PACKAGES) | tr ' ' ',') -o integrations.cover.test
.PHONY: migrations.mysql.test
-migrations.mysql.test: $(SOURCES)
+migrations.mysql.test: $(GO_SOURCES)
$(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.mysql.test
.PHONY: migrations.mysql8.test
-migrations.mysql8.test: $(SOURCES)
+migrations.mysql8.test: $(GO_SOURCES)
$(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.mysql8.test
.PHONY: migrations.pgsql.test
-migrations.pgsql.test: $(SOURCES)
+migrations.pgsql.test: $(GO_SOURCES)
$(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.pgsql.test
.PHONY: migrations.mssql.test
-migrations.mssql.test: $(SOURCES)
+migrations.mssql.test: $(GO_SOURCES)
$(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.mssql.test
.PHONY: migrations.sqlite.test
-migrations.sqlite.test: $(SOURCES)
+migrations.sqlite.test: $(GO_SOURCES)
$(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
.PHONY: check
@@ -354,10 +384,16 @@ check: test
install: $(wildcard *.go)
$(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
+.PHONY: go
+go: go-check $(EXECUTABLE)
+
+.PHONY: go-all
+go-all: go-check generate go
+
.PHONY: build
-build: $(EXECUTABLE)
+build: js css go-all
-$(EXECUTABLE): $(SOURCES)
+$(EXECUTABLE): $(GO_SOURCES)
GO111MODULE=on $(GO) build -mod=vendor $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
.PHONY: release
@@ -412,33 +448,26 @@ release-compress:
fi
cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && gxz -k -9 $${file}; done;
-npm-check:
- @hash npm > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
- echo "Please install Node.js 8.x or greater with npm"; \
- exit 1; \
- fi;
- @hash npx > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
- echo "Please install Node.js 8.x or greater with npm"; \
- exit 1; \
- fi;
-
-.PHONY: npm
-npm: npm-check
+node_modules: package-lock.json
npm install --no-save
.PHONY: npm-update
-npm-update: npm-check
+npm-update: node-check node_modules
npx updates -cu
rm -rf node_modules package-lock.json
npm install --package-lock
.PHONY: js
-js: npm
+js: node-check $(JS_DEST)
+
+$(JS_DEST): node_modules $(JS_SOURCES)
npx eslint web_src/js webpack.config.js
npx webpack
.PHONY: css
-css: npm
+css: node-check $(CSS_DEST)
+
+$(CSS_DEST): node_modules $(CSS_SOURCES)
npx stylelint web_src/less
npx lessc --clean-css="--s0 -b" web_src/less/index.less public/css/index.css
$(foreach file, $(filter-out web_src/less/themes/_base.less, $(wildcard web_src/less/themes/*)),npx lessc --clean-css="--s0 -b" web_src/less/themes/$(notdir $(file)) > public/css/theme-$(notdir $(call strip-suffix,$(file))).css;)