private static void WriteToFile(IDocumentResult result, PSDocumentOption option, IPipelineWriter writer, ShouldProcess shouldProcess) { var rootedPath = PSDocumentOption.GetRootedPath(option.Output.Path); var filePath = !string.IsNullOrEmpty(result.Culture) && option.Output?.Culture?.Length > 1 ? Path.Combine(rootedPath, result.Culture, result.Name) : Path.Combine(rootedPath, result.Name); var parentPath = Directory.GetParent(filePath); if (!parentPath.Exists && shouldProcess(target: parentPath.FullName, action: PSDocsResources.ShouldCreatePath)) { Directory.CreateDirectory(path: parentPath.FullName); } if (shouldProcess(target: rootedPath, action: PSDocsResources.ShouldWriteFile)) { var encoding = GetEncoding(option.Markdown.Encoding.Value); File.WriteAllText(filePath, result.ToString(), encoding); // Write file info instead var fileInfo = new FileInfo(filePath); writer.WriteObject(fileInfo, false); } }
private static void WriteToFile(IDocumentResult result, PSDocumentOption option, IPipelineWriter writer, ShouldProcess shouldProcess) { // Calculate paths var fileName = string.Concat(result.InstanceName, result.Extension); var outputPath = PSDocumentOption.GetRootedPath(result.OutputPath); var filePath = Path.Combine(outputPath, fileName); var parentPath = Directory.GetParent(filePath); if (!parentPath.Exists && shouldProcess(target: parentPath.FullName, action: PSDocsResources.ShouldCreatePath)) { Directory.CreateDirectory(path: parentPath.FullName); } if (shouldProcess(target: outputPath, action: PSDocsResources.ShouldWriteFile)) { var encoding = GetEncoding(option.Markdown.Encoding.Value); File.WriteAllText(filePath, result.ToString(), encoding); // Write file info instead var fileInfo = new FileInfo(filePath); writer.WriteObject(fileInfo, false); } }
private static void WriteToString(IDocumentResult result, bool enumerate, IPipelineWriter writer) { writer.WriteObject(result.ToString(), enumerate); }