Ejemplo n.º 1
0
        private void AddPage(FileInfo csprojFile, string pageName)
        {
            DirectoryInfo   projectParent   = csprojFile.Directory;
            string          appName         = Path.GetFileNameWithoutExtension(csprojFile.Name);
            DirectoryInfo   pagesDirectory  = new DirectoryInfo(Path.Combine(projectParent.FullName, "Pages"));
            PageRenderModel pageRenderModel = new PageRenderModel {
                BaseNamespace = $"{appName}", PageName = pageName
            };

            HandlebarsDirectory handlebarsDirectory = GetHandlebarsDirectory();

            string csHtmlFilePath = Path.Combine(pagesDirectory.FullName, $"{pageName}.cshtml");

            if (!File.Exists(csHtmlFilePath))
            {
                EnsureDirectoryExists(csHtmlFilePath);
                string pageContent = handlebarsDirectory.Render("Page.cshtml", pageRenderModel);
                Message.PrintLine("Writing page file {0}", ConsoleColor.Cyan, csHtmlFilePath);
                pageContent.SafeWriteToFile(csHtmlFilePath, true);
            }

            string csHtmlcsFilePath = $"{csHtmlFilePath}.cs";

            if (!File.Exists(csHtmlcsFilePath))
            {
                EnsureDirectoryExists(csHtmlcsFilePath);
                string codeBehindContent = handlebarsDirectory.Render("Page.cshtml.cs", pageRenderModel);
                Message.PrintLine("Writing code behind file {0}", ConsoleColor.DarkCyan, csHtmlcsFilePath);
                codeBehindContent.SafeWriteToFile(csHtmlcsFilePath, true);
            }

            AddWebPackConfig(csprojFile, pageName);
        }
Ejemplo n.º 2
0
        private void AddWebPackConfig(FileInfo csprojFile, string pageName)
        {
            DirectoryInfo wwwroot       = new DirectoryInfo(Path.Combine(csprojFile.Directory.FullName, "wwwroot"));
            DirectoryInfo projectParent = csprojFile.Directory;
            string        appName       = Path.GetFileNameWithoutExtension(csprojFile.Name);
            string        wwwrootPath   = wwwroot.FullName;

            if (!wwwrootPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
            {
                wwwrootPath += Path.DirectorySeparatorChar.ToString();
            }
            PageRenderModel pageRenderModel = new PageRenderModel {
                BaseNamespace = $"{appName}", PageName = pageName, WwwRoot = wwwrootPath
            };

            HandlebarsDirectory handlebarsDirectory = GetHandlebarsDirectory();
            string pageJsPath        = Path.Combine(wwwroot.FullName, "bam.js", "pages", $"{pageName}.js");
            string webPackConfigPath = Path.Combine(wwwroot.FullName, "bam.js", "configs", pageName, "webpack.config.js");

            if (!File.Exists(pageJsPath))
            {
                Message.PrintLine("Writing page JavaScript file {0}", ConsoleColor.Blue, pageJsPath);
                handlebarsDirectory.Render("Page.js", pageRenderModel).SafeWriteToFile(pageJsPath, true);
            }
            if (!File.Exists(webPackConfigPath))
            {
                Message.PrintLine("Writing web pack config file {0}", ConsoleColor.DarkBlue, webPackConfigPath);
                handlebarsDirectory.Render("Webpack.config.js", pageRenderModel).SafeWriteToFile(webPackConfigPath, true);
            }
        }
Ejemplo n.º 3
0
        public override void Build(Action <string> output = null, Action <string> error = null)
        {
            DirectoryInfo       projectParent = ShellProvider.GetProjectParentDirectoryOrExit(out FileInfo csprojFile);
            BamSettings         settings      = ShellProvider.GetSettings();
            HandlebarsDirectory handlebars    = ShellProvider.GetHandlebarsDirectory();
            string projectName        = Path.GetFileNameWithoutExtension(csprojFile.Name);
            string dockerFileContents = handlebars.Render("Dockerfile", new { AspNetCoreEnvironment = settings.Environment, ProjectName = projectName });
            string startDir           = Environment.CurrentDirectory;

            Environment.CurrentDirectory = projectParent.FullName;
            string dockerFile = Path.Combine(".", "Dockerfile");

            dockerFileContents.SafeWriteToFile(dockerFile, true);
            ProcessStartInfo startInfo = settings.DockerPath.ToStartInfo($"tag {projectName} bamapps/containers:{projectName}");
            ProcessOutput    tagOutput = startInfo.Run(msg => OutLine(msg, ConsoleColor.Blue));

            Environment.CurrentDirectory = startDir;
            if (tagOutput.ExitCode != 0)
            {
                Message.PrintLine("docker tag command failed: {0}\r\n{1}", tagOutput.StandardOutput, tagOutput.StandardError);
                Exit(1);
            }
            ProcessOutput pushOutput = settings.DockerPath.ToStartInfo("push bamapps/containers:{projectName}").Run(msg => OutLine(msg, ConsoleColor.DarkCyan));

            if (tagOutput.ExitCode != 0)
            {
                Message.PrintLine("docker push command failed: {0}\r\n{1}", tagOutput.StandardOutput, tagOutput.StandardError);
                Exit(1);
            }
        }
Ejemplo n.º 4
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);
                }
            }
        }
Ejemplo n.º 5
0
        public static Tag CreateFromTemplate(TemplateAttribute templateAttribute, object data = null)
        {
            HandlebarsDirectory directory = new HandlebarsDirectory(templateAttribute.DirectoryPath ?? "./Handlebars");
            Tag result = Tags.Span();

            result.Content = directory.Render(templateAttribute.Name, data);
            return(result);
        }
        private HandlebarsDirectory GetHandlebarsDirectory(string templateName)
        {
            HandlebarsDirectory toUse = HandlebarsDirectories.FirstOrDefault(h => h.HasTemplate(templateName));

            if (HandlebarsDirectories.Count(h => h.HasTemplate(templateName)) > 1)
            {
                (Logger ?? Log.Default).Info("Multiple templates named {0} were found, using {1}", templateName, Path.Combine(toUse.Directory.FullName, templateName));
            }

            return(toUse);
        }
Ejemplo n.º 7
0
        public CoreNotificationService(DataSettings dataSettings, ILogger logger = null)
        {
            Logger       = logger ?? Log.Default;
            DataSettings = dataSettings;
            string emailTemplatesDirectory = dataSettings.GetEmailTemplatesDirectory().FullName;

            NotificationTemplateDirectory = new DirectoryInfo(Path.Combine(dataSettings.GetRootDataDirectory().FullName, "NotificationTemplates"));
            Templates = new HandlebarsDirectory(NotificationTemplateDirectory);
            Tld       = "com";
            Templates.Reload();
        }
Ejemplo n.º 8
0
        public NotificationService(IUserManager userManager, SmtpSettingsProvider smtpSettingsProvider, ILogger logger)
        {
            UserManager          = userManager;
            SmtpSettingsProvider = smtpSettingsProvider ?? DataSettingsSmtpSettingsProvider.Default;
            Logger = logger ?? Log.Default;
            string emailTemplatesDirectory = DataSettings.Current.GetSysEmailTemplatesDirectory().FullName;

            NotificationTemplateDirectory = new DirectoryInfo(Path.Combine(DataSettings.Current.GetRootDataDirectory().FullName, "NotificationTemplates"));
            Templates = new HandlebarsDirectory(NotificationTemplateDirectory);
            Tld       = "com";
            Templates.Reload();
        }
Ejemplo n.º 9
0
        private static void EnsureTemplatesAreLoaded()
        {
            Args.ThrowIf(HandlebarsDirectory == null && HandlebarsEmbeddedResources == null, "Must specify at least one of Handlebars.HandlebarsDirectory or Handlebars.EmbeddedResources");
            if (HandlebarsDirectory != null && !HandlebarsDirectory.IsLoaded)
            {
                HandlebarsDirectory.Reload();
            }

            if (HandlebarsEmbeddedResources != null && !HandlebarsEmbeddedResources.IsLoaded)
            {
                HandlebarsEmbeddedResources.Reload();
            }
        }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
0
        public static void Render(string templateName, object renderModel, Stream output)
        {
            EnsureTemplatesAreLoaded();
            if ((HandlebarsDirectory?.Templates?.ContainsKey(templateName)) == true)
            {
                string code = HandlebarsDirectory.Render(templateName, renderModel);

                code.WriteToStream(output, false);
            }
            else if ((HandlebarsEmbeddedResources?.Templates?.ContainsKey(templateName)) == true)
            {
                string code = HandlebarsEmbeddedResources.Render(templateName, renderModel);
                code.WriteToStream(output, false);
            }
            else
            {
                Args.Throw <InvalidOperationException>("Specified template ('{0}') not found", templateName);
            }
        }
        public void Render(string templateName, object renderModel, Stream output, bool dispose = false)
        {
            HandlebarsDirectory handlebarsDirectory = GetHandlebarsDirectory(templateName);

            if (handlebarsDirectory != null)
            {
                string code = handlebarsDirectory.Render(templateName, renderModel);
                code.WriteToStream(output, dispose);
            }
            else if ((HandlebarsEmbeddedResources?.Templates?.ContainsKey(templateName)) == true)
            {
                string code = HandlebarsEmbeddedResources.Render(templateName, renderModel);
                code.WriteToStream(output, dispose);
            }
            else
            {
                Args.Throw <InvalidOperationException>("Specified template {0} not found", templateName);
            }
        }
Ejemplo n.º 13
0
        public void RenderTags()
        {
            HandlebarsDirectory hbs = new HandlebarsDirectory("./Templates");
            string code             = string.Empty;
            string tagData          = "./Tags.txt".SafeReadFile();

            foreach (string line in tagData.DelimitSplit("\r\n"))
            {
                string tagName = line.ReadUntil('>', out string description);
                if (tagName.StartsWith("<"))
                {
                    tagName = tagName.TruncateFront(1).Trim();
                }

                code += hbs.Render("Tag", new TagDescriptor {
                    TagName = tagName, Description = description.Trim()
                });
            }
            FileInfo file = new FileInfo("./tags.cs");

            code.SafeWriteToFile(file.FullName, true);
            $"notepad {file.FullName}".Run();
        }
 public HandlebarsTemplateRenderer(HandlebarsEmbeddedResources handlebarsEmbeddedResources, HandlebarsDirectory handlebarsDirectory)
     : this(handlebarsEmbeddedResources, new HandlebarsDirectory[] { handlebarsDirectory })
 {
 }