eia-api-go/Makefile

51 lines
1.9 KiB
Makefile
Raw Normal View History

2024-11-16 19:02:46 +00:00
# Variables
2024-11-27 21:06:30 +00:00
SCHEMA_DIR := ./schema
SCHEMA_ZIP := eia-api-swagger.zip
SCHEMA_YML := eia-api-swagger.yaml
2024-11-16 19:02:46 +00:00
CLIENT_PKG := ./cmd/eia-client
2024-11-26 15:54:55 +00:00
CLIENT_GEN_FILE := ./api/eiaapi.gen.go
2024-11-26 22:12:39 +00:00
MAPPER_GEN_FILE := ./api/eiaapi_funcmap.gen.go
2024-11-26 15:54:55 +00:00
GO_FORMATTER := gofumpt
2024-11-27 21:06:30 +00:00
IS_GNU_SED := $(shell sed --version >/dev/null 2>&1 && echo true || echo false)
2024-11-27 21:06:30 +00:00
SED_INLINE := $(if $(IS_GNU_SED),-i '',-i)
2024-11-15 21:30:45 +00:00
2024-11-27 21:06:30 +00:00
.PHONY: all schema generate build install clean
2024-11-15 21:30:45 +00:00
2024-11-16 19:02:46 +00:00
# Default target
2024-11-27 21:07:35 +00:00
all: schema generate build install
2024-11-27 21:06:30 +00:00
# Retrieve and prepare schema
schema:
curl https://www.eia.gov/opendata/$(SCHEMA_ZIP) -o $(SCHEMA_DIR)/$(SCHEMA_ZIP)
unzip -o $(SCHEMA_DIR)/$(SCHEMA_ZIP) -d $(SCHEMA_DIR)
sed -E $(SED_INLINE) 's/responses\/data/schemas\/DataResponseContainer/g' $(SCHEMA_DIR)/$(SCHEMA_YML)
2024-11-29 21:58:12 +00:00
sed -E $(SED_INLINE) 's/responses\/route/schemas\/RouteResponse/g' $(SCHEMA_DIR)/$(SCHEMA_YML)
2024-11-27 21:06:30 +00:00
sed -E $(SED_INLINE) 's/responses\/facets/schemas\/FacetOptionListContainer/g' $(SCHEMA_DIR)/$(SCHEMA_YML)
sed -E $(SED_INLINE) 's/responses\/facet/schemas\/FacetDetailsContainer/g' $(SCHEMA_DIR)/$(SCHEMA_YML)
sed -E $(SED_INLINE) 's/responses\/final-route/schemas\/FinalRouteResponse/g' $(SCHEMA_DIR)/$(SCHEMA_YML)
sed -E $(SED_INLINE) 's/[[:space:]]+Frequency:/ Frequency:\n x-go-name: FrequencyObject/g' $(SCHEMA_DIR)/$(SCHEMA_YML)
2024-11-15 21:30:45 +00:00
2024-11-16 19:02:46 +00:00
# Generate code
generate:
go generate ./...
2024-11-29 21:58:12 +00:00
sed -E $(SED_INLINE) 's/Total[[:space:]]+\*int/Total *string/g' $(CLIENT_GEN_FILE)
sed -E $(SED_INLINE) 's/Command[[:space:]]+\*\[\]string/Command *string/g' $(CLIENT_GEN_FILE)
sed -E $(SED_INLINE) 's/Routes[[:space:]]+\*\[\]string/Routes *[]Routes/g' $(CLIENT_GEN_FILE)
2024-11-26 15:54:55 +00:00
# Pretty it up
$(GO_FORMATTER) -w $(CLIENT_GEN_FILE)
2024-11-26 22:12:39 +00:00
$(GO_FORMATTER) -w $(MAPPER_GEN_FILE)
2024-11-15 21:30:45 +00:00
2024-11-16 19:02:46 +00:00
# Build the client command binary
build: generate
go build -o bin/eia-client $(CLIENT_PKG)
2024-11-15 21:30:45 +00:00
2024-11-16 19:02:46 +00:00
# Install the client command binary
2024-11-27 01:22:07 +00:00
install:
2024-11-26 15:54:55 +00:00
go install -v $(CLIENT_PKG)
2024-11-15 21:30:45 +00:00
2024-11-16 19:02:46 +00:00
# Clean up generated files and build artifacts
2024-11-15 21:30:45 +00:00
clean:
2024-11-16 19:02:46 +00:00
rm -rf bin/eia-client