Skip to content

Commit a94358e

Browse files
committed
Support merging archives that don't have static hosting files
1 parent 60a271c commit a94358e

File tree

2 files changed

+109
-1
lines changed

2 files changed

+109
-1
lines changed

Sources/SwiftDocCUtilities/Action/Actions/MergeAction.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ struct MergeAction: Action {
171171
|| fileManager.directoryExists(atPath: $0.appendingPathComponent("tutorials").path)
172172
}
173173

174-
guard archivesWithStaticHostingSupport.count == nonEmptyArchives.count else {
174+
guard archivesWithStaticHostingSupport.count == nonEmptyArchives.count // All archives support static hosting
175+
|| archivesWithStaticHostingSupport.count == 0 // No archives support static hosting
176+
else {
175177
struct DifferentStaticHostingSupportError: DescribedError {
176178
var withSupport: Set<String>
177179
var withoutSupport: Set<String>

Tests/SwiftDocCUtilitiesTests/MergeActionTests.swift

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,112 @@ class MergeActionTests: XCTestCase {
219219
""")
220220
}
221221

222+
func testSupportsArchivesWithoutStaticHosting() throws {
223+
let fileSystem = try TestFileSystem(
224+
folders: [
225+
Folder(name: "Output.doccarchive", content: []),
226+
Self.makeArchive(
227+
name: "First",
228+
documentationPages: [
229+
"First",
230+
"First/SomeClass",
231+
"First/SomeClass/someProperty",
232+
"First/SomeClass/someFunction(:_)",
233+
],
234+
tutorialPages: [
235+
"First",
236+
"First/SomeTutorial",
237+
],
238+
images: ["something.png"],
239+
videos: ["something.mov"],
240+
downloads: ["something.zip"],
241+
supportsStaticHosting: false
242+
),
243+
Self.makeArchive(
244+
name: "Second",
245+
documentationPages: [
246+
"Second",
247+
"Second/SomeStruct",
248+
"Second/SomeStruct/someProperty",
249+
"Second/SomeStruct/someFunction(:_)",
250+
],
251+
tutorialPages: [
252+
"Second",
253+
"Second/SomeTutorial",
254+
],
255+
images: ["something.png"],
256+
videos: ["something.mov"],
257+
downloads: ["something.zip"],
258+
supportsStaticHosting: false
259+
),
260+
]
261+
)
262+
263+
let logStorage = LogHandle.LogStorage()
264+
var action = MergeAction(
265+
archives: [
266+
URL(fileURLWithPath: "/First.doccarchive"),
267+
URL(fileURLWithPath: "/Second.doccarchive"),
268+
],
269+
outputURL: URL(fileURLWithPath: "/Output.doccarchive"),
270+
fileManager: fileSystem
271+
)
272+
273+
_ = try action.perform(logHandle: .memory(logStorage))
274+
XCTAssertEqual(logStorage.text, "", "The action didn't log anything")
275+
276+
// The combined archive as the data and assets from the input archives but only one set of archive template files
277+
XCTAssertEqual(fileSystem.dump(subHierarchyFrom: "/Output.doccarchive"), """
278+
Output.doccarchive/
279+
├─ css/
280+
│ ╰─ something.css
281+
├─ data/
282+
│ ├─ documentation/
283+
│ │ ├─ first.json
284+
│ │ ├─ first/
285+
│ │ │ ├─ someclass.json
286+
│ │ │ ╰─ someclass/
287+
│ │ │ ├─ somefunction(:_).json
288+
│ │ │ ╰─ someproperty.json
289+
│ │ ├─ second.json
290+
│ │ ╰─ second/
291+
│ │ ├─ somestruct.json
292+
│ │ ╰─ somestruct/
293+
│ │ ├─ somefunction(:_).json
294+
│ │ ╰─ someproperty.json
295+
│ ╰─ tutorials/
296+
│ ├─ first.json
297+
│ ├─ first/
298+
│ │ ╰─ sometutorial.json
299+
│ ├─ second.json
300+
│ ╰─ second/
301+
│ ╰─ sometutorial.json
302+
├─ downloads/
303+
│ ├─ com.example.first/
304+
│ │ ╰─ something.zip
305+
│ ╰─ com.example.second/
306+
│ ╰─ something.zip
307+
├─ favicon.svg
308+
├─ images/
309+
│ ├─ com.example.first/
310+
│ │ ╰─ something.png
311+
│ ╰─ com.example.second/
312+
│ ╰─ something.png
313+
├─ img/
314+
│ ╰─ something.svg
315+
├─ index/
316+
│ ╰─ index.json
317+
├─ js/
318+
│ ╰─ something.js
319+
├─ metadata.json
320+
╰─ videos/
321+
├─ com.example.first/
322+
│ ╰─ something.mov
323+
╰─ com.example.second/
324+
╰─ something.mov
325+
""")
326+
}
327+
222328
func testErrorWhenArchivesContainOverlappingData() throws {
223329
let fileSystem = try TestFileSystem(
224330
folders: [

0 commit comments

Comments
 (0)