The pepperminty.wiki website! https://peppermint.mooncarrot.space/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

137 lines
3.7 KiB

  1. #!/usr/bin/env bash
  2. # Make sure the current directory is the location of this script to simplify matters
  3. cd "$(dirname "$(readlink -f "$0")")";
  4. ################
  5. ### Settings ###
  6. ################
  7. # The name of this project
  8. project_name="pepperminty.wiki";
  9. # The path to the lantern build engine git submodule
  10. lantern_path="./lantern-build-engine";
  11. ###
  12. # Custom Settings
  13. ###
  14. config="./.eleventy.js"; # relative to src/
  15. output_dir="${PWD}/public";
  16. port_number="5726"
  17. scp_path="starbeamrainbowlabs.com:/srv/pepperminty.wiki/www/";
  18. ###############################################################################
  19. # Check out the lantern git submodule if needed
  20. if [ ! -f "${lantern_path}/lantern.sh" ]; then git submodule update --init "${lantern_path}"; fi
  21. source "${lantern_path}/lantern.sh";
  22. if [[ "$#" -lt 1 ]]; then
  23. echo -e "${FBLE}${project_name}${RS} build script";
  24. echo -e " by Starbeamrainbowlabs";
  25. echo -e "${LC}Powered by the lantern build engine, v${version}${RS}";
  26. echo -e "";
  27. echo -e "${CSECTION}Usage${RS}";
  28. echo -e " ./build ${CTOKEN}{action}${RS} ${CTOKEN}{action}${RS} ${CTOKEN}{action}${RS} ...";
  29. echo -e "";
  30. echo -e "${CSECTION}Available actions${RS}";
  31. echo -e " ${CACTION}setup${RS} - Perform initial setup";
  32. echo -e " ${CACTION}build${RS} - Build the static site";
  33. echo -e " ${CACTION}watch${RS} - Watch for changes and rebuild automatically";
  34. echo -e " ${CACTION}server${RS} - Start a development busybox http server";
  35. echo -e " ${CACTION}launch${RS} - Do both ${CACTION}server${RS} and ${CACTION}watch${RS}";
  36. echo -e " ${CACTION}serve${RS} - Start a livereload server";
  37. echo -e " ${CACTION}deploy${RS} - Build and deploy to the remote web server";
  38. echo -e "";
  39. exit 1;
  40. fi
  41. ###############################################################################
  42. task_setup() {
  43. task_begin "Checking environment";
  44. check_command git true;
  45. check_command node true;
  46. check_command npm true;
  47. check_command npx true;
  48. task_end 0;
  49. task_begin "Initialising submodules";
  50. execute git submodule update --init;
  51. task_end $?;
  52. task_begin "Installing dependencies";
  53. npm install;
  54. task_end "$?";
  55. }
  56. task_build() {
  57. task_begin "Building site";
  58. cd src || { echo "Failed to cd into src"; exit 1; };
  59. execute npx @11ty/eleventy --config="${config}" --output="${output_dir}";
  60. task_end "$?";
  61. }
  62. task_watch() {
  63. echo -e "Watching for changes.";
  64. while :; do # : = infinite loop
  65. # Wait for an update
  66. # inotifywait's non-0 exit code forces an exit for some reason :-/
  67. inotifywait -qr --event modify --event close_write --format '%:e %f' src;
  68. # Rebuild the client code - spawn a sub-process to avoid the hard exit
  69. # This still doesn't work though, which is *really* annoying
  70. stage_begin "Rebuilding";
  71. set +e; # Allow errors
  72. ./build build;
  73. set -e;
  74. stage_end 0;
  75. done
  76. }
  77. task_server() {
  78. task_begin "Starting server";
  79. busybox httpd -vv -f -p "${port_number}" -h "${output_dir}" &
  80. pid="$!"
  81. task_end "$?";
  82. echo -e "Server started on ${HC}http://$(hostname -I | tr ' ' '\n' | head -n1):${port_number}/${RS}"
  83. on_exit() {
  84. task_begin "Stopping server";
  85. kill "${pid}";
  86. task_end "$?";
  87. }
  88. trap on_exit EXIT;
  89. wait
  90. }
  91. task_launch() {
  92. tasks_run server &
  93. tasks_run watch &
  94. wait
  95. }
  96. task_serve() {
  97. tasks_run watch &
  98. sleep 0.2;
  99. task_begin "Building site";
  100. cd src || { echo "Failed to cd into src"; exit 1; };
  101. execute npx @11ty/eleventy --config="${config}" --serve --output "${output_dir}";
  102. task_end "$?";
  103. }
  104. task_deploy() {
  105. tasks_run build;
  106. task_begin "Deploying pepperminty.wiki";
  107. scp -r ${output_dir}/* "${scp_path}";
  108. task_end "$?";
  109. }
  110. ###############################################################################
  111. tasks_run "$@";