Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
f8a14e46ed | |||
888d00c1e8 | |||
fce5a23734 | |||
ced12d509e | |||
ab5f589547 | |||
7ee071010d | |||
6a3b9b5141 |
@ -7,7 +7,15 @@ struct Colibri: AsyncParsableCommand {
|
||||
|
||||
static let configuration = CommandConfiguration(
|
||||
abstract: "The utility to manage your Hummingbird apps",
|
||||
subcommands: [Create.self]
|
||||
subcommands: [
|
||||
Build.self,
|
||||
Clean.self,
|
||||
Create.self,
|
||||
Open.self,
|
||||
Outdated.self,
|
||||
Update.self
|
||||
],
|
||||
defaultSubcommand: Create.self
|
||||
)
|
||||
|
||||
}
|
||||
|
29
Executable/Sources/Commands/BuildCommand.swift
Normal file
29
Executable/Sources/Commands/BuildCommand.swift
Normal file
@ -0,0 +1,29 @@
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
31
Executable/Sources/Commands/CleanCommand.swift
Normal file
31
Executable/Sources/Commands/CleanCommand.swift
Normal file
@ -0,0 +1,31 @@
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
29
Executable/Sources/Commands/OpenCommand.swift
Normal file
29
Executable/Sources/Commands/OpenCommand.swift
Normal file
@ -0,0 +1,29 @@
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
29
Executable/Sources/Commands/OutdatedCommand.swift
Normal file
29
Executable/Sources/Commands/OutdatedCommand.swift
Normal file
@ -0,0 +1,29 @@
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
29
Executable/Sources/Commands/UpdateCommand.swift
Normal file
29
Executable/Sources/Commands/UpdateCommand.swift
Normal file
@ -0,0 +1,29 @@
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
7
Executable/Sources/Definitions/Conformances.swift
Normal file
7
Executable/Sources/Definitions/Conformances.swift
Normal file
@ -0,0 +1,7 @@
|
||||
import ArgumentParser
|
||||
import ColibriLibrary
|
||||
|
||||
// MARK: - ExpressibleByArgument
|
||||
|
||||
extension Artifact: ExpressibleByArgument {}
|
||||
extension IDE: ExpressibleByArgument {}
|
16
Executable/Sources/Options/BuildOptions.swift
Normal file
16
Executable/Sources/Options/BuildOptions.swift
Normal file
@ -0,0 +1,16 @@
|
||||
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?
|
||||
|
||||
}
|
||||
}
|
19
Executable/Sources/Options/CleanOptions.swift
Normal file
19
Executable/Sources/Options/CleanOptions.swift
Normal file
@ -0,0 +1,19 @@
|
||||
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 Foundation
|
||||
import ColibriLibrary
|
||||
|
||||
extension Colibri.Create {
|
||||
struct Options: ParsableArguments {
|
||||
struct Options: ParsableArguments, Locationable {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
@ -12,11 +12,5 @@ extension Colibri.Create {
|
||||
@Option(name: .shortAndLong)
|
||||
var location: String?
|
||||
|
||||
// MARK: Computed
|
||||
|
||||
var locationURL: URL? {
|
||||
location.flatMap { URL(fileURLWithPath: $0) }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
16
Executable/Sources/Options/OpenOptions.swift
Normal file
16
Executable/Sources/Options/OpenOptions.swift
Normal file
@ -0,0 +1,16 @@
|
||||
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?
|
||||
|
||||
}
|
||||
}
|
13
Executable/Sources/Options/OutdatedOptions.swift
Normal file
13
Executable/Sources/Options/OutdatedOptions.swift
Normal file
@ -0,0 +1,13 @@
|
||||
import ArgumentParser
|
||||
import ColibriLibrary
|
||||
|
||||
extension Colibri.Outdated {
|
||||
struct Options: ParsableArguments, Locationable {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
@Option(name: .shortAndLong)
|
||||
var location: String?
|
||||
|
||||
}
|
||||
}
|
13
Executable/Sources/Options/UpdateOptions.swift
Normal file
13
Executable/Sources/Options/UpdateOptions.swift
Normal file
@ -0,0 +1,13 @@
|
||||
import ArgumentParser
|
||||
import ColibriLibrary
|
||||
|
||||
extension Colibri.Update {
|
||||
struct Options: ParsableArguments, Locationable {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
@Option(name: .shortAndLong)
|
||||
var location: String?
|
||||
|
||||
}
|
||||
}
|
7
Library/Resources/Files/Sources/DockerCompose
Normal file
7
Library/Resources/Files/Sources/DockerCompose
Normal file
@ -0,0 +1,7 @@
|
||||
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-noble as build
|
||||
FROM swift:6.0.3-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,6 +2,7 @@ enum File: String {
|
||||
case appArguments = "AppArguments"
|
||||
case appBuilder = "AppBuilder"
|
||||
case appOptions = "AppOptions"
|
||||
case dockerCompose = "DockerCompose"
|
||||
case dockerFile = "DockerFile"
|
||||
case dockerIgnore = "DockerIgnore"
|
||||
case environment = "Environment"
|
||||
@ -24,6 +25,7 @@ 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: true)
|
||||
path(percentEncoded: false)
|
||||
} else {
|
||||
path
|
||||
}
|
||||
|
7
Library/Sources/Internal/Protocols/Randomable.swift
Normal file
7
Library/Sources/Internal/Protocols/Randomable.swift
Normal file
@ -0,0 +1,7 @@
|
||||
protocol Randomable: CaseIterable {
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
static func random() -> Self
|
||||
|
||||
}
|
16
Library/Sources/Public/Enumerations/Artifact.swift
Normal file
16
Library/Sources/Public/Enumerations/Artifact.swift
Normal file
@ -0,0 +1,16 @@
|
||||
public enum Artifact: String {
|
||||
case executable
|
||||
case image
|
||||
}
|
||||
|
||||
// MARK: - Randomable
|
||||
|
||||
extension Artifact: Randomable {
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
static func random() -> Artifact {
|
||||
.allCases.randomElement() ?? .executable
|
||||
}
|
||||
|
||||
}
|
16
Library/Sources/Public/Enumerations/IDE.swift
Normal file
16
Library/Sources/Public/Enumerations/IDE.swift
Normal file
@ -0,0 +1,16 @@
|
||||
public enum IDE: String {
|
||||
case vscode
|
||||
case xcode
|
||||
}
|
||||
|
||||
// MARK: - Randomable
|
||||
|
||||
extension IDE: Randomable {
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
static func random() -> IDE {
|
||||
.allCases.randomElement() ?? .xcode
|
||||
}
|
||||
|
||||
}
|
21
Library/Sources/Public/Protocols/Locationable.swift
Normal file
21
Library/Sources/Public/Protocols/Locationable.swift
Normal file
@ -0,0 +1,21 @@
|
||||
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) }
|
||||
}
|
||||
|
||||
}
|
40
Library/Sources/Public/Tasks/BuildArtifactTask.swift
Normal file
40
Library/Sources/Public/Tasks/BuildArtifactTask.swift
Normal file
@ -0,0 +1,40 @@
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
|
49
Library/Sources/Public/Tasks/CleanProjectTask.swift
Normal file
49
Library/Sources/Public/Tasks/CleanProjectTask.swift
Normal file
@ -0,0 +1,49 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
44
Library/Sources/Public/Tasks/OpenProjectTask.swift
Normal file
44
Library/Sources/Public/Tasks/OpenProjectTask.swift
Normal file
@ -0,0 +1,44 @@
|
||||
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"
|
||||
}
|
||||
}
|
33
Library/Sources/Public/Tasks/UpdateDependenciesTask.swift
Normal file
33
Library/Sources/Public/Tasks/UpdateDependenciesTask.swift
Normal file
@ -0,0 +1,33 @@
|
||||
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
Normal file
59
Makefile
Normal file
@ -0,0 +1,59 @@
|
||||
# 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,6 +56,7 @@ private extension FileTests {
|
||||
"AppArguments.swift",
|
||||
"AppBuilder.swift",
|
||||
"AppOptions.swift",
|
||||
"docker-compose.yml",
|
||||
"Dockerfile",
|
||||
".dockerignore",
|
||||
"Environment+Properties.swift",
|
||||
@ -70,6 +71,7 @@ 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",
|
||||
@ -86,6 +88,7 @@ private extension FileTests {
|
||||
.app,
|
||||
.root,
|
||||
.root,
|
||||
.root,
|
||||
.libraryInternal,
|
||||
.root,
|
||||
.root,
|
||||
@ -100,6 +103,7 @@ 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, .someURL],
|
||||
[String.someFilePath, .dotPath, .tildePath, .empty]))
|
||||
@Test(arguments: zip([URL.someFile, .dotFile, .tildeFile, .someEncodedFile, .someURL],
|
||||
[String.someFilePath, .dotPath, .tildePath, .someEncodedPath, .empty]))
|
||||
func pathString(
|
||||
with url: URL,
|
||||
expects path: String
|
||||
@ -63,6 +63,7 @@ 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"
|
||||
}
|
||||
|
||||
@ -70,6 +71,7 @@ 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)
|
||||
|
32
Test/Sources/Cases/Internal/Protocols/RandomableTests.swift
Normal file
32
Test/Sources/Cases/Internal/Protocols/RandomableTests.swift
Normal file
@ -0,0 +1,32 @@
|
||||
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
|
||||
}
|
||||
|
||||
}
|
63
Test/Sources/Cases/Public/Tasks/BuildArtifactTaskTests.swift
Normal file
63
Test/Sources/Cases/Public/Tasks/BuildArtifactTaskTests.swift
Normal file
@ -0,0 +1,63 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
128
Test/Sources/Cases/Public/Tasks/CleanProjectTaskTests.swift
Normal file
128
Test/Sources/Cases/Public/Tasks/CleanProjectTaskTests.swift
Normal file
@ -0,0 +1,128 @@
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
56
Test/Sources/Cases/Public/Tasks/OpenProjectTaskTests.swift
Normal file
56
Test/Sources/Cases/Public/Tasks/OpenProjectTaskTests.swift
Normal file
@ -0,0 +1,56 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
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,6 +19,14 @@ final class TemplateServiceMock {
|
||||
self.spy = spy
|
||||
}
|
||||
|
||||
init(
|
||||
actions: [Action],
|
||||
spy: TemplateServiceSpy? = nil
|
||||
) {
|
||||
self.actions = actions
|
||||
self.spy = spy
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - TemplateServicing
|
||||
|
@ -19,6 +19,14 @@ 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