private string GetTemplatePackReportLineFor(TemplatePackReportInternalSummaryInfo info)
        {
            Debug.Assert(info != null);

            var line = $"{ReplaceComma(info.PackageName)},{ReplaceComma(info.Version)},{info.HasLibFolder}, {ReplaceComma(GetTemplatePackReportStringFor(info.PackageType))},{info.DownloadCount}";

            return(line);
        }
        private void CreateTemplatePackFile(List <TemplatePack> templatePacks, string templateReportJsonPath, string resultsPath)
        {
            // write the results to a temp file, and then copy to the final destination
            var tempfilepath = Path.GetTempFileName();

            //var templatePacks = TemplatePack.CreateFromFile(templateReportJsonPath);
            using var writer = new StreamWriter(tempfilepath);
            writer.WriteLine("package name, version, has lib folder, packagetype,num-downloads");
            foreach (var tp in templatePacks)
            {
                var info = new TemplatePackReportInternalSummaryInfo(_remoteFile.CacheFolderpath, tp);
                var line = GetTemplatePackReportLineFor(info);
                Console.WriteLine(line);
                writer.WriteLine(line);
            }
            writer.Flush();
            writer.Close();

            // string resultsPath = optionAnalysisResultFilePath.HasValue() ? optionAnalysisResultFilePath.Value() : "template-pack-analysis.csv";
            Console.WriteLine($"writing analysis file to {resultsPath}");
            File.Copy(tempfilepath, resultsPath, true);

            // now create the template-details.csv file
            var allTemplates     = new List <Template>();
            var allTemplateInfos = new List <TemplateReportSummaryInfo>();

            foreach (var tp in templatePacks)
            {
                var extractFolderPath = Path.Combine(_remoteFile.CacheFolderpath, "extracted", ($"{tp.Package}.{tp.Version}.nupkg").ToLowerInvariant());
                var templates         = TemplatePack.GetTemplateFilesUnder(extractFolderPath);
                foreach (var template in templates)
                {
                    var templateObj = Template.CreateFromFile(template);
                    allTemplates.Add(templateObj);
                    allTemplateInfos.Add(new TemplateReportSummaryInfo {
                        Template = templateObj
                    });
                }
            }
        }
        private void CreateTemplatePackFile(List <TemplatePack> templatePacks, string templateReportJsonPath, string resultsPath)
        {
            // write the results to a temp file, and then copy to the final destination
            var tempfilepath = Path.GetTempFileName();

            //var templatePacks = TemplatePack.CreateFromFile(templateReportJsonPath);
            using var writer = new StreamWriter(tempfilepath);
            writer.WriteLine("package name, version, has lib folder, packagetype,num-downloads");

            // list of template packs that could not be initalized for some reason
            // they need to be removed from the list to prevent futher issues
            var tpToRemove = new List <TemplatePack>();

            foreach (var tp in templatePacks)
            {
                TemplatePackReportInternalSummaryInfo info = null;
                try {
                    info = new TemplatePackReportInternalSummaryInfo(_remoteFile.CacheFolderpath, tp);
                }
                catch (TemplateInitException tie) {
                    // TODO: Reporter should be used instead of writing directly to the console
                    Console.WriteLine($"ERROR: Unable to initalize template pack from '{tp.Package}', skipping this one. Error: {tie.ToString()}");
                    tpToRemove.Add(tp);
                    continue;
                }
                var line = GetTemplatePackReportLineFor(info);
                Console.WriteLine(line);
                writer.WriteLine(line);
            }
            writer.Flush();
            writer.Close();

            if (tpToRemove.Count > 0)
            {
                foreach (var tp in tpToRemove)
                {
                    templatePacks.Remove(tp);
                }
            }

            // string resultsPath = optionAnalysisResultFilePath.HasValue() ? optionAnalysisResultFilePath.Value() : "template-pack-analysis.csv";
            var dir = Path.GetDirectoryName(resultsPath);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            Console.WriteLine($"writing analysis file to {resultsPath}");
            File.Copy(tempfilepath, resultsPath, true);

            // now create the template-details.csv file
            var allTemplates     = new List <Template>();
            var allTemplateInfos = new List <TemplateReportSummaryInfo>();

            foreach (var tp in templatePacks)
            {
                var extractFolderPath = Path.Combine(_remoteFile.CacheFolderpath, "extracted", ($"{tp.Package}.{tp.Version}.nupkg").ToLowerInvariant());
                var templates         = TemplatePack.GetTemplateFilesUnder(extractFolderPath);
                foreach (var template in templates)
                {
                    // TODO: null check is needed here
                    var templateObj = Template.CreateFromFile(template);
                    if (templateObj != null)
                    {
                        allTemplates.Add(templateObj);
                        allTemplateInfos.Add(new TemplateReportSummaryInfo {
                            Template = templateObj
                        });
                    }
                    else
                    {
                        Console.WriteLine($"unable to initalize template from path '{template.ToString()}'");
                    }
                }
            }
        }