Skip to content

Commit

Permalink
Add filePaths property
Browse files Browse the repository at this point in the history
  • Loading branch information
pereBohigas committed Mar 23, 2024
1 parent 9af8ecc commit 3f1f43c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
13 changes: 12 additions & 1 deletion Sources/SwiftPolyglot/main.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import Foundation
import SwiftPolyglotCore

let swiftPolyglot: SwiftPolyglot = .init(arguments: CommandLine.arguments)
guard
let enumerator = FileManager.default.enumerator(atPath: FileManager.default.currentDirectoryPath),
let filePaths = enumerator.allObjects as? [String]
else {
exit(EXIT_FAILURE)
}

let swiftPolyglot: SwiftPolyglot = .init(
arguments: Array(CommandLine.arguments.dropFirst()),
filePaths: filePaths
)

do {
try swiftPolyglot.run()
Expand Down
21 changes: 9 additions & 12 deletions Sources/SwiftPolyglotCore/SwiftPolyglot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import Foundation

public struct SwiftPolyglot {
private let arguments: [String]
private let filePaths: [String]

public init(arguments: [String]) {
public init(arguments: [String], filePaths: [String]) {
self.arguments = arguments
self.filePaths = filePaths
}

public func run() throws {
Expand All @@ -17,9 +19,6 @@ public struct SwiftPolyglot {
let languages = arguments[0].split(separator: ",").map(String.init)
let errorOnMissing = arguments.contains("--errorOnMissing")

let fileManager = FileManager.default
let currentDirectoryPath = fileManager.currentDirectoryPath

var missingTranslations = false

func checkTranslations(in fileURL: URL, for languages: [String]) {
Expand Down Expand Up @@ -56,13 +55,11 @@ public struct SwiftPolyglot {
}
}

func searchDirectory(_ dirPath: String) {
if let enumerator = fileManager.enumerator(atPath: dirPath) {
for case let file as String in enumerator {
if file.hasSuffix(".xcstrings") {
let fileURL = URL(fileURLWithPath: dirPath).appendingPathComponent(file)
checkTranslations(in: fileURL, for: languages)
}
func searchDirectory() {
for filePath in filePaths {
if filePath.hasSuffix(".xcstrings") {
let fileURL = URL(fileURLWithPath: filePath)
checkTranslations(in: fileURL, for: languages)
}
}
}
Expand All @@ -79,7 +76,7 @@ public struct SwiftPolyglot {
}
}

searchDirectory(currentDirectoryPath)
searchDirectory()

if missingTranslations, errorOnMissing {
print("Error: One or more translations are missing.")
Expand Down

0 comments on commit 3f1f43c

Please sign in to comment.