build-ui.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. # Copyright 2014 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # This script builds ui assets into a single go datafile
  16. set -o errexit
  17. set -o nounset
  18. set -o pipefail
  19. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
  20. source "${KUBE_ROOT}/hack/lib/init.sh"
  21. cd "${KUBE_ROOT}"
  22. if ! which go-bindata > /dev/null 2>&1 ; then
  23. echo "Cannot find go-bindata. Install with \"go get github.com/jteeuwen/go-bindata/...\""
  24. exit 1
  25. fi
  26. readonly TMP_DATAFILE="/tmp/datafile.go"
  27. readonly SWAGGER_SRC="third_party/swagger-ui/..."
  28. readonly SWAGGER_PKG="swagger"
  29. function kube::hack::build_ui() {
  30. local pkg="$1"
  31. local src="$2"
  32. local output_file="pkg/ui/data/${pkg}/datafile.go"
  33. go-bindata -nocompress -o "${output_file}" -prefix ${PWD} -pkg "${pkg}" "${src}"
  34. local year=$(date +%Y)
  35. cat hack/boilerplate/boilerplate.go.txt | sed "s/YEAR/${year}/" > "${TMP_DATAFILE}"
  36. echo -e "// generated by hack/build-ui.sh; DO NOT EDIT\n" >> "${TMP_DATAFILE}"
  37. cat "${output_file}" >> "${TMP_DATAFILE}"
  38. gofmt -s -w "${TMP_DATAFILE}"
  39. mv "${TMP_DATAFILE}" "${output_file}"
  40. }
  41. kube::hack::build_ui "${SWAGGER_PKG}" "${SWAGGER_SRC}"