Skip to content

Commit a1f1685

Browse files
Improve directory URL naming (and mocks) (#593)
1 parent 093a74e commit a1f1685

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

Sources/NodesXcodeTemplatesGenerator/XcodeTemplateGenerator.swift

+9-9
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ internal final class XcodeTemplateGenerator {
1212
self.fileSystem = fileSystem
1313
}
1414

15-
internal func generate(template: XcodeTemplate, into url: URL) throws {
16-
let url: URL = url
15+
internal func generate(template: XcodeTemplate, into directory: URL) throws {
16+
let url: URL = directory
1717
.appendingPathComponent(template.name)
1818
.appendingPathExtension("xctemplate")
1919
try? fileSystem.removeItem(at: url)
@@ -23,36 +23,36 @@ internal final class XcodeTemplateGenerator {
2323
try copyIcons(into: url)
2424
}
2525

26-
private func renderStencils(for template: XcodeTemplate, into url: URL) throws {
26+
private func renderStencils(for template: XcodeTemplate, into directory: URL) throws {
2727
let stencilRenderer: StencilRenderer = .init()
2828
try template.stencils.forEach { stencil in
2929
let contents: String = try stencilRenderer.render(stencil, with: template.stencilContext.dictionary)
3030
try fileSystem.write(Data(contents.utf8),
31-
to: url
31+
to: directory
3232
.appendingPathComponent("___FILEBASENAME___\(stencil.name)")
3333
.appendingPathExtension("swift"),
3434
atomically: true)
3535
}
3636
}
3737

38-
private func writePropertyList(for template: XcodeTemplate, into url: URL) throws {
38+
private func writePropertyList(for template: XcodeTemplate, into directory: URL) throws {
3939
try fileSystem.write(template.propertyList.encode(),
40-
to: url
40+
to: directory
4141
.appendingPathComponent("TemplateInfo")
4242
.appendingPathExtension("plist"),
4343
atomically: true)
4444
}
4545

46-
private func copyIcons(into url: URL) throws {
46+
private func copyIcons(into directory: URL) throws {
4747
let bundle: Bundle = .moduleRelativeToExecutable ?? .module
4848
// swiftlint:disable:next force_unwrapping
4949
try fileSystem.copyItem(at: bundle.url(forResource: "Tinder", withExtension: "png")!,
50-
to: url
50+
to: directory
5151
.appendingPathComponent("TemplateIcon")
5252
.appendingPathExtension("png"))
5353
// swiftlint:disable:next force_unwrapping
5454
try fileSystem.copyItem(at: bundle.url(forResource: "Tinder@2x", withExtension: "png")!,
55-
to: url
55+
to: directory
5656
.appendingPathComponent("TemplateIcon@2x")
5757
.appendingPathExtension("png"))
5858
}

Sources/NodesXcodeTemplatesGenerator/XcodeTemplates.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ public final class XcodeTemplates {
2020
public func generate(
2121
identifier: String
2222
) throws {
23-
let url: URL = fileSystem.libraryURL
23+
let directory: URL = fileSystem.libraryURL
2424
.appendingPathComponent("Developer")
2525
.appendingPathComponent("Xcode")
2626
.appendingPathComponent("Templates")
2727
.appendingPathComponent("File Templates")
2828
.appendingPathComponent("Nodes Architecture Framework (\(identifier))")
29-
try? fileSystem.removeItem(at: url)
30-
try generate(at: url)
29+
try? fileSystem.removeItem(at: directory)
30+
try generate(into: directory)
3131
}
3232

3333
public func generate(
34-
at url: URL
34+
into directory: URL
3535
) throws {
3636
var templates: [XcodeTemplate] = UIFramework.Kind
3737
.allCases
@@ -46,6 +46,6 @@ public final class XcodeTemplates {
4646
WorkerXcodeTemplate(config: config)
4747
]
4848
let generator: XcodeTemplateGenerator = .init(fileSystem: fileSystem)
49-
try templates.forEach { try generator.generate(template: $0, into: url) }
49+
try templates.forEach { try generator.generate(template: $0, into: directory) }
5050
}
5151
}

Tests/NodesXcodeTemplatesGeneratorTests/ConfigTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ final class ConfigTests: XCTestCase, TestFactories {
2323

2424
func testConfig() throws {
2525
let fileSystem: FileSystemMock = .init()
26-
let url: URL = .init(fileURLWithPath: "/")
26+
let url: URL = .init(fileURLWithPath: "/", isDirectory: true)
2727
fileSystem.contents[url] = Data(givenConfig().utf8)
2828
let config: Config = try .init(at: url.path, using: fileSystem)
2929
assertSnapshot(of: config, as: .dump)
3030
}
3131

3232
func testConfigWithEmptyFileContents() throws {
3333
let fileSystem: FileSystemMock = .init()
34-
let url: URL = .init(fileURLWithPath: "/")
34+
let url: URL = .init(fileURLWithPath: "/", isDirectory: true)
3535
fileSystem.contents[url] = Data("".utf8)
3636
let config: Config = try .init(at: url.path, using: fileSystem)
3737
expect(config) == Config()

Tests/NodesXcodeTemplatesGeneratorTests/XcodeTemplatesTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ final class XcodeTemplatesTests: XCTestCase {
2121

2222
func testGenerateWithURL() throws {
2323
let fileSystem: FileSystemMock = .init()
24-
let url: URL = .init(fileURLWithPath: "/")
25-
try XcodeTemplates(config: givenConfig(), fileSystem: fileSystem).generate(at: url)
24+
let url: URL = .init(fileURLWithPath: "/", isDirectory: true)
25+
try XcodeTemplates(config: givenConfig(), fileSystem: fileSystem).generate(into: url)
2626
// swiftlint:disable:next large_tuple
2727
let writes: [(contents: String, path: String, atomically: Bool)] = fileSystem.writes
2828
writes.forEach { assertSnapshot(of: $0.contents, as: .lines, named: "Contents.\(name(from: $0.path))") }

0 commit comments

Comments
 (0)