diff --git a/Library/Resources/Files/Sources/License b/Library/Resources/Files/Sources/License index bea052c..05b900f 100644 --- a/Library/Resources/Files/Sources/License +++ b/Library/Resources/Files/Sources/License @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2024 Adam Fowler + Copyright 2025 Röck+Cöde Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/Library/Resources/Files/Templates/App/App.mustache b/Library/Resources/Files/Templates/App/App.mustache new file mode 100644 index 0000000..c33bcd7 --- /dev/null +++ b/Library/Resources/Files/Templates/App/App.mustache @@ -0,0 +1,20 @@ +import AppLibrary +import ArgumentParser + +@main +struct App: AsyncParsableCommand { + + // MARK: Properties + + @OptionGroup var options: Options + + // MARK: Functions + + mutating func run() async throws { + let builder = AppBuilder(name: "{{ name }}") + let app = try await builder(options) + + try await app.runService() + } + +} diff --git a/Library/Resources/Files/Templates/Package.mustache b/Library/Resources/Files/Templates/Package.mustache new file mode 100644 index 0000000..7d500db --- /dev/null +++ b/Library/Resources/Files/Templates/Package.mustache @@ -0,0 +1,45 @@ +// swift-tools-version:6.0 + +import PackageDescription + +let package = Package( + name: "{{ name }}", + platforms: [ + .macOS(.v14) + ], + products: [ + .executable(name: "App", targets: ["App"]), + .library(name: "AppLibrary", targets: ["AppLibrary"]) + ], + dependencies: [ + .package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0"), + .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.3.0") + ], + targets: [ + .executableTarget( + name: "App", + dependencies: [ + .product(name: "ArgumentParser", package: "swift-argument-parser"), + .product(name: "Hummingbird", package: "hummingbird"), + .target(name: "AppLibrary") + ], + path: "App" + ), + .target( + name: "AppLibrary", + dependencies: [ + .product(name: "ArgumentParser", package: "swift-argument-parser"), + .product(name: "Hummingbird", package: "hummingbird") + ], + path: "Library" + ), + .testTarget( + name: "AppTests", + dependencies: [ + .product(name: "HummingbirdTesting", package: "hummingbird"), + .target(name: "AppLibrary") + ], + path: "Test" + ) + ] +) diff --git a/Library/Resources/Files/Templates/Test/AppTests.mustache b/Library/Resources/Files/Templates/Test/AppTests.mustache new file mode 100644 index 0000000..1cf3444 --- /dev/null +++ b/Library/Resources/Files/Templates/Test/AppTests.mustache @@ -0,0 +1,33 @@ +import AppLibrary +import Hummingbird +import HummingbirdTesting +import Testing + +struct AppTests { + + // MARK: Properties + + private let arguments = TestArguments() + private let builder = AppBuilder(name: "{{ name }}") + + // MARK: Route tests + + @Test(arguments: ["/"]) + func routes(_ uri: String) async throws { + let app = try await builder(arguments) + + try await app.test(.router) { client in + try await client.execute(uri: uri, method: .get) { response in + #expect(response.status == .ok) + #expect(response.body == .empty) + } + } + } + +} + +// MARK: ByteBuffer+Constants + +private extension ByteBuffer { + static let empty = ByteBuffer(string: "") +}