Create Makefile

This commit is contained in:
perennial
2024-09-16 18:52:00 +10:00
parent 96387b9925
commit 47aafb75f1
2 changed files with 76 additions and 3 deletions
+54
View File
@@ -0,0 +1,54 @@
# Makefile for PixivFE
# Variables
BINARY_NAME=pixivfe
GOFILES=$(shell find . -type f -name '*.go')
# Environment variables (customize as needed)
export PIXIVFE_TOKEN=token_123456
export PIXIVFE_IMAGEPROXY=pximg.cocomi.cf
export PIXIVFE_PORT=8282
.PHONY: all fmt build test run clean
all: fmt build test
fmt:
@echo "Formatting Go code..."
@go fmt ./$(shell find . -type d)
build:
@echo "Building $(BINARY_NAME)..."
@go mod download
@go get codeberg.org/vnpower/pixivfe/v2/...
@CGO_ENABLED=0 go build -v -ldflags="-extldflags=-static" -tags netgo -o $(BINARY_NAME)
test:
@echo "Running tests..."
@go test ./server/template
run: build
@echo "Running $(BINARY_NAME)..."
./$(BINARY_NAME)
clean:
@echo "Cleaning up..."
@rm -f $(BINARY_NAME)
# Additional target to install test script as pre-commit hook
install-pre-commit:
@echo "Installing pre-commit hook..."
@cp test.sh .git/hooks/pre-commit
@chmod +x .git/hooks/pre-commit
# Help target
help:
@echo "Available targets:"
@echo " all - Run fmt, build, and test"
@echo " fmt - Format Go code"
@echo " build - Build the binary"
@echo " test - Run tests"
@echo " run - Build and run the binary"
@echo " clean - Remove the binary"
@echo " install-pre-commit - Install test script as pre-commit hook"
@echo " help - Show this help message"
+22 -3
View File
@@ -28,6 +28,7 @@ Prerequisites:
- [Go](https://go.dev/doc/install) (to build PixivFE from source)
- [Sass](https://github.com/sass/dart-sass/) (will be run by PixivFE in development mode)
- [Make](https://www.gnu.org/software/make/) (to use the Makefile)
To install Dart Sass, you can choose any of the following methods.
@@ -41,13 +42,31 @@ Then, run the project:
# Clone the PixivFE repository
git clone https://codeberg.org/VnPower/PixivFE.git && cd PixivFE
# Run in PixivFE in development mode (styles and templates reload automatically)
PIXIVFE_DEV=1 <other_environment_variables> go run .
# Build the project
make build
# Run PixivFE in development mode (styles and templates reload automatically)
PIXIVFE_DEV=1 <other_environment_variables> make run
```
## Using the Makefile
The project includes a Makefile to simplify common development tasks. Here are the available commands:
- `make all`: Run fmt, build, and test
- `make fmt`: Format Go code
- `make build`: Build the binary
- `make test`: Run tests
- `make run`: Build and run the binary
- `make clean`: Remove the built binary
- `make install-pre-commit`: Install test script as pre-commit hook
- `make help`: Show all available targets and their descriptions
You can use these commands to streamline your development workflow.
## Hosting PixivFE
You can use PixivFE for personal use! Assuming that you use an operating system that can run POSIX shell scripts, install `go`, clone this repository, modify the `run.sh` file, and profit!
You can use PixivFE for personal use! Assuming that you use an operating system that can run POSIX shell scripts, install `go`, clone this repository, and use the Makefile to build and run the project.
I recommend self-hosting your own instance for personal use, instead of relying entirely on official instances.
To deploy PixivFE using Docker or the compiled binary, see [Hosting PixivFE](https://pixivfe-docs.pages.dev/hosting-pixivfe/).