Skip to content

Commit

Permalink
Default done file renamed to done.json; content is JSON (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
orchetect committed Dec 30, 2022
1 parent 9ba63e1 commit aaa7d5a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Sources/MarkersExtractor/MarkersExtractor Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension MarkersExtractor {
public static func mediaSearchPaths(from fcpxml: FCPXMLFile) -> [URL] {
[fcpxml.defaultMediaSearchPath].compactMap { $0 }
}
public static let doneFilename = "done.txt"
public static let doneFilename = "done.json"
}

public enum Validation {
Expand Down
11 changes: 8 additions & 3 deletions Sources/MarkersExtractor/MarkersExtractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ extension MarkersExtractor {

if s.createDoneFile {
logger.info("Creating \(s.doneFilename.quoted) done file at \(outputPath.path.quoted).")
try saveDoneFile(at: outputPath, fileName: s.doneFilename, content: csvPath.path)
let doneFileContent = ["csvPath": csvPath.path]
try saveDoneFile(at: outputPath, fileName: s.doneFilename, content: doneFileContent)
}

logger.info("Done!")
Expand Down Expand Up @@ -178,11 +179,15 @@ extension MarkersExtractor {
// MARK: - Done File

extension MarkersExtractor {
private func saveDoneFile(at outputPath: URL, fileName: String, content: String) throws {
private func saveDoneFile<E: Encodable>(at outputPath: URL, fileName: String, content: E) throws {
let doneFile = outputPath.appendingPathComponent(fileName)

do {
try content.write(to: doneFile, atomically: true, encoding: .utf8)
let encoder = JSONEncoder()
encoder.outputFormatting = [.prettyPrinted]

let data = try encoder.encode(content)
try data.write(to: doneFile)
} catch {
throw MarkersExtractorError.runtimeError(
"Failed to create done file \(doneFile.path.quoted): \(error.localizedDescription)"
Expand Down

0 comments on commit aaa7d5a

Please sign in to comment.