lib_sxng_node.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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="18.17.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. (
  23. set -e
  24. build_msg INSTALL "[npm] ./client/simple/package.json"
  25. npm --prefix client/simple install
  26. )
  27. dump_return $?
  28. }
  29. node.env.dev() {
  30. nodejs.ensure
  31. build_msg INSTALL "[npm] ./package.json: developer and CI tools"
  32. npm install
  33. }
  34. node.clean() {
  35. if ! required_commands npm 2>/dev/null; then
  36. build_msg CLEAN "npm is not installed / ignore npm dependencies"
  37. return 0
  38. fi
  39. build_msg CLEAN "themes -- locally installed npm dependencies"
  40. (
  41. set -e
  42. npm --prefix client/simple run clean |
  43. prefix_stdout "${_Blue}CLEAN ${_creset} "
  44. if [ "${PIPESTATUS[0]}" -ne "0" ]; then
  45. return 1
  46. fi
  47. )
  48. build_msg CLEAN "locally installed developer and CI tools"
  49. (
  50. set -e
  51. npm --prefix . run clean |
  52. prefix_stdout "${_Blue}CLEAN ${_creset} "
  53. if [ "${PIPESTATUS[0]}" -ne "0" ]; then
  54. return 1
  55. fi
  56. )
  57. dump_return $?
  58. }