96 lines
2.5 KiB
Swift
96 lines
2.5 KiB
Swift
import CommandClient
|
|
import ConfigurationClient
|
|
import Dependencies
|
|
import DependenciesMacros
|
|
|
|
public extension DependencyValues {
|
|
var pandocClient: PandocClient {
|
|
get { self[PandocClient.self] }
|
|
set { self[PandocClient.self] = newValue }
|
|
}
|
|
}
|
|
|
|
@DependencyClient
|
|
public struct PandocClient: Sendable {
|
|
|
|
public var run: Run
|
|
|
|
@DependencyClient
|
|
public struct Run: Sendable {
|
|
public var generateLatex: @Sendable (RunOptions) async throws -> String
|
|
public var generateHtml: @Sendable (RunOptions) async throws -> String
|
|
public var generatePdf: @Sendable (RunOptions, String?) async throws -> String
|
|
|
|
public func generatePdf(
|
|
_ options: RunOptions,
|
|
pdfEngine: String? = nil
|
|
) async throws -> String {
|
|
try await generatePdf(options, pdfEngine)
|
|
}
|
|
|
|
}
|
|
|
|
public struct RunOptions: Equatable, Sendable {
|
|
|
|
let buildDirectory: String?
|
|
let extraOptions: [String]?
|
|
let files: [String]?
|
|
let loggingOptions: LoggingOptions
|
|
let includeInHeader: [String]?
|
|
let outputDirectory: String?
|
|
let outputFileName: String?
|
|
let projectDirectory: String?
|
|
let quiet: Bool
|
|
let shell: String?
|
|
let shouldBuild: Bool
|
|
|
|
public init(
|
|
buildDirectory: String? = nil,
|
|
extraOptions: [String]? = nil,
|
|
files: [String]? = nil,
|
|
loggingOptions: LoggingOptions,
|
|
includeInHeader: [String]? = nil,
|
|
outputDirectory: String? = nil,
|
|
projectDirectory: String? = nil,
|
|
outputFileName: String? = nil,
|
|
quiet: Bool = false,
|
|
shell: String? = nil,
|
|
shouldBuild: Bool = true
|
|
) {
|
|
self.buildDirectory = buildDirectory
|
|
self.extraOptions = extraOptions
|
|
self.files = files
|
|
self.loggingOptions = loggingOptions
|
|
self.includeInHeader = includeInHeader
|
|
self.outputDirectory = outputDirectory
|
|
self.outputFileName = outputFileName
|
|
self.projectDirectory = projectDirectory
|
|
self.quiet = quiet
|
|
self.shell = shell
|
|
self.shouldBuild = shouldBuild
|
|
}
|
|
|
|
}
|
|
|
|
@_spi(Internal)
|
|
public enum FileType: Equatable, Sendable {
|
|
case html
|
|
case latex
|
|
case pdf(engine: String?)
|
|
}
|
|
}
|
|
|
|
extension PandocClient: DependencyKey {
|
|
public static let testValue: PandocClient = Self(run: Run())
|
|
|
|
public static var liveValue: PandocClient {
|
|
.init(
|
|
run: Run(
|
|
generateLatex: { try await $0.run(.latex) },
|
|
generateHtml: { try await $0.run(.html) },
|
|
generatePdf: { try await $0.run(.pdf(engine: $1)) }
|
|
)
|
|
)
|
|
}
|
|
}
|