Clone templates from git by default

This commit is contained in:
hh
2026-09-08 20:04:08 +02:00
parent f8b5765c15
commit 7a1774a36f
2 changed files with 10 additions and 6 deletions
+1 -1
View File
@@ -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
+9 -5
View File
@@ -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 <dest> [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)