Compare commits
No commits in common. "main" and "v0.1.0" have entirely different histories.
@ -7,15 +7,7 @@ struct Colibri: AsyncParsableCommand {
|
||||
|
||||
static let configuration = CommandConfiguration(
|
||||
abstract: "The utility to manage your Hummingbird apps",
|
||||
subcommands: [
|
||||
Build.self,
|
||||
Clean.self,
|
||||
Create.self,
|
||||
Open.self,
|
||||
Outdated.self,
|
||||
Update.self
|
||||
],
|
||||
defaultSubcommand: Create.self
|
||||
subcommands: [Create.self]
|
||||
)
|
||||
|
||||
}
|
||||
|
@ -1,29 +0,0 @@
|
||||
import ArgumentParser
|
||||
import ColibriLibrary
|
||||
|
||||
extension Colibri {
|
||||
struct Build: AsyncParsableCommand {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "build-project",
|
||||
abstract: "Build a Hummingbird app",
|
||||
helpNames: .shortAndLong,
|
||||
aliases: ["build"]
|
||||
)
|
||||
|
||||
@OptionGroup var options: Options
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
mutating func run() async throws {
|
||||
let terminalService = TerminalService()
|
||||
|
||||
let buildArtifact = BuildArtifactTask(terminalService: terminalService)
|
||||
|
||||
try await buildArtifact(options.artifact, at: options.locationURL)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
import ArgumentParser
|
||||
import ColibriLibrary
|
||||
|
||||
extension Colibri {
|
||||
struct Clean: AsyncParsableCommand {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "clean-project",
|
||||
abstract: "Clean a Hummingbird app",
|
||||
helpNames: .shortAndLong,
|
||||
aliases: ["clean"]
|
||||
)
|
||||
|
||||
@OptionGroup var options: Options
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
mutating func run() async throws {
|
||||
let terminalService = TerminalService()
|
||||
|
||||
let cleanProject = CleanProjectTask(terminalService: terminalService)
|
||||
|
||||
try await cleanProject(at: options.locationURL,
|
||||
shouldReset: options.reset,
|
||||
purgeCache: options.purgeCache)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
import ArgumentParser
|
||||
import ColibriLibrary
|
||||
|
||||
extension Colibri {
|
||||
struct Open: AsyncParsableCommand {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "open-project",
|
||||
abstract: "Open a Hummingbird app",
|
||||
helpNames: .shortAndLong,
|
||||
aliases: ["open"]
|
||||
)
|
||||
|
||||
@OptionGroup var options: Options
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
mutating func run() async throws {
|
||||
let terminalService = TerminalService()
|
||||
|
||||
let openProject = OpenProjectTask(terminalService: terminalService)
|
||||
|
||||
try await openProject(with: options.ide, at: options.locationURL)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
import ArgumentParser
|
||||
import ColibriLibrary
|
||||
|
||||
extension Colibri {
|
||||
struct Outdated: AsyncParsableCommand {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "outdated-dependencies",
|
||||
abstract: "Check for outdated package dependencies in a Hummingbird app",
|
||||
helpNames: .shortAndLong,
|
||||
aliases: ["outdated"]
|
||||
)
|
||||
|
||||
@OptionGroup var options: Options
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
mutating func run() async throws {
|
||||
let terminalService = TerminalService()
|
||||
|
||||
let updateDependencies = UpdateDependenciesTask(terminalService: terminalService)
|
||||
|
||||
try await updateDependencies(at: options.locationURL, checkOutdated: true)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
import ArgumentParser
|
||||
import ColibriLibrary
|
||||
|
||||
extension Colibri {
|
||||
struct Update: AsyncParsableCommand {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "update-dependencies",
|
||||
abstract: "Update package dependencies in a Hummingbird app",
|
||||
helpNames: .shortAndLong,
|
||||
aliases: ["update"]
|
||||
)
|
||||
|
||||
@OptionGroup var options: Options
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
mutating func run() async throws {
|
||||
let terminalService = TerminalService()
|
||||
|
||||
let updateDependencies = UpdateDependenciesTask(terminalService: terminalService)
|
||||
|
||||
try await updateDependencies(at: options.locationURL)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
import ArgumentParser
|
||||
import ColibriLibrary
|
||||
|
||||
// MARK: - ExpressibleByArgument
|
||||
|
||||
extension Artifact: ExpressibleByArgument {}
|
||||
extension IDE: ExpressibleByArgument {}
|
@ -1,16 +0,0 @@
|
||||
import ArgumentParser
|
||||
import ColibriLibrary
|
||||
|
||||
extension Colibri.Build {
|
||||
struct Options: ParsableArguments, Locationable {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
@Option(name: .shortAndLong)
|
||||
var artifact: Artifact = .executable
|
||||
|
||||
@Option(name: .shortAndLong)
|
||||
var location: String?
|
||||
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
import ArgumentParser
|
||||
import ColibriLibrary
|
||||
|
||||
extension Colibri.Clean {
|
||||
struct Options: ParsableArguments, Locationable {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
@Flag(name: .shortAndLong)
|
||||
var reset: Bool = false
|
||||
|
||||
@Flag(name: .shortAndLong)
|
||||
var purgeCache: Bool = false
|
||||
|
||||
@Option(name: .shortAndLong)
|
||||
var location: String?
|
||||
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
import ArgumentParser
|
||||
import ColibriLibrary
|
||||
import Foundation
|
||||
|
||||
extension Colibri.Create {
|
||||
struct Options: ParsableArguments, Locationable {
|
||||
struct Options: ParsableArguments {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
@ -11,6 +11,12 @@ extension Colibri.Create {
|
||||
|
||||
@Option(name: .shortAndLong)
|
||||
var location: String?
|
||||
|
||||
|
||||
// MARK: Computed
|
||||
|
||||
var locationURL: URL? {
|
||||
location.flatMap { URL(fileURLWithPath: $0) }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
import ArgumentParser
|
||||
import ColibriLibrary
|
||||
|
||||
extension Colibri.Open {
|
||||
struct Options: ParsableArguments, Locationable {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
@Option(name: .shortAndLong)
|
||||
var ide: IDE = .xcode
|
||||
|
||||
@Option(name: .shortAndLong)
|
||||
var location: String?
|
||||
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
import ArgumentParser
|
||||
import ColibriLibrary
|
||||
|
||||
extension Colibri.Outdated {
|
||||
struct Options: ParsableArguments, Locationable {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
@Option(name: .shortAndLong)
|
||||
var location: String?
|
||||
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
import ArgumentParser
|
||||
import ColibriLibrary
|
||||
|
||||
extension Colibri.Update {
|
||||
struct Options: ParsableArguments, Locationable {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
@Option(name: .shortAndLong)
|
||||
var location: String?
|
||||
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
services:
|
||||
app:
|
||||
build:
|
||||
context: .
|
||||
port:
|
||||
- 3000:8080
|
||||
command: ["--hostname", "0.0.0.0", "--port", "8080"]
|
@ -1,7 +1,7 @@
|
||||
# ================================
|
||||
# Build image
|
||||
# ================================
|
||||
FROM swift:6.0.3-noble AS build
|
||||
FROM swift:6.0-noble as build
|
||||
|
||||
# Install OS updates
|
||||
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
|
||||
@ -83,5 +83,5 @@ USER hummingbird:hummingbird
|
||||
EXPOSE 8080
|
||||
|
||||
# Start the Hummingbird service when the image is run, default to listening on 8080 in production environment
|
||||
ENTRYPOINT ["./App"]
|
||||
ENTRYPOINT ["./App]
|
||||
CMD ["--hostname", "0.0.0.0", "--port", "8080"]
|
||||
|
@ -2,7 +2,6 @@ enum File: String {
|
||||
case appArguments = "AppArguments"
|
||||
case appBuilder = "AppBuilder"
|
||||
case appOptions = "AppOptions"
|
||||
case dockerCompose = "DockerCompose"
|
||||
case dockerFile = "DockerFile"
|
||||
case dockerIgnore = "DockerIgnore"
|
||||
case environment = "Environment"
|
||||
@ -25,7 +24,6 @@ extension File {
|
||||
case .appArguments: "AppArguments.swift"
|
||||
case .appBuilder: "AppBuilder.swift"
|
||||
case .appOptions: "AppOptions.swift"
|
||||
case .dockerCompose: "docker-compose.yml"
|
||||
case .dockerFile: "Dockerfile"
|
||||
case .dockerIgnore: ".dockerignore"
|
||||
case .environment: "Environment+Properties.swift"
|
||||
|
@ -16,7 +16,7 @@ extension URL {
|
||||
|
||||
var pathString: String {
|
||||
if #available(macOS 13.0, *) {
|
||||
path(percentEncoded: false)
|
||||
path(percentEncoded: true)
|
||||
} else {
|
||||
path
|
||||
}
|
||||
|
@ -1,7 +0,0 @@
|
||||
protocol Randomable: CaseIterable {
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
static func random() -> Self
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
public enum Artifact: String {
|
||||
case executable
|
||||
case image
|
||||
}
|
||||
|
||||
// MARK: - Randomable
|
||||
|
||||
extension Artifact: Randomable {
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
static func random() -> Artifact {
|
||||
.allCases.randomElement() ?? .executable
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
public enum IDE: String {
|
||||
case vscode
|
||||
case xcode
|
||||
}
|
||||
|
||||
// MARK: - Randomable
|
||||
|
||||
extension IDE: Randomable {
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
static func random() -> IDE {
|
||||
.allCases.randomElement() ?? .xcode
|
||||
}
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
import Foundation
|
||||
|
||||
public protocol Locationable {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
var location: String? { get set }
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Locationable+Properties
|
||||
|
||||
public extension Locationable {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
var locationURL: URL? {
|
||||
location.flatMap { URL(fileURLWithPath: $0) }
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
import Foundation
|
||||
|
||||
public struct BuildArtifactTask {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
private let terminalService: TerminalServicing
|
||||
|
||||
// MARK: Initialisers
|
||||
|
||||
public init(terminalService: TerminalServicing) {
|
||||
self.terminalService = terminalService
|
||||
}
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
public func callAsFunction(_ artifact: Artifact, at location: URL? = nil) async throws (TerminalServiceError) {
|
||||
let executableURL: URL = switch artifact {
|
||||
case .executable: .init(at: "/usr/bin/swift")
|
||||
case .image: .init(at: "/usr/local/bin/docker")
|
||||
}
|
||||
|
||||
var arguments: [String] = switch artifact {
|
||||
case .executable: ["build"]
|
||||
case .image: ["compose", "build"]
|
||||
}
|
||||
|
||||
if let location {
|
||||
if case .executable = artifact {
|
||||
arguments.append(contentsOf: ["--package-path", location.pathString])
|
||||
} else if case .image = artifact {
|
||||
arguments.insert(contentsOf: ["--project-directory", location.pathString], at: 1)
|
||||
}
|
||||
}
|
||||
|
||||
try await terminalService.run(executableURL, arguments: arguments)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,49 +0,0 @@
|
||||
import Foundation
|
||||
|
||||
public struct CleanProjectTask {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
private let terminalService: TerminalServicing
|
||||
|
||||
// MARK: Initialisers
|
||||
|
||||
public init(terminalService: TerminalServicing) {
|
||||
self.terminalService = terminalService
|
||||
}
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
public func callAsFunction(
|
||||
at location: URL? = nil,
|
||||
shouldReset: Bool = false,
|
||||
purgeCache: Bool = false
|
||||
) async throws (TerminalServiceError) {
|
||||
let executableURL = URL(at: "/usr/bin/swift")
|
||||
|
||||
var arguments: [String] = ["package"]
|
||||
|
||||
if let location {
|
||||
arguments.append(contentsOf: ["--package-path", location.pathString])
|
||||
}
|
||||
|
||||
arguments.insert("clean", at: 1)
|
||||
|
||||
try await terminalService.run(executableURL, arguments: arguments)
|
||||
|
||||
if shouldReset {
|
||||
arguments.remove(at: 1)
|
||||
arguments.insert("reset", at: 1)
|
||||
|
||||
try await terminalService.run(executableURL, arguments: arguments)
|
||||
}
|
||||
|
||||
if purgeCache {
|
||||
arguments.remove(at: 1)
|
||||
arguments.insert("purge-cache", at: 1)
|
||||
|
||||
try await terminalService.run(executableURL, arguments: arguments)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
import Foundation
|
||||
|
||||
public struct OpenProjectTask {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
private let terminalService: TerminalServicing
|
||||
|
||||
// MARK: Initialisers
|
||||
|
||||
public init(terminalService: TerminalServicing) {
|
||||
self.terminalService = terminalService
|
||||
}
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
public func callAsFunction(with ide: IDE, at location: URL? = nil) async throws (TerminalServiceError) {
|
||||
let executableURL: URL = switch ide {
|
||||
case .vscode: .init(at: "/usr/local/bin/code")
|
||||
case .xcode: .init(at: "/usr/bin/open")
|
||||
}
|
||||
|
||||
let locationPath = switch ide {
|
||||
case .vscode: location?.pathString ?? "."
|
||||
case .xcode: location?.appendingPath(.Path.package).pathString ?? .Path.package
|
||||
}
|
||||
|
||||
let arguments: [String] = switch ide {
|
||||
case .vscode: [locationPath]
|
||||
case .xcode: ["-a", "Xcode", locationPath]
|
||||
}
|
||||
|
||||
try await terminalService.run(executableURL, arguments: arguments)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - String+Constants
|
||||
|
||||
private extension String {
|
||||
enum Path {
|
||||
static let package = "Package.swift"
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
import Foundation
|
||||
|
||||
public struct UpdateDependenciesTask {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
private let terminalService: TerminalServicing
|
||||
|
||||
// MARK: Initialisers
|
||||
|
||||
public init(terminalService: TerminalServicing) {
|
||||
self.terminalService = terminalService
|
||||
}
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
public func callAsFunction(at location: URL? = nil, checkOutdated: Bool = false) async throws (TerminalServiceError) {
|
||||
let executableURL = URL(at: "/usr/bin/swift")
|
||||
|
||||
var arguments: [String] = ["package", "update"]
|
||||
|
||||
if let location {
|
||||
arguments.append(contentsOf: ["--package-path", location.pathString])
|
||||
}
|
||||
|
||||
if checkOutdated {
|
||||
arguments.append("--dry-run")
|
||||
}
|
||||
|
||||
try await terminalService.run(executableURL, arguments: arguments)
|
||||
}
|
||||
|
||||
}
|
59
Makefile
59
Makefile
@ -1,59 +0,0 @@
|
||||
# VARIABLES
|
||||
|
||||
BINARY_FOLDER = $(prefix)/bin
|
||||
BUILD_FOLDER = .build/release
|
||||
EXECUTABLE_FILE = colibri
|
||||
|
||||
# INPUT ARGUMENTS
|
||||
|
||||
prefix ?= /usr/local
|
||||
|
||||
# EXECUTABLE MANAGEMENT
|
||||
|
||||
build: ## Build the executable from source code
|
||||
@swift build -c release --disable-sandbox
|
||||
|
||||
install: build ## Install the built executable into the system
|
||||
@install -d "$(BINARY_FOLDER)"
|
||||
@install "$(BUILD_FOLDER)/$(EXECUTABLE_FILE)" "$(BINARY_FOLDER)"
|
||||
|
||||
uninstall: ## Uninstall the built executable from the system
|
||||
@rm -rf "$(BINARY_FOLDER)/$(EXECUTABLE_FILE)"
|
||||
|
||||
# PACKAGE MANAGEMENT
|
||||
|
||||
clean: ## Delete built SPM artifacts from the package
|
||||
@swift package clean
|
||||
|
||||
outdated: ## List the SPM package dependencies that can be updated
|
||||
@swift package update --dry-run
|
||||
|
||||
purge: ## Purge the global SPM package repository
|
||||
@swift package purge-cache
|
||||
|
||||
reset: ## Reset the complete SPM cache/build folder from the package
|
||||
@swift package reset
|
||||
|
||||
update: ## Update the SPM package dependencies
|
||||
@swift package update
|
||||
|
||||
wipe: clean reset purge ## Wipe all SPM package dependencies and purge the global SPM repository
|
||||
|
||||
# OPEN IDEs
|
||||
|
||||
vscode: ## Opens this project with Visual Studio Code
|
||||
@code .
|
||||
|
||||
xcode: ## Opens this project with Xcode
|
||||
@open -a Xcode Package.swift
|
||||
|
||||
# HELP
|
||||
|
||||
# Output the documentation for each of the defined tasks when `help` is called.
|
||||
# Reference: https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
|
||||
.PHONY: help
|
||||
|
||||
help: ## Prints the written documentation for all the defined tasks
|
||||
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
|
||||
|
||||
.DEFAULT_GOAL := help
|
@ -56,7 +56,6 @@ private extension FileTests {
|
||||
"AppArguments.swift",
|
||||
"AppBuilder.swift",
|
||||
"AppOptions.swift",
|
||||
"docker-compose.yml",
|
||||
"Dockerfile",
|
||||
".dockerignore",
|
||||
"Environment+Properties.swift",
|
||||
@ -71,7 +70,6 @@ private extension FileTests {
|
||||
"Library/Sources/Public/AppArguments.swift",
|
||||
"Library/Sources/Public/AppBuilder.swift",
|
||||
"App/Sources/AppOptions.swift",
|
||||
"docker-compose.yml",
|
||||
"Dockerfile",
|
||||
".dockerignore",
|
||||
"Library/Sources/Internal/Environment+Properties.swift",
|
||||
@ -88,7 +86,6 @@ private extension FileTests {
|
||||
.app,
|
||||
.root,
|
||||
.root,
|
||||
.root,
|
||||
.libraryInternal,
|
||||
.root,
|
||||
.root,
|
||||
@ -103,7 +100,6 @@ private extension FileTests {
|
||||
"Resources/Files/Sources/App",
|
||||
"Resources/Files/Sources",
|
||||
"Resources/Files/Sources",
|
||||
"Resources/Files/Sources",
|
||||
"Resources/Files/Sources/Library",
|
||||
"Resources/Files/Sources",
|
||||
"Resources/Files/Sources",
|
||||
|
@ -24,8 +24,8 @@ struct URL_ExtensionsTests {
|
||||
|
||||
// MARK: Computed tests
|
||||
|
||||
@Test(arguments: zip([URL.someFile, .dotFile, .tildeFile, .someEncodedFile, .someURL],
|
||||
[String.someFilePath, .dotPath, .tildePath, .someEncodedPath, .empty]))
|
||||
@Test(arguments: zip([URL.someFile, .dotFile, .tildeFile, .someURL],
|
||||
[String.someFilePath, .dotPath, .tildePath, .empty]))
|
||||
func pathString(
|
||||
with url: URL,
|
||||
expects path: String
|
||||
@ -63,7 +63,6 @@ private extension String {
|
||||
static let dotPath = "."
|
||||
static let empty = ""
|
||||
static let tildePath = "~"
|
||||
static let someEncodedPath = "/sömê/páth/fîlê"
|
||||
static let someFilePath = "/some/file/path"
|
||||
}
|
||||
|
||||
@ -71,7 +70,6 @@ private extension String {
|
||||
|
||||
private extension URL {
|
||||
static let dotFile = URL(at: .dotPath)
|
||||
static let someEncodedFile = URL(at: "/sömê/páth/fîlê")
|
||||
static let someFile = URL(at: .someFilePath)
|
||||
static let someURL = URL(string: "https://some.url.path")!
|
||||
static let tildeFile = URL(at: .tildePath)
|
||||
|
@ -1,32 +0,0 @@
|
||||
import Testing
|
||||
|
||||
@testable import ColibriLibrary
|
||||
|
||||
struct RandomableTest {
|
||||
|
||||
@Test func random() {
|
||||
// GIVEN
|
||||
let allCases = TestRandomable.allCases
|
||||
|
||||
// WHEN
|
||||
let random = TestRandomable.random()
|
||||
|
||||
// THEN
|
||||
#expect(allCases.contains(random))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Enumerations
|
||||
|
||||
enum TestRandomable: Randomable {
|
||||
case someCase
|
||||
case someOtherCase
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
static func random() -> TestRandomable {
|
||||
.allCases.randomElement() ?? .someCase
|
||||
}
|
||||
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
import Foundation
|
||||
import Testing
|
||||
|
||||
@testable import ColibriLibrary
|
||||
|
||||
struct BuildArtifactTaskTests {
|
||||
|
||||
@Test(arguments: [nil, URL.someCurrentFolder])
|
||||
func taskForExecutable(at location: URL?) async throws {
|
||||
// GIVEN
|
||||
let terminalService = TerminalServiceSpy()
|
||||
let task = BuildArtifactTask(terminalService: terminalService)
|
||||
|
||||
// WHEN
|
||||
try await task(.executable, at: location)
|
||||
|
||||
// THEN
|
||||
let executableURL = URL(at: "/usr/bin/swift")
|
||||
let arguments = if let location {
|
||||
["build", "--package-path", location.pathString]
|
||||
} else {
|
||||
["build"]
|
||||
}
|
||||
|
||||
#expect(terminalService.actions.count == 1)
|
||||
#expect(terminalService.actions[0] == .ran(executableURL, arguments))
|
||||
}
|
||||
|
||||
@Test(arguments: [nil, URL.someCurrentFolder])
|
||||
func taskForImage(at location: URL?) async throws {
|
||||
// GIVEN
|
||||
let terminalService = TerminalServiceSpy()
|
||||
let task = BuildArtifactTask(terminalService: terminalService)
|
||||
|
||||
// WHEN
|
||||
try await task(.image, at: location)
|
||||
|
||||
// THEN
|
||||
let executableURL = URL(at: "/usr/local/bin/docker")
|
||||
let arguments = if let location {
|
||||
["compose", "--project-directory", location.pathString, "build"]
|
||||
} else {
|
||||
["compose", "build"]
|
||||
}
|
||||
|
||||
#expect(terminalService.actions.count == 1)
|
||||
#expect(terminalService.actions[0] == .ran(executableURL, arguments))
|
||||
}
|
||||
|
||||
@Test(arguments: [nil, URL.someCurrentFolder], [TerminalServiceError.unexpected, .output(""), .captured("")])
|
||||
func taskForArtifact(at location: URL?, throws error: TerminalServiceError) async throws {
|
||||
// GIVEN
|
||||
let terminalService = TerminalServiceMock(action: .error(error))
|
||||
let task = BuildArtifactTask(terminalService: terminalService)
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: error) {
|
||||
try await task(.random(), at: location)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,128 +0,0 @@
|
||||
import Foundation
|
||||
import Testing
|
||||
|
||||
@testable import ColibriLibrary
|
||||
|
||||
struct CleanProjectTaskTests {
|
||||
|
||||
@Test(arguments: [nil, URL.someCurrentFolder])
|
||||
func task(at location: URL?) async throws {
|
||||
// GIVEN
|
||||
let terminalService = TerminalServiceSpy()
|
||||
let task = CleanProjectTask(terminalService: terminalService)
|
||||
|
||||
// WHEN
|
||||
try await task(at: location)
|
||||
|
||||
// THEN
|
||||
let executableURL = URL(at: "/usr/bin/swift")
|
||||
let arguments = if let location {
|
||||
["package", "clean", "--package-path", location.pathString]
|
||||
} else {
|
||||
["package", "clean"]
|
||||
}
|
||||
|
||||
#expect(terminalService.actions.count == 1)
|
||||
#expect(terminalService.actions[0] == .ran(executableURL, arguments))
|
||||
}
|
||||
|
||||
@Test(arguments: [nil, URL.someCurrentFolder])
|
||||
func taskWithReset(at location: URL?) async throws {
|
||||
// GIVEN
|
||||
let terminalService = TerminalServiceSpy()
|
||||
let task = CleanProjectTask(terminalService: terminalService)
|
||||
|
||||
// WHEN
|
||||
try await task(at: location, shouldReset: true)
|
||||
|
||||
// THEN
|
||||
let executableURL = URL(at: "/usr/bin/swift")
|
||||
|
||||
var arguments = if let location {
|
||||
["package", "clean", "--package-path", location.pathString]
|
||||
} else {
|
||||
["package", "clean"]
|
||||
}
|
||||
|
||||
#expect(terminalService.actions.count == 2)
|
||||
#expect(terminalService.actions[0] == .ran(executableURL, arguments))
|
||||
|
||||
arguments.remove(at: 1)
|
||||
arguments.insert("reset", at: 1)
|
||||
|
||||
#expect(terminalService.actions[1] == .ran(executableURL, arguments))
|
||||
}
|
||||
|
||||
@Test(arguments: [nil, URL.someCurrentFolder])
|
||||
func taskWithPurgeCache(at location: URL?) async throws {
|
||||
// GIVEN
|
||||
let terminalService = TerminalServiceSpy()
|
||||
let task = CleanProjectTask(terminalService: terminalService)
|
||||
|
||||
// WHEN
|
||||
try await task(at: location, purgeCache: true)
|
||||
|
||||
// THEN
|
||||
let executableURL = URL(at: "/usr/bin/swift")
|
||||
|
||||
var arguments = if let location {
|
||||
["package", "clean", "--package-path", location.pathString]
|
||||
} else {
|
||||
["package", "clean"]
|
||||
}
|
||||
|
||||
#expect(terminalService.actions.count == 2)
|
||||
#expect(terminalService.actions[0] == .ran(executableURL, arguments))
|
||||
|
||||
arguments.remove(at: 1)
|
||||
arguments.insert("purge-cache", at: 1)
|
||||
|
||||
#expect(terminalService.actions[1] == .ran(executableURL, arguments))
|
||||
}
|
||||
|
||||
@Test(arguments: [nil, URL.someCurrentFolder])
|
||||
func taskWithResetAndPurgeCache(at location: URL?) async throws {
|
||||
// GIVEN
|
||||
let terminalService = TerminalServiceSpy()
|
||||
let task = CleanProjectTask(terminalService: terminalService)
|
||||
|
||||
// WHEN
|
||||
try await task(at: location, shouldReset: true, purgeCache: true)
|
||||
|
||||
// THEN
|
||||
let executableURL = URL(at: "/usr/bin/swift")
|
||||
|
||||
var arguments = if let location {
|
||||
["package", "clean", "--package-path", location.pathString]
|
||||
} else {
|
||||
["package", "clean"]
|
||||
}
|
||||
|
||||
#expect(terminalService.actions.count == 3)
|
||||
#expect(terminalService.actions[0] == .ran(executableURL, arguments))
|
||||
|
||||
arguments.remove(at: 1)
|
||||
arguments.insert("reset", at: 1)
|
||||
|
||||
#expect(terminalService.actions[1] == .ran(executableURL, arguments))
|
||||
|
||||
arguments.remove(at: 1)
|
||||
arguments.insert("purge-cache", at: 1)
|
||||
|
||||
#expect(terminalService.actions[2] == .ran(executableURL, arguments))
|
||||
}
|
||||
|
||||
@Test(arguments: [nil, URL.someCurrentFolder], [TerminalServiceError.unexpected, .output(""), .captured("")])
|
||||
func task(at location: URL?, throws error: TerminalServiceError) async throws {
|
||||
// GIVEN
|
||||
let terminalService = TerminalServiceMock(action: .error(error))
|
||||
let task = CleanProjectTask(terminalService: terminalService)
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: error) {
|
||||
try await task(at: location, shouldReset: .random(), purgeCache: .random())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
import Foundation
|
||||
import Testing
|
||||
|
||||
@testable import ColibriLibrary
|
||||
|
||||
struct OpenProjectTaskTests {
|
||||
|
||||
@Test(arguments: [nil, URL.someCurrentFolder])
|
||||
func taskWithVSCodeIDE(at location: URL?) async throws {
|
||||
// GIVEN
|
||||
let terminalService = TerminalServiceSpy()
|
||||
let task = OpenProjectTask(terminalService: terminalService)
|
||||
|
||||
// WHEN
|
||||
try await task(with: .vscode, at: location)
|
||||
|
||||
// THEN
|
||||
let executableURL = URL(at: "/usr/local/bin/code")
|
||||
let arguments = [location?.pathString ?? "."]
|
||||
|
||||
#expect(terminalService.actions.count == 1)
|
||||
#expect(terminalService.actions[0] == .ran(executableURL, arguments))
|
||||
}
|
||||
|
||||
@Test(arguments: [nil, URL.someCurrentFolder])
|
||||
func taskWithXcodeIDE(at location: URL?) async throws {
|
||||
// GIVEN
|
||||
let terminalService = TerminalServiceSpy()
|
||||
let task = OpenProjectTask(terminalService: terminalService)
|
||||
|
||||
// WHEN
|
||||
try await task(with: .xcode, at: location)
|
||||
|
||||
// THEN
|
||||
let locationPath = location?.appendingPath("Package.swift").pathString ?? "Package.swift"
|
||||
let executableURL = URL(at: "/usr/bin/open")
|
||||
let arguments = ["-a", "Xcode", locationPath]
|
||||
|
||||
#expect(terminalService.actions.count == 1)
|
||||
#expect(terminalService.actions[0] == .ran(executableURL, arguments))
|
||||
}
|
||||
|
||||
@Test(arguments: [nil, URL.someCurrentFolder], [TerminalServiceError.unexpected, .output(""), .captured("")])
|
||||
func task(at location: URL?, throws error: TerminalServiceError) async throws {
|
||||
// GIVEN
|
||||
let terminalService = TerminalServiceMock(action: .error(error))
|
||||
let task = OpenProjectTask(terminalService: terminalService)
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: error) {
|
||||
try await task(with: .random(), at: location)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
import Foundation
|
||||
import Testing
|
||||
|
||||
@testable import ColibriLibrary
|
||||
|
||||
struct UpdateDependenciesTaskTests {
|
||||
|
||||
@Test(arguments: [nil, URL.someCurrentFolder], [false, true])
|
||||
func task(at location: URL?, checkOutdated: Bool) async throws {
|
||||
// GIVEN
|
||||
let terminalService = TerminalServiceSpy()
|
||||
let task = UpdateDependenciesTask(terminalService: terminalService)
|
||||
|
||||
// WHEN
|
||||
try await task(at: location, checkOutdated: checkOutdated)
|
||||
|
||||
// THEN
|
||||
let executableURL = URL(at: "/usr/bin/swift")
|
||||
|
||||
var arguments = if let location {
|
||||
["package", "update", "--package-path", location.pathString]
|
||||
} else {
|
||||
["package", "update"]
|
||||
}
|
||||
|
||||
if checkOutdated {
|
||||
arguments.append("--dry-run")
|
||||
}
|
||||
|
||||
#expect(terminalService.actions.count == 1)
|
||||
#expect(terminalService.actions[0] == .ran(executableURL, arguments))
|
||||
}
|
||||
|
||||
@Test(arguments: [nil, URL.someCurrentFolder], [TerminalServiceError.unexpected, .output(""), .captured("")])
|
||||
func task(at location: URL?, throws error: TerminalServiceError) async throws {
|
||||
// GIVEN
|
||||
let terminalService = TerminalServiceMock(action: .error(error))
|
||||
let task = UpdateDependenciesTask(terminalService: terminalService)
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: error) {
|
||||
try await task(at: location, checkOutdated: .random())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -19,14 +19,6 @@ final class TemplateServiceMock {
|
||||
self.spy = spy
|
||||
}
|
||||
|
||||
init(
|
||||
actions: [Action],
|
||||
spy: TemplateServiceSpy? = nil
|
||||
) {
|
||||
self.actions = actions
|
||||
self.spy = spy
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - TemplateServicing
|
||||
|
@ -19,14 +19,6 @@ final class TerminalServiceMock {
|
||||
self.spy = spy
|
||||
}
|
||||
|
||||
init(
|
||||
actions: [Action],
|
||||
spy: TerminalServiceSpy? = nil
|
||||
) {
|
||||
self.actions = actions
|
||||
self.spy = spy
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - TerminalServicing
|
||||
|
Loading…
x
Reference in New Issue
Block a user