diff --git a/hack/cuegen/cuegen.sh b/hack/cuegen/cuegen.sh new file mode 100644 index 000000000..c7db724bf --- /dev/null +++ b/hack/cuegen/cuegen.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +set -e + +# Usage: cuegen.sh dir [flagsToVela] +# Example: cuegen.sh references/cuegen/generators/provider/testdata/ \ +# -t provider \ +# --types *k8s.io/apimachinery/pkg/apis/meta/v1/unstructured.Unstructured=ellipsis + + +# check vela binary +if ! [ -x "$(command -v vela)" ]; then + echo "Please put vela binary in the PATH" + exit 1 +fi + +# get dir from first arg +dir="$1" +if [ -z "$dir" ]; then + echo "Please provide a directory" + exit 1 +fi + +echo "Generating CUE files from go files in $dir" +echo "========" + +find "$dir" -name "*.go" | while read -r file; do + echo "- Generating CUE file for $file" + + # redirect output if command exits successfully + (out=$(vela def gen-cue ${*:2} "$file") && echo "$out" > "${file%.go}".cue) & +done + +echo "========" +echo "Waiting for all background processes to finish" + +wait +sleep 5s # wait for all stderr to be printed + +echo "Done" diff --git a/makefiles/develop.mk b/makefiles/develop.mk index 56e0bc567..f957b8447 100644 --- a/makefiles/develop.mk +++ b/makefiles/develop.mk @@ -24,4 +24,9 @@ core-debug-run: fmt vet manifests # Run against the configured Kubernetes cluster in ~/.kube/config .PHONY: core-run core-run: fmt vet manifests - go run ./cmd/core/main.go \ No newline at end of file + go run ./cmd/core/main.go + +## gen-cue: Generate CUE files from Go files. Variable DIR is the directory of the Go files, FLAGS is the flags for vela def gen-cue command. +.PHONY: gen-cue +gen-cue: + ./hack/cuegen/cuegen.sh $(DIR) $(FLAGS)