From 42874b6dc9ac6ae5a9b4872e905548744f723500 Mon Sep 17 00:00:00 2001 From: fwcd Date: Thu, 19 Sep 2024 03:18:13 +0200 Subject: [PATCH] Vendor NodePackage wrapper ...and deprecate it upstream --- Sources/D2Commands/Math/LatexRenderer.swift | 2 +- Sources/D2Commands/NodePackage.swift | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 Sources/D2Commands/NodePackage.swift diff --git a/Sources/D2Commands/Math/LatexRenderer.swift b/Sources/D2Commands/Math/LatexRenderer.swift index 6ef1ca96..490eb3d1 100644 --- a/Sources/D2Commands/Math/LatexRenderer.swift +++ b/Sources/D2Commands/Math/LatexRenderer.swift @@ -15,6 +15,6 @@ class LatexRenderer { private func renderPNG(from formula: String, color: String, scale: Double) async throws -> Data { log.debug("Invoking latex-renderer") - return try await node.start(withArgs: [formula, "--color", color, "--scale", String(scale)]).get() + return try await node.start(withArgs: [formula, "--color", color, "--scale", String(scale)]) } } diff --git a/Sources/D2Commands/NodePackage.swift b/Sources/D2Commands/NodePackage.swift new file mode 100644 index 00000000..534b4af5 --- /dev/null +++ b/Sources/D2Commands/NodePackage.swift @@ -0,0 +1,17 @@ +import Foundation +import Utils + +/// A wrapper around an executable node package that is located in the `Node` +/// folder of this repository. +public struct NodePackage { + private let directoryURL: URL + + public init(name: String) { + directoryURL = URL(fileURLWithPath: "Node/\(name)") + } + + /// Invokes `npm start` with the given arguments. + public func start(withArgs args: [String]) async throws -> Data { + try await Shell().output(for: "npm", in: directoryURL, args: ["run", "--silent", "start", "--"] + args).get() + } +}