| 
									
										
										
										
											2023-10-07 22:23:40 +01:00
										 |  |  | #!/usr/bin/env bash
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # {{ managedText | raw }}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-22 21:53:50 +00:00
										 |  |  | set -o errexit
 | 
					
						
							|  |  |  | set -o pipefail
 | 
					
						
							| 
									
										
										
										
											2023-10-07 22:23:40 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | PATH="$PATH:./node_modules/.bin"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-08 09:59:03 +01:00
										 |  |  | {% if isDocker %}
 | 
					
						
							| 
									
										
										
										
											2023-10-07 22:23:40 +01:00
										 |  |  | # If we're running in CI we need to disable TTY allocation for docker compose
 | 
					
						
							|  |  |  | # commands that enable it by default, such as exec and run.
 | 
					
						
							|  |  |  | TTY="${TTY:-}"
 | 
					
						
							|  |  |  | if [[ ! -t 1 ]]; then
 | 
					
						
							|  |  |  |   TTY="-T"
 | 
					
						
							|  |  |  | fi
 | 
					
						
							|  |  |  | {% endif %}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Remove and generated or temporary files.
 | 
					
						
							|  |  |  | function build {
 | 
					
						
							| 
									
										
										
										
											2023-10-08 09:59:03 +01:00
										 |  |  | {% if isDocker %}
 | 
					
						
							| 
									
										
										
										
											2023-10-08 09:52:50 +01:00
										 |  |  |   cmd fractal build "${@}"
 | 
					
						
							| 
									
										
										
										
											2023-10-08 10:02:12 +01:00
										 |  |  | {% else %}
 | 
					
						
							| 
									
										
										
										
											2023-10-08 09:59:03 +01:00
										 |  |  |   fractal build "${@}"
 | 
					
						
							|  |  |  | {% endif %}
 | 
					
						
							| 
									
										
										
										
											2023-10-07 22:23:40 +01:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function ci:build {
 | 
					
						
							| 
									
										
										
										
											2023-10-08 09:59:03 +01:00
										 |  |  | {% if isDocker %}
 | 
					
						
							| 
									
										
										
										
											2023-10-08 17:24:31 +01:00
										 |  |  |   cp -v --no-clobber .env.example .env
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   docker network create traefik_proxy || true
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-08 09:59:03 +01:00
										 |  |  |   docker compose up -d
 | 
					
						
							|  |  |  | {% endif %}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-07 22:23:40 +01:00
										 |  |  |   build
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Remove and generated or temporary files.
 | 
					
						
							|  |  |  | function clean {
 | 
					
						
							|  |  |  |   rm -fr build node_modules
 | 
					
						
							|  |  |  |   touch build/.keep
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Disable Git hooks.
 | 
					
						
							|  |  |  | function git-hooks:off {
 | 
					
						
							|  |  |  |   git config --unset core.hooksPath
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Enable Git hooks.
 | 
					
						
							|  |  |  | function git-hooks:on {
 | 
					
						
							|  |  |  |   git config core.hooksPath .githooks
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Create a new Fractal component.
 | 
					
						
							|  |  |  | function fractal:new {
 | 
					
						
							|  |  |  |   mkdir -p "components/${1}"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   echo "name: ${1}" > "components/${1}/${1}.config.yml"
 | 
					
						
							|  |  |  |   echo "${1}" > "components/${1}/${1}.twig"
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Display a list of all available commands.
 | 
					
						
							|  |  |  | function help {
 | 
					
						
							|  |  |  |   printf "%s <task> [args]\n\nTasks:\n" "${0}"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   compgen -A function | grep -v "^_" | cat -n
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   printf "\nExtended help:\n  Each task has comments for general usage\n"
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Start the project.
 | 
					
						
							|  |  |  | function start {
 | 
					
						
							|  |  |  |   {% if not isFlake %}
 | 
					
						
							|  |  |  |     cp -v --no-clobber .env.example .env
 | 
					
						
							|  |  |  |     docker compose up -d
 | 
					
						
							|  |  |  |   {% else %}
 | 
					
						
							|  |  |  |     fractal start --sync
 | 
					
						
							|  |  |  |   {% endif %}
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function sync {
 | 
					
						
							|  |  |  |   clean
 | 
					
						
							|  |  |  |   fractal build
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   aws s3 sync "build/." s3://"${BUCKET_NAME}" \
 | 
					
						
							|  |  |  |     --acl "public-read" \
 | 
					
						
							|  |  |  |     --cache-control max-age=3600
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | {% if not isFlake %}
 | 
					
						
							|  |  |  | # Run a command within the node container.
 | 
					
						
							|  |  |  | function cmd {
 | 
					
						
							|  |  |  |   docker compose exec node yarn "${@}"
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Stop the project
 | 
					
						
							|  |  |  | function stop {
 | 
					
						
							|  |  |  |   docker compose down
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Execute yarn commands.
 | 
					
						
							|  |  |  | function yarn {
 | 
					
						
							|  |  |  |   cmd node yarn "${@}"
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function _run {
 | 
					
						
							|  |  |  |   local service="${1}"
 | 
					
						
							|  |  |  |   local command="${2}"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   docker compose run \
 | 
					
						
							|  |  |  |     --entrypoint "${command}" \
 | 
					
						
							|  |  |  |     --no-deps \
 | 
					
						
							|  |  |  |     --rm \
 | 
					
						
							|  |  |  |     -T \
 | 
					
						
							|  |  |  |     "${service}" "${@}"
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | {% endif %}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-19 23:07:38 +02:00
										 |  |  | # Include any local tasks.
 | 
					
						
							| 
									
										
										
										
											2023-11-18 08:40:43 +00:00
										 |  |  | [[ -e run.local ]] && source run.local
 | 
					
						
							| 
									
										
										
										
											2023-10-19 23:07:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-07 22:23:40 +01:00
										 |  |  | TIMEFORMAT=$'\nTask completed in %3lR'
 | 
					
						
							|  |  |  | time "${@:-help}"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # vim: ft=bash
 |