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
|
|
|
|
2024-11-26 16:46:15 +00:00
|
|
|
IS_GNU_SED := $(shell sed --version >/dev/null 2>&1 && echo true || echo false)
|
2024-12-06 20:27:45 +00:00
|
|
|
SED_INLINE := $(if $(filter true,$(IS_GNU_SED)),-i,-i '')
|
2024-11-15 21:30:45 +00:00
|
|
|
|
2024-12-05 17:36:49 +00:00
|
|
|
.PHONY: all schema generate test build install clean
|
2024-11-15 21:30:45 +00:00
|
|
|
|
2024-11-16 19:02:46 +00:00
|
|
|
# Default target
|
2024-12-05 17:36:49 +00:00
|
|
|
all: schema generate test 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)
|
2024-12-05 17:36:49 +00:00
|
|
|
@echo "Using GNU sed: $(IS_GNU_SED)"
|
2024-11-27 21:06:30 +00:00
|
|
|
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-12-05 17:36:49 +00:00
|
|
|
@echo "Using GNU sed: $(IS_GNU_SED)"
|
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-12-05 17:36:49 +00:00
|
|
|
test:
|
|
|
|
# Test EIA API client package
|
|
|
|
go test -v ./pkg/eia
|
|
|
|
|
2024-11-16 19:02:46 +00:00
|
|
|
# Build the client command binary
|
2024-12-05 17:36:49 +00:00
|
|
|
build: generate test
|
2024-11-16 19:02:46 +00:00
|
|
|
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
|