diff --git a/README.md b/README.md index 601f99b..4de6367 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ One command that composes a project from the templates in this organization: `in newproject ~/projects/my-thing ``` -Templates are read from `$TEMPLATES_DIR` (default `~/projects/templates`). Every part updates independently: +Templates are cloned from `https://git.kotikot.com/templates` by default; set `TEMPLATES_DIR` to a directory with local checkouts to work on the templates themselves. Every part updates independently: ```sh copier update -a .copier-answers.backend.yml diff --git a/newproject b/newproject index b8cf032..a6836c5 100755 --- a/newproject +++ b/newproject @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -euo pipefail -TEMPLATES="${TEMPLATES_DIR:-$HOME/projects/templates}" +TEMPLATES="${TEMPLATES_DIR:-https://git.kotikot.com/templates}" dest="${1:?usage: newproject [copier options]}" shift copier_args=("$@") @@ -18,6 +18,10 @@ yes_no() { [[ "$answer" =~ ^[Yy] ]] } +template() { + if [[ -d "$TEMPLATES/$1" ]]; then printf '%s' "$TEMPLATES/$1"; else printf '%s' "$TEMPLATES/$1.git"; fi +} + copy() { uvx copier@latest copy --trust "${copier_args[@]}" "$@" } @@ -52,21 +56,21 @@ json_list() { } mkdir -p "$dest" -copy -d "parts=$(json_list "${parts[@]}")" "$TEMPLATES/infra" "$dest" +copy -d "parts=$(json_list "${parts[@]}")" "$(template infra)" "$dest" if [[ " ${parts[*]} " == *" backend "* ]]; then copy -d "project_name=$project_name" -d "project_slug=$project_slug" \ -d "author_name=$author_name" -d "author_email=$author_email" \ - -d "serve_spa=$serve_spa" "$TEMPLATES/backend-python" "$dest" + -d "serve_spa=$serve_spa" "$(template backend-python)" "$dest" fi if [[ " ${parts[*]} " == *" frontend "* ]]; then copy -d "project_name=$project_name" -d "project_slug=$project_slug" \ - -d "serve=$serve" "$TEMPLATES/frontend-svelte" "$dest" + -d "serve=$serve" "$(template frontend-svelte)" "$dest" fi if $with_caddy; then - copy -d "project_slug=$project_slug" -d "routes=$(json_list "${routes[@]}")" "$TEMPLATES/caddy" "$dest" + copy -d "project_slug=$project_slug" -d "routes=$(json_list "${routes[@]}")" "$(template caddy)" "$dest" fi (cd "$dest" && make env)