diff --git a/.gitattributes b/.gitattributes index 6afd357c..ed8ab3b5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,5 @@ .git* export-ignore -/CMakeLists.txt export-subst \ No newline at end of file +/CMakeLists.txt export-subst + +# Mark auto-generated SDK clients as "generated" to hide them in GitHub diffs +utils/sdk/client/** linguist-generated=true \ No newline at end of file diff --git a/Makefile b/Makefile index 66a794c1..e4391e7b 100644 --- a/Makefile +++ b/Makefile @@ -190,3 +190,4 @@ tags: ctags -R --sort=1 --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ src contrib tests/gtest .PHONY: all release upload-conan-cache docs docs-dev configure static static-release test test-release test-debug clean tags conan-profile-detect get-conan $(PROFILES) sdk $(SDK_TARGETS) +.PHONY: go-client \ No newline at end of file diff --git a/utils/sdk/Makefile b/utils/sdk/Makefile index 98afd90c..a2bbc27d 100644 --- a/utils/sdk/Makefile +++ b/utils/sdk/Makefile @@ -1,9 +1,29 @@ PACKAGE_VERSION?=6.0.1 BASE_DIR:=$(CURDIR) -BUILD_DIR:=$(BASE_DIR)/../../build/packages +# Default build directory. Can be overridden from the parent Makefile. +# e.g., `make sdk BUILD_DIR=client` will output to the `client/` directory. +BUILD_DIR?=$(BASE_DIR)/../../build/packages SDK_TARGETS := $(patsubst packages/%.json,%,$(wildcard packages/*.json)) -# Default target to build all SDKs. This is the main entry point. +# --- Target-Specific Hooks --- +# Define pre- and post-build steps for specific languages. +# By default, these hooks are empty. + +PRE_BUILD_HOOK = @true +POST_BUILD_HOOK = @true + + # For the 'go' target, create an ignore file to prevent unwanted files from being generated. + go: PRE_BUILD_HOOK = @echo "--> Creating .openapi-generator-ignore file for Go client"; \ + echo "go.sum" >> $(BUILD_DIR)/go/.openapi-generator-ignore + +# For the 'go' target, define specific post-build steps. +go: POST_BUILD_HOOK = (cd $(BUILD_DIR)/go && go mod edit -module github.com/letheanVPN/blockchain/utils/sdk/client/go && go mod tidy) + +# For the 'go' target, set the generator name correctly. +go: GENERATOR_NAME = go + +# --- Main Targets --- + all: build build: $(SDK_TARGETS) @@ -12,19 +32,28 @@ build: $(SDK_TARGETS) # Rule to build each SDK package using OpenAPI Generator. # It reads the corresponding JSON config file and generates the SDK in the build directory. $(SDK_TARGETS): %: packages/%.json + # Default generator name is the target name itself. + $(eval GENERATOR_NAME = $@) + @echo "--> Creating .openapi-generator-ignore file" + @echo "git_push.sh" > "$(BUILD_DIR)/$@/.openapi-generator-ignore" + @echo ".travis.yml" >> "$(BUILD_DIR)/$@/.openapi-generator-ignore" + @echo "README.md" >> "$(BUILD_DIR)/$@/.openapi-generator-ignore" + @echo "--- Building package $@ with version $(PACKAGE_VERSION) ---" + # Run pre-build hook + $(PRE_BUILD_HOOK) rm -rf "$(BUILD_DIR)/$@/*" export TS_POST_PROCESS_FILE="/usr/local/bin/prettier --write" && \ - openapi-generator generate --skip-validate-spec \ + openapi-generator generate --minimal-update --git-host "github.com" --git-repo-id "blockchain" --git-user-id "letheanVPN" \ -i "$(BASE_DIR)/spec/oas-3.0.0.json" \ - -g "$@" \ + -g "$(GENERATOR_NAME)" \ -o "$(BUILD_DIR)/$@" \ -c "$<" \ --artifact-version "$(PACKAGE_VERSION)" \ - --group-id "lethean" \ - -p packageVersion="$(PACKAGE_VERSION)" \ - --global-property "apiTests=true" \ - --additional-properties=npmVersion="$(PACKAGE_VERSION)",artifactVersion="$(PACKAGE_VERSION)" + --package-name "lthn" + # Run post-build hook + @echo "--> Running Post Build..." + $(POST_BUILD_HOOK) # Phony targets to avoid conflicts with file names and to ensure they always run. .PHONY: all build $(SDK_TARGETS) diff --git a/utils/sdk/packages/go.json b/utils/sdk/packages/go.json index 11efc703..ec20510b 100644 --- a/utils/sdk/packages/go.json +++ b/utils/sdk/packages/go.json @@ -1,6 +1,7 @@ { "additionalProperties": { - "packageName": "lethean-chain-sdk-go", - "generateInterfaces": true + "packageName": "lthn", + "generateInterfaces": true, + "isGoSubmodule": true } } \ No newline at end of file