mirror of
https://github.com/ViennaRSS/vienna-rss.git
synced 2026-06-06 19:37:49 +00:00
This requires macOS 13 and Xcode 14.3 (Swift 5.8). The ProcessPredicateLocalizations source uses Regex, which requires macOS 13 and Swift 5.7. The ProcessPredicateLocalizations source also uses "bare slash literals", which is an upcoming feature of Swift that requires the `.enableUpcomingFeature` setting (Swift 5.8+) to work in Swift 5.8.
86 lines
2.8 KiB
Swift
86 lines
2.8 KiB
Swift
//
|
|
// CombinePredicateLocalizations.swift
|
|
// ProcessPredicateLocalizations
|
|
//
|
|
// Copyright 2023
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//
|
|
|
|
import Foundation
|
|
import PackagePlugin
|
|
import XcodeProjectPlugin
|
|
|
|
let targetDisplayName = "Vienna"
|
|
let baseLocalization = "Base.lproj"
|
|
let stringsFileName = "Predicates.strings"
|
|
let toolName = "ProcessPredicateLocalizations"
|
|
let toolMode = "combine"
|
|
|
|
@main
|
|
struct CombinePredicateLocalizations: CommandPlugin {
|
|
|
|
func performCommand(context: PluginContext, arguments: [String]) async throws {
|
|
throw PluginDeserializationError.internalError("Not implemented")
|
|
}
|
|
|
|
}
|
|
|
|
extension CombinePredicateLocalizations: XcodeCommandPlugin {
|
|
|
|
func performCommand(context: XcodePluginContext, arguments: [String]) throws {
|
|
guard
|
|
let target = context.xcodeProject.targets.first(where: { target in
|
|
target.displayName == targetDisplayName
|
|
})
|
|
else {
|
|
Diagnostics.error("This plug-in only works for the \(targetDisplayName) target")
|
|
return
|
|
}
|
|
|
|
let stringsFiles = target.inputFiles.filter { file in
|
|
file.path.lastComponent == stringsFileName
|
|
}
|
|
|
|
let tool = try context.tool(named: toolName)
|
|
for stringsFile in stringsFiles {
|
|
do {
|
|
let process = Process()
|
|
process.executableURL = URL(
|
|
fileURLWithPath: tool.path.string,
|
|
isDirectory: false
|
|
)
|
|
let filePath = stringsFile.path.string
|
|
process.arguments = [toolMode, filePath]
|
|
let outputPipe = Pipe()
|
|
process.standardOutput = outputPipe
|
|
|
|
Diagnostics.remark("Process file: \(stringsFile.path)")
|
|
try process.run()
|
|
process.waitUntilExit()
|
|
|
|
let outputData = try outputPipe.fileHandleForReading.readToEnd()
|
|
if !FileManager.default.createFile(
|
|
atPath: filePath,
|
|
contents: outputData
|
|
) {
|
|
Diagnostics.error("Failed to change file \(stringsFile.path)")
|
|
}
|
|
} catch {
|
|
Diagnostics.error("Failed to process file \(stringsFile.path)")
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|