lib_sxng_node.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env bash
  2. # SPDX-License-Identifier: AGPL-3.0-or-later
  3. declare _Blue
  4. declare _creset
  5. export NODE_MINIMUM_VERSION="16.13.0"
  6. node.help(){
  7. cat <<EOF
  8. node.:
  9. env : download & install SearXNG's npm dependencies locally
  10. env.dev : download & install developer and CI tools
  11. clean : drop locally npm installations
  12. EOF
  13. }
  14. nodejs.ensure() {
  15. if ! nvm.min_node "${NODE_MINIMUM_VERSION}"; then
  16. info_msg "install Node.js by NVM"
  17. nvm.nodejs
  18. fi
  19. }
  20. node.env() {
  21. nodejs.ensure
  22. ( set -e
  23. build_msg INSTALL "[npm] ./client/simple/package.json"
  24. npm --prefix client/simple install
  25. )
  26. dump_return $?
  27. }
  28. node.env.dev() {
  29. nodejs.ensure
  30. build_msg INSTALL "[npm] ./package.json: developer and CI tools"
  31. npm install
  32. }
  33. node.clean() {
  34. if ! required_commands npm 2>/dev/null; then
  35. build_msg CLEAN "npm is not installed / ignore npm dependencies"
  36. return 0
  37. fi
  38. build_msg CLEAN "themes -- locally installed npm dependencies"
  39. ( set -e
  40. npm --prefix client/simple run clean \
  41. | prefix_stdout "${_Blue}CLEAN ${_creset} "
  42. if [ "${PIPESTATUS[0]}" -ne "0" ]; then
  43. return 1
  44. fi
  45. )
  46. build_msg CLEAN "locally installed developer and CI tools"
  47. ( set -e
  48. npm --prefix . run clean \
  49. | prefix_stdout "${_Blue}CLEAN ${_creset} "
  50. if [ "${PIPESTATUS[0]}" -ne "0" ]; then
  51. return 1
  52. fi
  53. )
  54. dump_return $?
  55. }