Skip to content

Commit 0dcdfaf

Browse files
committed
first commit
1 parent 00125cf commit 0dcdfaf

File tree

9 files changed

+461
-2
lines changed

9 files changed

+461
-2
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@ modules.order
5050
Module.symvers
5151
Mkfile.old
5252
dkms.conf
53+
54+
# Folders
55+
.config
56+
[o|O]bj
57+
[b|B]in
58+
nupkg
59+
.vs

NuGet.config

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<!-- <add key="myGet" value="https://www.myget.org/F/genocs-microservices/api/v3/index.json" protocolVersion="3" /> -->
5+
</packageSources>
6+
<packageSourceCredentials>
7+
</packageSourceCredentials>
8+
</configuration>

README.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,56 @@
1-
# genocs-library-cli
2-
The cli tool used to setup the genocs templates
1+
# Genocs cli
2+
3+
Another key component for the Genocs ecosystem
4+
5+
## Introduction
6+
7+
Genocs cli is the genocs **dotnet tool** that allow you to use the genocs templates.
8+
Genocs template are dotnet template that will help you to setup quickly and easily your microservices.
9+
10+
Here where you can find the official Documentation:
11+
- [microsoft - dotnet tools](https://learn.microsoft.com/en-us/dotnet/core/tools/global-tools)
12+
13+
14+
## Supported runtime
15+
16+
Genocs cli can be used on NET6 or NET7 runtimes
17+
18+
---
19+
20+
Usefull commands
21+
``` bash
22+
# Get the list of tool
23+
dotnet tool list
24+
25+
# Install from nuget
26+
dotnet tool install -g genocs.cli
27+
28+
# Update the tool
29+
dotnet tool update -g genocs.cli
30+
31+
# Uninstall cache
32+
dotnet tool uninstall genocs.cli -g
33+
```
34+
35+
36+
Usefull commands to work on your own
37+
``` bash
38+
# build the project
39+
dotnet build ./src/genocs.cli.csproj
40+
41+
# Pack the tool (to be deployed on nuget)
42+
dotnet pack
43+
44+
# Run the tool to install the templates
45+
dotnet run -f net7.0 --project ./src/genocs.cli.csproj genocs i
46+
47+
# Run the tool to install the templates (some as above with cd command)
48+
cd ./src
49+
dotnet run -f net7.0 genocs -i
50+
51+
# Pack the tool (to be deployed on nuget)
52+
dotnet pack
53+
54+
# Install the tool from local folder to the global cache
55+
dotnet tool install --global --add-source ./src/nupkg genocs.cli
56+
```

genocs.cli.sln

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.6.33706.43
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "genocs.cli", "src\genocs.cli.csproj", "{E8F25820-FF5F-4AC8-ACA5-1EC4CCFEE5BE}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_Solution Items", "_Solution Items", "{BE6A9801-D663-426E-8591-E4A7556DC972}"
9+
ProjectSection(SolutionItems) = preProject
10+
README.md = README.md
11+
EndProjectSection
12+
EndProject
13+
Global
14+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
15+
Debug|Any CPU = Debug|Any CPU
16+
Release|Any CPU = Release|Any CPU
17+
EndGlobalSection
18+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
19+
{E8F25820-FF5F-4AC8-ACA5-1EC4CCFEE5BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20+
{E8F25820-FF5F-4AC8-ACA5-1EC4CCFEE5BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
21+
{E8F25820-FF5F-4AC8-ACA5-1EC4CCFEE5BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
22+
{E8F25820-FF5F-4AC8-ACA5-1EC4CCFEE5BE}.Release|Any CPU.Build.0 = Release|Any CPU
23+
EndGlobalSection
24+
GlobalSection(SolutionProperties) = preSolution
25+
HideSolutionNode = FALSE
26+
EndGlobalSection
27+
GlobalSection(ExtensibilityGlobals) = postSolution
28+
SolutionGuid = {4CEBD513-17C0-420C-A427-0CA311BD44EC}
29+
EndGlobalSection
30+
EndGlobal

icon.png

1.01 KB
Loading

src/Program.cs

Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
// See https://aka.ms/new-console-template for more information
2+
3+
using System.Diagnostics;
4+
using System.Reflection;
5+
using System.Text.RegularExpressions;
6+
7+
8+
var version = Assembly.GetEntryAssembly()?
9+
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
10+
.InformationalVersion;
11+
12+
Console.WriteLine($"genocs v{version}");
13+
Console.WriteLine(Figgle.FiggleFonts.Doom.Render($"genocs v{version}"));
14+
ShowBot("Hello!!!");
15+
16+
if (args.Length == 0)
17+
{
18+
Console.WriteLine("Insufficient params. Please refer to https://blog.genocs.com/dotnet-webapi-boilerplate/general/genocs-api-console");
19+
return;
20+
}
21+
22+
23+
string firstArg = args[0].Trim().ToLower();
24+
if (firstArg == "install" || firstArg == "i" || firstArg == "update" || firstArg == "u")
25+
{
26+
await InstallTemplates();
27+
return;
28+
}
29+
30+
if (firstArg == "cleanarchitecture")
31+
{
32+
if (args.Length != 3)
33+
{
34+
Console.WriteLine("Invalid command. Use something like: genocs cleanarchitecture new <CompanyName.ProjectName>");
35+
return;
36+
}
37+
38+
string command = args[1].Trim().ToLower();
39+
// Convert to Capital case
40+
string projectName = args[2].Trim();
41+
if (command == "n" || command == "new")
42+
{
43+
await BootstrapCleanArchitectureSolution(projectName);
44+
}
45+
46+
return;
47+
}
48+
49+
if (firstArg == "microservice")
50+
{
51+
if (args.Length != 3)
52+
{
53+
Console.WriteLine("Invalid command. Use something like: genocs microservice new <CompanyName.ProjectName>");
54+
return;
55+
}
56+
57+
string command = args[1].Trim().ToLower();
58+
// Convert to Capital case
59+
string projectName = args[2].Trim();
60+
if (command == "n" || command == "new")
61+
{
62+
await BootstrapMicroserviceSolution(projectName);
63+
}
64+
65+
return;
66+
}
67+
68+
69+
if (firstArg == "wasm")
70+
{
71+
if (args.Length != 3)
72+
{
73+
Console.WriteLine("Invalid command. Use something like: genocs wasm new <CompanyName.ProjectName>");
74+
return;
75+
}
76+
77+
string command = args[1].Trim().ToLower();
78+
// Convert to Capital case
79+
// Convert to Capital case
80+
string projectName = args[2].Trim();
81+
if (command == "n" || command == "new")
82+
{
83+
await BootstrapBlazorWasmSolution(projectName);
84+
}
85+
86+
return;
87+
}
88+
89+
90+
static void ShowBot(string message)
91+
{
92+
string bot = $"\n {message}";
93+
bot += @"
94+
__________________
95+
\
96+
\
97+
....
98+
....'
99+
....
100+
..........
101+
.............'..'..
102+
................'..'.....
103+
.......'..........'..'..'....
104+
........'..........'..'..'.....
105+
.'....'..'..........'..'.......'.
106+
.'..................'... ......
107+
. ......'......... .....
108+
. _ __ ......
109+
.. # ## ......
110+
.... . .......
111+
...... ....... ............
112+
................ ......................
113+
........................'................
114+
......................'..'...... .......
115+
.........................'..'..... .......
116+
........ ..'.............'..'.... ..........
117+
..'..'... ...............'....... ..........
118+
...'...... ...... .......... ...... .......
119+
........... ....... ........ ......
120+
....... '...'.'. '.'.'.' ....
121+
....... .....'.. ..'.....
122+
.. .......... ..'........
123+
............ ..............
124+
............. '..............
125+
...........'.. .'.'............
126+
............... .'.'.............
127+
.............'.. ..'..'...........
128+
............... .'..............
129+
......... ..............
130+
.....
131+
";
132+
Console.WriteLine(bot);
133+
}
134+
135+
static void WriteColor(string message, ConsoleColor color)
136+
{
137+
var pieces = Regex.Split(message, @"(\[[^\]]*\])");
138+
139+
for (int i = 0; i < pieces.Length; i++)
140+
{
141+
string piece = pieces[i];
142+
143+
if (piece.StartsWith("[") && piece.EndsWith("]"))
144+
{
145+
Console.ForegroundColor = color;
146+
piece = piece.Substring(1, piece.Length - 2);
147+
}
148+
149+
Console.Write(piece);
150+
Console.ResetColor();
151+
}
152+
153+
Console.WriteLine();
154+
}
155+
156+
async Task InstallTemplates()
157+
{
158+
WriteSuccessMessage("Installing genocs dotnet Clean Architecture template...");
159+
160+
var cleanArchitecturePsi = new ProcessStartInfo
161+
{
162+
FileName = "dotnet",
163+
Arguments = "new install Genocs.CleanArchitectureTemplate::2.1.0"
164+
};
165+
166+
using var cleanArchitectureProc = Process.Start(cleanArchitecturePsi)!;
167+
await cleanArchitectureProc.WaitForExitAsync();
168+
// --------------------------
169+
170+
Console.WriteLine("Installing genocs Microservice template...");
171+
var microservicePsi = new ProcessStartInfo
172+
{
173+
FileName = "dotnet",
174+
Arguments = "new install Genocs.MicroserviceTemplate::0.1.0"
175+
};
176+
177+
using var microserviceProc = Process.Start(microservicePsi)!;
178+
await microserviceProc.WaitForExitAsync();
179+
// --------------------------
180+
181+
Console.WriteLine("Installing genocs blazor wasm template...");
182+
var blazorWebAssemblyPsi = new ProcessStartInfo
183+
{
184+
FileName = "dotnet",
185+
Arguments = "new install Genocs.MicroserviceTemplate::0.1.0"
186+
};
187+
188+
using var blazorWebAssemblyProc = Process.Start(blazorWebAssemblyPsi)!;
189+
await blazorWebAssemblyProc.WaitForExitAsync();
190+
// --------------------------
191+
192+
WriteSuccessMessage("Installed the required templates.");
193+
Console.WriteLine("Get started by using : genocs <type> new <CompanyName.ProjectName>.");
194+
Console.WriteLine("NOTE: <type> can be [cleanarchitecture | microservice | blazor].");
195+
Console.WriteLine("Refer to documentation at https://majestic-wisp-d90424.netlify.app");
196+
}
197+
198+
async Task BootstrapCleanArchitectureSolution(string projectName)
199+
{
200+
Console.WriteLine($"Bootstrapping genocs Clean Architecture project at \"./{projectName}\"...");
201+
var psi = new ProcessStartInfo
202+
{
203+
FileName = "dotnet",
204+
Arguments = $"new cleanarchitecture -n {projectName} -o {projectName} -v=q"
205+
};
206+
using var proc = Process.Start(psi)!;
207+
await proc.WaitForExitAsync();
208+
WriteSuccessMessage($"Genocs Architecture solution {projectName} successfully created.");
209+
WriteSuccessMessage("Application ready! Build something amazing!");
210+
Console.WriteLine("Refer to documentation at https://blog.genocs.com/dotnet-webapi-boilerplate/general/getting-started");
211+
}
212+
213+
async Task BootstrapMicroserviceSolution(string projectName)
214+
{
215+
Console.WriteLine($"Bootstrapping genocs Microservice project at \"./{projectName}\"...");
216+
var psi = new ProcessStartInfo
217+
{
218+
FileName = "dotnet",
219+
Arguments = $"new microservice -n {projectName} -o {projectName} -v=q"
220+
};
221+
using var proc = Process.Start(psi)!;
222+
await proc.WaitForExitAsync();
223+
WriteSuccessMessage($"Genocs Microservice solution {projectName} successfully created.");
224+
WriteSuccessMessage("Application ready! Build something amazing!");
225+
Console.WriteLine("Refer to documentation at https://blog.genocs.com/dotnet-webapi-boilerplate/general/getting-started");
226+
}
227+
228+
async Task BootstrapBlazorWasmSolution(string projectName)
229+
{
230+
Console.WriteLine($"Bootstrapping genocs Blazor wasm solution at \"./{projectName}\"...");
231+
var psi = new ProcessStartInfo
232+
{
233+
FileName = "dotnet",
234+
Arguments = $"new gnx-blazor -n {projectName} -o {projectName} -v=q"
235+
};
236+
237+
using var proc = Process.Start(psi)!;
238+
await proc.WaitForExitAsync();
239+
WriteSuccessMessage($"Genocs blazor wasm solution {projectName} successfully created.");
240+
WriteSuccessMessage("Application ready! Build something amazing!");
241+
Console.WriteLine("Refer to documentation at https://blog.genocs.com/blazor-webassembly-boilerplate/general/getting-started/");
242+
}
243+
244+
static void WriteSuccessMessage(string message)
245+
{
246+
Console.ForegroundColor = ConsoleColor.Green;
247+
Console.WriteLine(message);
248+
Console.ResetColor();
249+
}
250+
251+
static void WriteColorEx(string str, params (string substring, ConsoleColor color)[] colors)
252+
{
253+
var words = Regex.Split(str, @"( )");
254+
255+
foreach (var word in words)
256+
{
257+
(string substring, ConsoleColor color) cl = colors.FirstOrDefault(x => x.substring.Equals("{" + word + "}"));
258+
if (cl.substring != null)
259+
{
260+
Console.ForegroundColor = cl.color;
261+
Console.Write(cl.substring.Substring(1, cl.substring.Length - 2));
262+
Console.ResetColor();
263+
}
264+
else
265+
{
266+
Console.Write(word);
267+
}
268+
}
269+
}
270+
271+
Console.WriteLine("\nUsage:");
272+
Console.WriteLine(" genocs <params>");
273+
274+
// WriteColorEx("This is my message with new color with red", ("{message}", ConsoleColor.Red), ("{with}", ConsoleColor.Blue));
275+
276+
Console.WriteLine("\n");

src/Properties/launchSettings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"profiles": {
3+
"genocs.cli": {
4+
"commandName": "Project",
5+
"commandLineArgs": "i"
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)