Skip to content

Commit 70c794a

Browse files
committed
feat: migrate project from cookiecutter to copier template
1 parent ab41fe5 commit 70c794a

File tree

74 files changed

+757
-675
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+757
-675
lines changed

.github/workflows/ci-for-example.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ jobs:
2929
restore-keys: |
3030
${{ runner.os }}-maven-
3131
- name: Build with Maven
32-
run: mvn clean verify -ntp
32+
run: mvn clean verify -ntp

.github/workflows/ci-from-template.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
branches:
55
- main
66
paths:
7-
- '{{cookiecutter.app_name}}/**'
7+
- '{{app_name}}/**'
88
workflow_dispatch:
99
jobs:
1010
generate-from-template:
@@ -20,14 +20,14 @@ jobs:
2020
uses: actions/setup-python@v5
2121
with:
2222
python-version: '3.x'
23-
- name: Install cookiecutter
23+
- name: Install copier
2424
run: |
25-
pip install --upgrade pip cookiecutter
26-
- name: Generate from default context (cookiecutter.json)
25+
pip install --upgrade pip copier
26+
- name: Generate from default context (copier)
2727
run: |
28-
# Generate using the config file test-config.yml from the repo root.
29-
# Use the repo root as the template directory (.) and overwrite any existing generated output.
30-
cookiecutter --no-input --config-file test-config.yml --overwrite-if-exists --output-dir . .
28+
# Use the repo root as the template directory and generate into ./cart-service
29+
# Use copier.yml as the default data file with --defaults and --force to overwrite any existing generated output.
30+
copier copy . . --defaults --force
3131
- name: Upload generated cart-service as artifact
3232
uses: actions/upload-artifact@v4
3333
with:
@@ -59,5 +59,5 @@ jobs:
5959
restore-keys: |
6060
${{ runner.os }}-maven-
6161
- name: Build with Maven
62-
run: git init && mvn clean verify -Dgit-code-format.skip=true -DargLine="--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED" -ntp
63-
working-directory: ./cart-service
62+
run: git init && mvn clean verify -ntp
63+
working-directory: ./cart-service

.github/workflows/generate-template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666

6767
- name: Copy generated template to {{cookiecutter.app_name}}
6868
run: |
69-
rsync -a --delete --exclude='.git' ./example-template/ ./{{cookiecutter.app_name}}/
69+
rsync -a --delete --exclude='.git' ./example-template/ ./{{app_name}}/
7070
7171
- name: Commit and push changes
7272
id: commit

README.md

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Template project for hexagonal-spring-boot-java
1+
# Template project for hexagonal-spring-boot-java [![Copier](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/copier-org/copier/master/img/badge/badge-grayscale-inverted-border-orange.json)](https://github.com/copier-org/copier)
22

3-
This is a template project for hexagonal-spring-boot-java. This project is generated using [cookiecutter](https://cookiecutter.readthedocs.io/en).
3+
This is a template project for hexagonal-spring-boot-java. This project is generated using [copier](https://copier.readthedocs.io/en/stable/) .
44

55
## Pre-requisites
66

7-
- [cookiecutter](https://cookiecutter.readthedocs.io/en/stable/README.html#installation)
7+
- [copier](https://copier.readthedocs.io/en/stable/#installation)
88
- Jdk 21
99
- Maven >3.9.5
1010

@@ -22,26 +22,41 @@ flowchart LR
2222

2323
### example
2424

25-
This directory contains the maven hexagonal-spring-boot-java template project. This will be used to generate template project for cookiecutter. This project is used for the contributors to make their changes and test it locally.
25+
This directory contains the maven hexagonal-spring-boot-java template project. This will be used to generate template project for copier. This project is used for the contributors to make their changes and test it locally.
2626

27-
Following are the keywords reserved for the template project and their equivalent replacements in {{cookiecutter.app_name}} project:
27+
Following are the keywords reserved for the template project and their equivalent replacements in {{app_name}} project:
2828

29-
| Keyword | Replacement |
30-
|--------------|---------------------------------------------|
31-
| Examples | {{cookiecutter.domain_plural_capitalized}} |
32-
| examples | {{cookiecutter.domain_plural}} |
33-
| Example | {{cookiecutter.domain_capitalized}} |
34-
| example | {{cookiecutter.domain}} |
35-
| packagename | {{cookiecutter.package_name}} |
36-
| artifactName | {{cookiecutter.artifact_id}} |
37-
| group-id | {{cookiecutter.group_id}} |
38-
| EXAMPLES | {{cookiecutter.domain_plural_uppercase}} |
39-
| EXAMPLE | {{cookiecutter.domain_uppercase}} |
29+
| Keyword | Replacement |
30+
|--------------|-------------------------------|
31+
| Examples | {{domain_plural_capitalized}} |
32+
| examples | {{domain_plural}} |
33+
| Example | {{domain_capitalized}} |
34+
| example | {{domain}} |
35+
| packagename | {{package_name}} |
36+
| artifactName | {{artifact_id}} |
37+
| group-id | {{group_id}} |
38+
| EXAMPLES | {{domain_plural_uppercase}} |
39+
| EXAMPLE | {{domain_uppercase}} |
4040

41-
Refer script [generate-cookiecutter-template-from-example-project.sh](generate-cookiecutter-template-from-example-project.sh) which is used to generate the cookiecutter template project. This script is also being used by [`.github/workflows/ci.yaml`](.github/workflows/ci.yaml) pipeline too.
41+
Refer script [generate-copier-template-from-example-project.sh](generate-copier-template-from-example-project.sh) which is used to generate the copier template project. This script is also being used by [generate-template.yaml](.github/workflows/generate-template.yaml) pipeline too.
4242

43-
### {{cookiecutter.app_name}}
43+
### {{app_name}}
4444

45-
> NOTE: DO NOT MODIFY THIS DIRECTORY DIRECTLY
45+
> [!WARNING]
46+
> DO NOT MODIFY THIS DIRECTORY DIRECTLY
4647
47-
This directory contains the generated project from `example` project. The project is generated using the script [generate-cookiecutter-template-from-example-project.sh](generate-cookiecutter-template-from-example-project.sh) which is used to generate the cookiecutter template project.
48+
This directory contains the generated project from `example` project. The project is generated using the script [generate-copier-template-from-example-project.sh](generate-copier-template-from-example-project.sh) which is used to generate the cookiecutter template project.
49+
50+
## Generating a new project
51+
52+
The following command can be used to generate a new project using this template:
53+
54+
```bash
55+
copier copy . <destination_folder>
56+
```
57+
58+
Command to generate with default values without prompt:
59+
60+
```bash
61+
copier copy . . --defaults
62+
```

cookiecutter.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

copier.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
app_name:
2+
type: str
3+
help: "Short project name (e.g., myapp)"
4+
default: "cart-service"
5+
6+
app_title:
7+
type: str
8+
help: "Project title"
9+
default: "{{ app_name|capitalize }}"
10+
11+
domain:
12+
type: str
13+
help: "Domain name (e.g., user, order)"
14+
default: "cart"
15+
16+
domain_capitalized:
17+
type: str
18+
help: "Domain name, capitalized"
19+
default: "{{ domain|capitalize }}"
20+
21+
domain_uppercase:
22+
type: str
23+
help: "Domain name, uppercase"
24+
default: "{{ domain|upper }}"
25+
26+
domain_plural:
27+
type: str
28+
help: "Plural form of domain"
29+
default: "{% if app_name.endswith('y') %}{{ domain.replace('y', '') }}ies{% else %}{{ domain.lower() }}s{% endif %}"
30+
31+
domain_plural_capitalized:
32+
type: str
33+
help: "Plural domain, capitalized"
34+
default: "{{ domain_plural|capitalize }}"
35+
36+
domain_plural_uppercase:
37+
type: str
38+
help: "Plural domain, uppercase"
39+
default: "{{ domain_plural|upper }}"
40+
41+
group_id:
42+
type: str
43+
help: "Maven groupId"
44+
default: "org.{{ domain }}"
45+
46+
artifact_id:
47+
type: str
48+
help: "Maven artifactId"
49+
default: "{{ domain }}"
50+
51+
package_name:
52+
type: str
53+
help: "Base package name"
54+
default: "{{ group_id }}"
55+
56+
_copy_without_render:
57+
- .github

generate-cookiecutter-template-from-example-project.sh

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
# This script is used to rename files and directories in the example project to that of the cookiecutter template.
3+
4+
# Remove previous example-template directory if it exists
5+
if [ -d "example-template" ]; then
6+
rm -rf "example-template"
7+
fi
8+
# Create a new example-template directory and copy the example project into it
9+
mkdir "example-template"
10+
rsync -a ./example/ ./example-template/
11+
cd ./example-template
12+
13+
# sets the locale for all commands run in the current shell session to the "C" locale, which is the default POSIX locale. This makes programs like sed and find treat files as raw bytes, ignoring any character encoding issues. It helps avoid errors like illegal byte sequence when processing files with mixed or unknown encodings.
14+
export LC_ALL=C
15+
16+
# Detect OS and set sed inline flag
17+
if [[ "$(uname)" == "Darwin" ]]; then
18+
SED_INPLACE=(-i '')
19+
else
20+
SED_INPLACE=(-i)
21+
fi
22+
23+
find . -type f -exec sed "${SED_INPLACE[@]}" -e s/Examples/{{domain_plural_capitalized}}/g '{}' ';'
24+
find . -depth -name '*Examples*' -print0|while IFS= read -rd '' f; do mv -i "$f" "$(echo "$f"|sed -E 's/(.*)Examples/\1{{domain_plural_capitalized}}/')"; done
25+
find . -type f -exec sed "${SED_INPLACE[@]}" -e s/examples/{{domain_plural}}/g '{}' ';'
26+
find . -depth -name '*examples*' -print0|while IFS= read -rd '' f; do mv -i "$f" "$(echo "$f"|sed -E 's/(.*)examples/\1{{domain_plural}}/')"; done
27+
find . -type f -exec sed "${SED_INPLACE[@]}" -e s/Example/{{domain_capitalized}}/g '{}' ';'
28+
find . -depth -name '*Example*' -print0|while IFS= read -rd '' f; do mv -i "$f" "$(echo "$f"|sed -E 's/(.*)Example/\1{{domain_capitalized}}/')"; done
29+
find . -type f -exec sed "${SED_INPLACE[@]}" -e s/example/{{domain}}/g '{}' ';'
30+
find . -depth -name '*example*' -print0|while IFS= read -rd '' f; do mv -i "$f" "$(echo "$f"|sed -E 's/(.*)example/\1{{domain}}/')"; done
31+
find . -type f -exec sed "${SED_INPLACE[@]}" -e s/packagename/{{package_name}}/g '{}' ';'
32+
find . -depth -name '*packagename*' -print0|while IFS= read -rd '' f; do mv -i "$f" "$(echo "$f"|sed -E 's/(.*)packagename/\1{{package_name}}/')"; done
33+
find . -type f -exec sed "${SED_INPLACE[@]}" -e s/artifactName/{{artifact_id}}/g '{}' ';'
34+
find . -type f -exec sed "${SED_INPLACE[@]}" -e s/group-id/{{group_id}}/g '{}' ';'
35+
## For the following, we need to replace EXAMPLES and EXAMPLE with the domain name
36+
find . -type f -exec sed "${SED_INPLACE[@]}" -e s/EXAMPLES/{{domain_plural_uppercase}}/g '{}' ';'
37+
find . -type f -exec sed "${SED_INPLACE[@]}" -e s/EXAMPLE/{{domain_uppercase}}/g '{}' ';'
38+
39+
# Rename files to add .jinja extension
40+
# Add .jinja extension to files except those under .github
41+
exts=(xml yml java feature sql yaml)
42+
for ext in "${exts[@]}"; do
43+
find . -type d -name .github -prune -o -type f -name "*.${ext}" -print0 | while IFS= read -r -d '' file; do
44+
mv "$file" "$file.jinja"
45+
done
46+
done

rename_dir.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
# Dry-run: show planned renames
3+
find . -depth -type d -name '{{cookiecutter.*' -print0 | \
4+
while IFS= read -r -d '' d; do
5+
new="$(dirname "$d")/$(basename "$d" | sed 's/^{{cookiecutter\./{{/')"
6+
printf '%s -> %s\n' "$d" "$new"
7+
done
8+
9+
## Apply changes: actually rename (run only after verifying dry-run)
10+
find . -depth -type d -name '{{cookiecutter.*' -print0 | \
11+
while IFS= read -r -d '' d; do
12+
new="$(dirname "$d")/$(basename "$d" | sed 's/^{{cookiecutter\./{{/')"
13+
if [ -e "$new" ]; then
14+
printf 'Skipping %s: target exists %s\n' "$d" "$new" >&2
15+
continue
16+
fi
17+
mv -- "$d" "$new" && printf 'Renamed %s -> %s\n' "$d" "$new"
18+
done

test-config.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)