-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
90 lines (70 loc) · 2.78 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Define the name of your gem
GEM_NAME = crimson-falcon
# Define the version of your gem
GEM_VERSION := $(shell ruby -r './lib/crimson-falcon/version.rb' -e 'puts Falcon::VERSION')
# Define the path to your gemspec file
GEMSPEC_PATH = $(GEM_NAME).gemspec
# Define shell commands
BUILD_COMMAND = gem build $(GEMSPEC_PATH)
INSTALL_COMMAND = gem install $(GEM_NAME)-$(GEM_VERSION).gem
UNINSTALL_COMMAND = gem uninstall $(GEM_NAME)
CLEAN_COMMAND = rm -f $(GEM_NAME)-$(GEM_VERSION).gem
# Directory where the ruby files are located (regex fix)
DIR := lib/crimson-falcon/
#------------------------
# Development tasks
#------------------------
.PHONY: default build install uninstall rebuild
default: build
build:
@echo "Building gem..."
@$(BUILD_COMMAND)
install:
@echo "Installing gem..."
@$(INSTALL_COMMAND)
uninstall:
@echo "Uninstalling gem..."
@$(UNINSTALL_COMMAND)
clean:
@echo "Cleaning up..."
@$(CLEAN_COMMAND)
rebuild: uninstall build install clean
#------------------------
# SDK Generation tasks
#------------------------
.PHONY: build-sdk fix-regex clean-generated-files rubocop remove-suffix
build-sdk:
@echo "Generating SDK..."
@openapi-generator generate -i .openapi-generator/swagger-patched.json -g ruby -c .openapi-generator/config.yml -t .openapi-generator/templates
fix-regex:
@echo "Fixing regex..."
ifeq ($(shell uname -s),Darwin) # If the operating system is macOS
@find $(DIR) -name "*.rb" -print0 | while IFS= read -r -d '' file; do \
sed -i '' -E 's/\[0-9a-z-_]/[0-9a-z\\-_]/g' "$$file" ; \
done
else # If the operating system is Linux
@find $(DIR) -name "*.rb" -print0 | while IFS= read -r -d '' file; do \
sed -i 's/\[0-9a-z-_]/[0-9a-z\\-_]/g' "$$file" ; \
done
endif
.openapi-generator/swagger-stripped-oauth.json: .openapi-generator/swagger-patched.json
# We remove security info from swagger before generating golang API interface.
# This achieves cleaner interface. OAuth is then applied automatically through the middle-ware.
jq 'walk(if type == "object" and has("security") and (has("consumes") or has("produces")) then del(.security) else . end)' $< > $@
.openapi-generator/swagger-patched.json: .openapi-generator/swagger.json .openapi-generator/transformation.jq
jq -f .openapi-generator/transformation.jq $< > $@
.openapi-generator/swagger.json:
@echo "Sorry swagger.json needs to be obtained manually at this moment"
@exit 1
rubocop:
@echo "Running rubocop..."
@rubocop -a
remove-suffix:
@echo "Removing generated API suffix..."
@ruby remove-suffix.rb
clean-generated-files:
@echo "Cleaning up generated files..."
@rm -rf docs/* lib/crimson-falcon/models/* lib/crimson-falcon/api/* spec/*
.PHONY: generate
generate: clean-generated-files .openapi-generator/swagger-stripped-oauth.json build-sdk fix-regex remove-suffix rubocop
@echo "SDK generated successfully."