public static void Render(DirectoryRenderArgs args)
        {
            var files = Directory.GetFiles(args.TemplateDirectory.FullName, "*", SearchOption.AllDirectories);

            var ignore      = new Ignore.Ignore();
            var ignoreFiles = args.Gitignore?.Exists == true;

            if (ignoreFiles)
            {
                var patterns = File
                               .ReadAllLines(args.Gitignore.FullName)
                               .Where(x =>
                                      !x.Trim().StartsWith("#") &&
                                      !string.IsNullOrWhiteSpace(x));
                ignore.Add(patterns);
            }

            foreach (var templateFile in files)
            {
                var templateFileInfo         = new FileInfo(templateFile);
                var templateFileRelativePath = templateFileInfo.FullName.Replace(args.TemplateDirectory.FullName, string.Empty).TrimStart('\\');

                if (ignoreFiles && ignore.IsIgnored(UseLinuxStyleRelativePath(templateFileRelativePath)))
                {
                    continue;
                }

                var outputFileInfo = new FileInfo(
                    Path.Combine(
                        args.OutputDirectory.FullName,
                        templateFileRelativePath));

                var fileRenderArgs = new FileRenderArgs
                {
                    TemplateFile      = templateFileInfo,
                    OutputFile        = outputFileInfo,
                    TemplateVariables = args.TemplateVariables,
                    TransformFilePath = args.TransformFilePath
                };

                FileTemplateRenderer.RenderFileFromTemplate(fileRenderArgs);
            }
Exemplo n.º 2
0
        public static async Task <IgnoreFile?> Create(
            string baseDirectoryPath,
            IFileSystem fileSystem,
            IConsole console,
            CancellationToken cancellationToken
            )
        {
            var ignore         = new Ignore.Ignore();
            var ignoreFilePath = FindIgnorePath(baseDirectoryPath, fileSystem);

            if (ignoreFilePath == null)
            {
                return(new IgnoreFile(ignore, baseDirectoryPath));
            }

            foreach (
                var line in await fileSystem.File.ReadAllLinesAsync(
                    ignoreFilePath,
                    cancellationToken
                    )
                )
            {
                try
                {
                    ignore.Add(line);
                }
                catch (Exception ex)
                {
                    console.WriteLine(
                        "The .csharpierignore file at "
                        + ignoreFilePath
                        + " could not be parsed due to the following line:"
                        );
                    console.WriteLine(line);
                    console.WriteLine("Exception: " + ex.Message);
                    return(null);
                }
            }

            return(new IgnoreFile(ignore, fileSystem.Path.GetDirectoryName(ignoreFilePath)));
        }
Exemplo n.º 3
0
 protected IgnoreFile(Ignore.Ignore ignore, string ignoreBaseDirectoryPath)
 {
     this.Ignore = ignore;
     this.IgnoreBaseDirectoryPath = ignoreBaseDirectoryPath.Replace('\\', '/');
 }