Esempio n. 1
0
        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);
                }
            }
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        public static void AspNetRazorInit()
        {
            // find the first csproj file by looking first in the current directory then going up
            // using the parent of the csproj as the root
            // - clone bam.js into wwwroot/bam.js
            // - write Startup.cs (backing up existing)
            // - write sample modules
            BamSettings   settings      = ShellProvider.GetSettings();
            DirectoryInfo projectParent = ShellProvider.FindProjectParent(out FileInfo csprojFile);

            if (csprojFile == null)
            {
                OutLine("Can't find csproj file", ConsoleColor.Magenta);

                Thread.Sleep(3000);
                Exit(1);
            }

            DirectoryInfo wwwroot = new DirectoryInfo(Path.Combine(projectParent.FullName, "wwwroot"));

            if (!wwwroot.Exists)
            {
                Warn("{0} doesn't exist, creating...", wwwroot.FullName);
                wwwroot.Create();
            }

            string bamJsPath = Path.Combine(wwwroot.FullName, "bam.js");

            if (!Directory.Exists(bamJsPath))
            {
                Message.PrintLine("Cloning bam.js to {0}", ConsoleColor.Yellow, bamJsPath);
                ProcessStartInfo cloneCommand =
                    settings.GitPath.ToStartInfo("clone https://github.com/BryanApellanes/bam.js.git wwwroot/bam.js");
                cloneCommand.Run(msg => OutLine(msg, ConsoleColor.DarkCyan));
            }

            WriteStartupCs(csprojFile);
            WriteBaseAppModules(csprojFile);
        }