Skip to content

Commit 08cd5c3

Browse files
committed
Add dynamic template generation
1 parent 4ad8c65 commit 08cd5c3

File tree

3 files changed

+150
-3
lines changed

3 files changed

+150
-3
lines changed

CreateTemplate.ps1 renamed to template-src/CreateTemplate.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Write-Host "[$timestamp] Copying solution files..."
4545
$excludedItems = @(
4646
"bin", "obj", "node_modules", ".vs", ".vscode", "dist", ".git",
4747
".angular", "package-lock.json", "yarn.lock", ".env",
48-
"appsettings.Development.json", "CreateTemplate.ps1", "nupkg"
48+
"appsettings.Development.json", "template-src/CreateTemplate.ps1", "nupkg"
4949
)
5050

5151
# Get absolute path of the output directory to avoid copying it
@@ -71,7 +71,7 @@ Get-ChildItem -Path $SourceDirectory -Directory |
7171
Get-ChildItem -Path $SourceDirectory -File |
7272
Where-Object {
7373
-not $_.Name.StartsWith('.') -and
74-
$_.Name -ne "CreateTemplate.ps1" -and
74+
$_.Name -ne "template-src/CreateTemplate.ps1" -and
7575
$_.Extension -ne ".nupkg"
7676
} |
7777
ForEach-Object {
@@ -192,4 +192,4 @@ $templateJsonContent = $templateJson | ConvertTo-Json -Depth 10
192192
Set-Content -Path (Join-Path $templateConfigDir "template.json") -Value $templateJsonContent
193193

194194
Write-Host "[$timestamp] Template preparation completed successfully."
195-
Write-Host "Template output directory: $OutputDirectory"
195+
Write-Host "Template output directory: $OutputDirectory"

template-src/README.template.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Clean Architecture Docker Angular Template
2+
3+
This template provides a starting point for creating a Clean Architecture solution with Docker and Angular. Follow the instructions below to use the template.
4+
5+
## Prerequisites
6+
7+
- [.NET SDK 9.0](https://dotnet.microsoft.com/download/dotnet/9.0)
8+
- [Node.js](https://nodejs.org/) (for Angular)
9+
- [Docker](https://www.docker.com/get-started)
10+
11+
## Getting Started
12+
13+
1. **Install the template:**
14+
15+
```bash
16+
dotnet new install <path-to-template>
17+
```
18+
19+
2. **Create a new project using the template:**
20+
21+
```bash
22+
dotnet new cleanarch --projectName MyTestApp --namespacePrefix NitinSoft.
23+
```
24+
25+
3. **Navigate to the project directory:**
26+
27+
```bash
28+
cd MyTestApp
29+
```
30+
31+
4. **Build and run the project:**
32+
33+
```bash
34+
docker-compose up
35+
```
36+
37+
## Template Parameters
38+
39+
- `--projectName`: The name of the project. Default is `MyApp`.
40+
- `--namespacePrefix`: Optional namespace prefix (e.g., `MyOrg.`). Default is an empty string.
41+
42+
## Directory Structure
43+
44+
The template creates the following directory structure:
45+
46+
```
47+
MyTestApp/
48+
├── backend/
49+
│ ├── src/
50+
│ ├── tests/
51+
│ └── ...
52+
├── frontend/
53+
│ ├── src/
54+
│ ├── e2e/
55+
│ └── ...
56+
├── docker-compose.yml
57+
└── README.md
58+
```
59+
60+
## Customizing the Template
61+
62+
You can customize the template by modifying the `template.json` file located in the `template-src` directory. Refer to the [Microsoft documentation](https://docs.microsoft.com/en-us/dotnet/core/tools/custom-templates) for more information on creating custom templates.
63+
64+
## Contributing
65+
66+
If you would like to contribute to this template, please follow the steps below:
67+
68+
1. **Create a new branch:**
69+
70+
```bash
71+
git checkout -b template-generator
72+
```
73+
74+
2. **Add the folder structure:**
75+
76+
- Add the `template-src/` folder with:
77+
- `CreateTemplate.ps1`
78+
- `template.json`
79+
- `README.template.md`
80+
- `.github/workflows/dotnet-template-publish.yml` (if you’re automating)
81+
82+
3. **Test locally:**
83+
84+
```bash
85+
cd template-src
86+
./CreateTemplate.ps1
87+
```
88+
89+
4. **Install and try the template:**
90+
91+
```bash
92+
dotnet new install ../src/ProjectTemplate
93+
dotnet new cleanarch --projectName MyTestApp --namespacePrefix NitinSoft.
94+
```
95+
96+
5. **Check generated output:**
97+
98+
Validate if:
99+
- Project files are renamed
100+
- Namespaces are updated
101+
- It builds and runs
102+
103+
6. **Commit and push:**
104+
105+
```bash
106+
git add .
107+
git commit -m "Add dynamic template generation"
108+
git push origin template-generator
109+
```
110+
111+
Once you’re happy, you can either:
112+
- Merge into main, or
113+
- Keep it as a separate maintained branch for template packaging
114+
115+
## License
116+
117+
This project is licensed under the MIT License. See the [LICENSE](../LICENSE) file for details.

template-src/template.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"$schema": "http://json.schemastore.org/template",
3+
"author": "Nitin",
4+
"classifications": ["Web", "Clean Architecture"],
5+
"name": "Clean Architecture Docker Angular",
6+
"identity": "NitinSoft.CleanArch.Template",
7+
"groupIdentity": "NitinSoft.CleanArch.Template",
8+
"shortName": "cleanarch",
9+
"sourceName": "ProjectNamePlaceholder",
10+
"preferNameDirectory": true,
11+
"tags": {
12+
"language": "C#",
13+
"type": "project"
14+
},
15+
"symbols": {
16+
"namespacePrefix": {
17+
"type": "parameter",
18+
"datatype": "text",
19+
"description": "Optional namespace prefix (e.g., MyOrg.)",
20+
"defaultValue": "",
21+
"replaces": "NamespacePrefix"
22+
},
23+
"projectName": {
24+
"type": "parameter",
25+
"datatype": "text",
26+
"defaultValue": "MyApp",
27+
"replaces": "ProjectNamePlaceholder"
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)