예제 #1
0
        public static async Task <string> GenerateTemplatesAsync(string templateName, string targetFolder, string elementName, bool isGlobal = false)
        {
            string templateText;

            using (var reader = new StreamReader(templateName))
            {
                templateText = await reader.ReadToEndAsync();
            }

            var fileName              = Path.GetFileName(templateName);
            var parts                 = fileName.Split('.');
            var extension             = parts[parts.Length - 2];
            var pascalCaseElementName = elementName.ToPascalCase();
            var kebabCase             = pascalCaseElementName.PascalToKebabCase();
            var fullFileName          = Path.Combine(targetFolder, kebabCase, $"{kebabCase}.{extension}");

            templateText = templateText.Replace("%name%", pascalCaseElementName);
            templateText = templateText.Replace("%properties%", "");
            Directory.CreateDirectory(Path.GetDirectoryName(fullFileName));
            File.WriteAllText(fullFileName, templateText);

            if (isGlobal && (extension.ToLower() == "js" || extension.ToLower() == "ts"))
            {
                AureliaHelper.AddGlobalResource(fullFileName);
            }
            return(fullFileName);
        }
예제 #2
0
파일: Template.cs 프로젝트: aurelia/dotnet
        public static async Task <string> GenerateTemplatesAsync(string templateName, string targetFolder, string elementName, bool isGlobal = false)
        {
            string templateText;

            using (var reader = new StreamReader(templateName))
            {
                templateText = await reader.ReadToEndAsync();
            }

            var customIndex = elementName.IndexOf("Custom", StringComparison.InvariantCultureIgnoreCase);

            customIndex = customIndex > 0 ? customIndex : elementName.IndexOf("BindingBehavior", StringComparison.InvariantCultureIgnoreCase);
            customIndex = customIndex > 0 ? customIndex : elementName.IndexOf("ValueConverter", StringComparison.InvariantCultureIgnoreCase);
            elementName = elementName.Substring(0, customIndex > 0 ? customIndex : elementName.Length);

            var fileName              = Path.GetFileName(templateName);
            var parts                 = fileName.Split('.');
            var extension             = parts[parts.Length - 2];
            var pascalCaseElementName = elementName.ToPascalCase();
            var kebabCase             = pascalCaseElementName.PascalToKebabCase();
            var fullFileName          = Path.Combine(targetFolder, kebabCase, $"{kebabCase}.{extension}");

            templateText = templateText.Replace("%name%", pascalCaseElementName);
            templateText = templateText.Replace("%properties%", "");
            Directory.CreateDirectory(Path.GetDirectoryName(fullFileName));
            File.WriteAllText(fullFileName, templateText);

            if (templateName.Equals("feature"))
            {
                AureliaHelper.AddFeatureToConfigure(targetFolder);
            }

            if (isGlobal && (extension.ToLower() == "js" || extension.ToLower() == "ts"))
            {
                AureliaHelper.AddGlobalResource(fullFileName);
            }
            return(fullFileName);
        }