Makefile 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. # SeaweedFS Admin Component Makefile
  2. # Variables
  3. ADMIN_DIR := .
  4. VIEW_DIR := $(ADMIN_DIR)/view
  5. STATIC_DIR := $(ADMIN_DIR)/static
  6. TEMPL_FILES := $(shell find $(VIEW_DIR) -name "*.templ")
  7. TEMPL_GO_FILES := $(TEMPL_FILES:.templ=_templ.go)
  8. GO_FILES := $(shell find $(ADMIN_DIR) -name "*.go" -not -name "*_templ.go")
  9. BUILD_DIR := ../..
  10. WEED_BINARY := $(BUILD_DIR)/weed
  11. # Default target
  12. .PHONY: all
  13. all: build
  14. # Install templ if not present
  15. .PHONY: install-templ
  16. install-templ:
  17. @which templ > /dev/null || (echo "Installing templ..." && go install github.com/a-h/templ/cmd/templ@latest)
  18. # Generate templ files
  19. .PHONY: generate
  20. generate: install-templ
  21. @echo "Generating templ files..."
  22. @templ generate
  23. @echo "Generated: $(TEMPL_GO_FILES)"
  24. # Clean generated files
  25. .PHONY: clean-templ
  26. clean-templ:
  27. @echo "Cleaning generated templ files..."
  28. @find $(VIEW_DIR) -name "*_templ.go" -delete
  29. @echo "Cleaned templ files"
  30. # Watch for changes and regenerate
  31. .PHONY: watch
  32. watch: install-templ
  33. @echo "Watching for templ file changes..."
  34. @templ generate --watch
  35. # Build the main weed binary with admin component
  36. .PHONY: build
  37. build: generate
  38. @echo "Building weed binary with admin component..."
  39. @cd $(BUILD_DIR) && go build -o weed ./weed
  40. @echo "Built: $(BUILD_DIR)/weed"
  41. # Test the admin component
  42. .PHONY: test
  43. test: generate
  44. @echo "Running admin component tests..."
  45. @go test ./...
  46. # Run the admin server via weed command
  47. .PHONY: run
  48. run: build
  49. @echo "Starting admin server via weed command..."
  50. @cd $(BUILD_DIR) && ./weed admin
  51. # Development server with auto-reload
  52. .PHONY: dev
  53. dev: generate
  54. @echo "Starting development server with auto-reload..."
  55. @echo "Note: You'll need to manually restart the server when Go files change"
  56. @cd $(BUILD_DIR) && ./weed admin -port=23647 &
  57. @$(MAKE) watch
  58. # Lint the code
  59. .PHONY: lint
  60. lint:
  61. @echo "Linting admin component..."
  62. @golangci-lint run ./...
  63. # Format the code
  64. .PHONY: fmt
  65. fmt:
  66. @echo "Formatting Go code..."
  67. @go fmt ./...
  68. @echo "Formatting templ files..."
  69. @templ fmt $(VIEW_DIR)
  70. # Validate static files exist
  71. .PHONY: validate-static
  72. validate-static:
  73. @echo "Validating static files..."
  74. @test -f $(STATIC_DIR)/css/admin.css || (echo "Missing: admin.css" && exit 1)
  75. @test -f $(STATIC_DIR)/js/admin.js || (echo "Missing: admin.js" && exit 1)
  76. @echo "Static files validated"
  77. # Check dependencies
  78. .PHONY: deps
  79. deps:
  80. @echo "Checking dependencies..."
  81. @go mod tidy
  82. @go mod verify
  83. # Clean all build artifacts
  84. .PHONY: clean
  85. clean: clean-templ
  86. @echo "Cleaning build artifacts..."
  87. @rm -f $(BUILD_DIR)/weed 2>/dev/null || true
  88. @echo "Cleaned build artifacts"
  89. # Install dependencies
  90. .PHONY: install-deps
  91. install-deps:
  92. @echo "Installing Go dependencies..."
  93. @go mod download
  94. @$(MAKE) install-templ
  95. # Production build
  96. .PHONY: build-prod
  97. build-prod: clean generate validate-static
  98. @echo "Building production binary..."
  99. @cd $(BUILD_DIR) && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o weed-linux-amd64 ./weed
  100. @echo "Built production binary: $(BUILD_DIR)/weed-linux-amd64"
  101. # Docker build (if needed)
  102. .PHONY: docker-build
  103. docker-build: generate
  104. @echo "Building Docker image with admin component..."
  105. @cd $(BUILD_DIR) && docker build -t seaweedfs/seaweedfs:latest .
  106. # Help target
  107. .PHONY: help
  108. help:
  109. @echo "SeaweedFS Admin Component Makefile"
  110. @echo ""
  111. @echo "Available targets:"
  112. @echo " all - Build the weed binary with admin component (default)"
  113. @echo " generate - Generate templ files from templates"
  114. @echo " build - Build weed binary with admin component"
  115. @echo " build-prod - Build production binary"
  116. @echo " run - Run admin server via weed command"
  117. @echo " dev - Start development server with template watching"
  118. @echo " test - Run tests"
  119. @echo " watch - Watch for template changes and regenerate"
  120. @echo " clean - Clean all build artifacts"
  121. @echo " clean-templ - Clean generated template files"
  122. @echo " fmt - Format Go and templ code"
  123. @echo " lint - Lint the code"
  124. @echo " deps - Check and tidy dependencies"
  125. @echo " install-deps - Install all dependencies"
  126. @echo " install-templ - Install templ compiler"
  127. @echo " validate-static - Validate static files exist"
  128. @echo " docker-build - Build Docker image"
  129. @echo " help - Show this help message"
  130. @echo ""
  131. @echo "Examples:"
  132. @echo " make generate # Generate templates"
  133. @echo " make build # Build weed binary"
  134. @echo " make run # Start admin server"
  135. @echo " make dev # Development mode with auto-reload"
  136. # Make sure generated files are up to date before building
  137. $(WEED_BINARY): $(TEMPL_GO_FILES) $(GO_FILES)
  138. @$(MAKE) build
  139. # Auto-generate templ files when .templ files change
  140. %_templ.go: %.templ
  141. @echo "Regenerating $@ from $<"
  142. @templ generate
  143. .PHONY: $(TEMPL_GO_FILES)