private static void WriteBaseAppModules(FileInfo csprojFile) { DirectoryInfo projectParent = csprojFile.Directory; DirectoryInfo appModules = new DirectoryInfo(Path.Combine(projectParent.FullName, "AppModules")); HandlebarsDirectory handlebarsDirectory = ShellProvider.GetHandlebarsDirectory(); string appName = Path.GetFileNameWithoutExtension(csprojFile.Name); AppModuleModel model = new AppModuleModel { BaseNamespace = appName, AppModuleName = appName }; foreach (string moduleType in new string[] { "AppModule", "ScopedAppModule", "SingletonAppModule", "TransientAppModule" }) { string moduleContent = handlebarsDirectory.Render($"{moduleType}.cs", model); if (string.IsNullOrEmpty(moduleContent)) { Message.PrintLine("{0}: Template for {1} is empty", handlebarsDirectory.Directory.FullName, moduleType); } string filePath = Path.Combine(appModules.FullName, $"{appName}{moduleType}.cs"); if (!File.Exists(filePath)) { moduleContent.SafeWriteToFile(filePath, true); Message.PrintLine("Wrote file {0}...", ConsoleColor.Green, filePath); } } }
private static void WriteStartupCs(FileInfo csprojFile) { DirectoryInfo projectParent = csprojFile.Directory; if (projectParent != null) { FileInfo startupCs = new FileInfo(Path.Combine(projectParent.FullName, "Startup.cs")); if (startupCs.Exists) { string moveTo = startupCs.FullName.GetNextFileName(); File.Move(startupCs.FullName, moveTo); Message.PrintLine("Moved existing Startup.cs file to {0}", ConsoleColor.Yellow, moveTo); } HandlebarsDirectory handlebarsDirectory = ShellProvider.GetHandlebarsDirectory(); handlebarsDirectory.Render("Startup.cs", new { BaseNamespace = Path.GetFileNameWithoutExtension(csprojFile.Name) }).SafeWriteToFile(startupCs.FullName, true); } }