|
| 1 | +// Licensed to Elasticsearch B.V under one or more agreements. |
| 2 | +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. |
| 3 | +// See the LICENSE file in the project root for more information |
| 4 | + |
| 5 | +using System.IO.Abstractions; |
| 6 | +using Elastic.Markdown.Exporters; |
| 7 | +using Microsoft.Extensions.Logging; |
| 8 | + |
| 9 | +namespace Documentation.Assembler.Exporters; |
| 10 | + |
| 11 | +public class ConfigurationExporter(ILoggerFactory logFactory, AssembleContext context) : IMarkdownExporter |
| 12 | +{ |
| 13 | + private readonly ILogger<ConfigurationExporter> _logger = logFactory.CreateLogger<ConfigurationExporter>(); |
| 14 | + |
| 15 | + /// <inheritdoc /> |
| 16 | + public ValueTask StartAsync(CancellationToken ctx = default) => default; |
| 17 | + |
| 18 | + /// <inheritdoc /> |
| 19 | + public ValueTask StopAsync(CancellationToken ctx = default) => default; |
| 20 | + |
| 21 | + /// <inheritdoc /> |
| 22 | + public ValueTask<bool> ExportAsync(MarkdownExportFileContext fileContext, CancellationToken ctx) => default; |
| 23 | + |
| 24 | + /// <inheritdoc /> |
| 25 | + public ValueTask<bool> FinishExportAsync(IDirectoryInfo outputFolder, CancellationToken ctx) |
| 26 | + { |
| 27 | + var fs = context.WriteFileSystem; |
| 28 | + var configFolder = fs.DirectoryInfo.New(Path.Combine(context.OutputDirectory.FullName, "config")); |
| 29 | + if (!configFolder.Exists) |
| 30 | + configFolder.Create(); |
| 31 | + |
| 32 | + _logger.LogInformation("Exporting configuration"); |
| 33 | + |
| 34 | + var assemblerConfig = context.ConfigurationFileProvider.AssemblerFile; |
| 35 | + _logger.LogInformation("Exporting {Name} to {ConfigFolder}", assemblerConfig.Name, configFolder.FullName); |
| 36 | + context.WriteFileSystem.File.Copy(assemblerConfig.FullName, Path.Combine(configFolder.FullName, assemblerConfig.Name), true); |
| 37 | + |
| 38 | + var navigationConfig = context.ConfigurationFileProvider.NavigationFile; |
| 39 | + _logger.LogInformation("Exporting {Name} to {ConfigFolder}", navigationConfig.Name, configFolder.FullName); |
| 40 | + context.WriteFileSystem.File.Copy(navigationConfig.FullName, Path.Combine(configFolder.FullName, navigationConfig.Name), true); |
| 41 | + |
| 42 | + var legacyUrlMappingsConfig = context.ConfigurationFileProvider.LegacyUrlMappingsFile; |
| 43 | + _logger.LogInformation("Exporting {Name} to {ConfigFolder}", legacyUrlMappingsConfig.Name, configFolder.FullName); |
| 44 | + context.WriteFileSystem.File.Copy(legacyUrlMappingsConfig.FullName, Path.Combine(configFolder.FullName, legacyUrlMappingsConfig.Name), true); |
| 45 | + |
| 46 | + var versionsConfig = context.ConfigurationFileProvider.VersionFile; |
| 47 | + _logger.LogInformation("Exporting {Name} to {ConfigFolder}", versionsConfig.Name, configFolder.FullName); |
| 48 | + context.WriteFileSystem.File.Copy(versionsConfig.FullName, Path.Combine(configFolder.FullName, versionsConfig.Name), true); |
| 49 | + |
| 50 | + return default; |
| 51 | + } |
| 52 | +} |
0 commit comments