Skip to content

Commit 79bda2e

Browse files
authored
Merge pull request #639 from PassiveLogic/kr/bridgejs-skip-unchanged-writes
BridgeJS: Skip writing output files when content is unchanged
2 parents 809487c + 96c691b commit 79bda2e

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Plugins/BridgeJS/Sources/BridgeJSTool/BridgeJSTool.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ import BridgeJSUtilities
226226
withIntermediateDirectories: true,
227227
attributes: nil
228228
)
229-
try outputSwift.write(to: outputSwiftURL, atomically: true, encoding: .utf8)
229+
try writeIfChanged(outputSwift, to: outputSwiftURL)
230230
}
231231
}
232232

@@ -241,7 +241,7 @@ import BridgeJSUtilities
241241
let encoder = JSONEncoder()
242242
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
243243
let skeletonData = try encoder.encode(skeleton)
244-
try skeletonData.write(to: outputSkeletonURL)
244+
try writeIfChanged(skeletonData, to: outputSkeletonURL)
245245
}
246246

247247
if skeleton.exported != nil || skeleton.imported != nil {
@@ -283,6 +283,18 @@ private func hasBridgeJSSkipComment(_ content: String) -> Bool {
283283
BridgeJSGeneratedFile.hasSkipComment(content)
284284
}
285285

286+
private func writeIfChanged(_ content: String, to url: URL) throws {
287+
let existing = try? String(contentsOf: url, encoding: .utf8)
288+
guard existing != content else { return }
289+
try content.write(to: url, atomically: true, encoding: .utf8)
290+
}
291+
292+
private func writeIfChanged(_ data: Data, to url: URL) throws {
293+
let existing = try? Data(contentsOf: url)
294+
guard existing != data else { return }
295+
try data.write(to: url)
296+
}
297+
286298
private func combineGeneratedSwift(_ pieces: [String]) -> String {
287299
let trimmedPieces =
288300
pieces

0 commit comments

Comments
 (0)