Skip to content

Commit

Permalink
Resolved missing resources bundle for compiled CLI executable (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
orchetect committed Jan 1, 2023
1 parent c5f679f commit af5fdbc
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 84 deletions.
3 changes: 1 addition & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let package = Package(
products: [
.library(
name: "MarkersExtractor",
type: .static,
targets: ["MarkersExtractor"]
),
.executable(
Expand All @@ -35,8 +36,6 @@ let package = Package(
.product(name: "CodableCSV", package: "CodableCSV"),
.product(name: "Pipeline", package: "Pipeline"),
.product(name: "TimecodeKit", package: "TimecodeKit")
], resources: [
.copy("Resources")
]
),
.testTarget(
Expand Down
92 changes: 92 additions & 0 deletions Sources/MarkersExtractor/EmbeddedResource.swift

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions Sources/MarkersExtractor/Export/ExportProfile Export.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension ExportProfile {
if !isVideoPresent {
logger.info("Media file has no video track, using video placeholder for markers.")

if let markerVideoPlaceholderData = Resource.marker_video_placeholder_mov.data {
if let markerVideoPlaceholderData = EmbeddedResource.marker_video_placeholder_mov.data {
videoPlaceholder = try TemporaryMediaFile(withData: markerVideoPlaceholderData)
videoPath = videoPlaceholder.url!
} else {
Expand Down Expand Up @@ -187,9 +187,7 @@ extension ExportProfile {

for icon in icons {
let targetURL = outputDir.appendingPathComponent(icon.fileName)
if let iconURL = icon.url {
try FileManager.default.copyItem(at: iconURL, to: targetURL)
}
try icon.data.write(to: targetURL)
}
}

Expand Down
28 changes: 15 additions & 13 deletions Sources/MarkersExtractor/Extensions/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,21 @@ extension FourCharCode {
}

extension URL {
/// Form a URL to a resource file contained within this Swift package.
init?(
moduleResource: String,
withExtension: String,
subFolder: String? = nil
) {
guard let url = Bundle.module.url(
forResource: moduleResource,
withExtension: withExtension,
subdirectory: subFolder
) else { return nil }
self = url
}

// Note: this only compiles if Package.swift contains `.resources: []` for this package target
// /// Form a URL to a resource file contained within this Swift package.
//init?(
// moduleResource: String,
// withExtension: String,
// subFolder: String? = nil
//) {
// guard let url = Bundle.module.url(
// forResource: moduleResource,
// withExtension: withExtension,
// subdirectory: subFolder
// ) else { return nil }
// self = url
//}

var exists: Bool { FileManager.default.fileExists(atPath: path) }

Expand Down
10 changes: 5 additions & 5 deletions Sources/MarkersExtractor/Marker/Marker Icon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extension Marker {
case todo
case standard

var resource: Resource {
var resource: EmbeddedResource {
switch self {
case .chapter: return .marker_chapter_png
case .completed: return .marker_completed_png
Expand All @@ -33,12 +33,12 @@ extension Marker {
}
}

var url: URL? {
resource.url
}

var fileName: String {
resource.fileName
}

var data: Data {
resource.data ?? Data()
}
}
}
2 changes: 1 addition & 1 deletion Sources/MarkersExtractor/MarkersExtractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extension MarkersExtractor {
return
}

if !Resource.validateAll() {
if !EmbeddedResource.validateAll() {
logger.warning(
"Could not validate internal resource files. Export may not work correctly."
)
Expand Down
59 changes: 0 additions & 59 deletions Sources/MarkersExtractor/Resource.swift

This file was deleted.

0 comments on commit af5fdbc

Please sign in to comment.