|
| 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"); |
0 commit comments