Scaffold project structure

This commit is contained in:
T. R. Bernstein
2026-03-11 16:09:09 +01:00
commit 1a7e5ca5de
8 changed files with 224 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.build

87
Package.resolved Normal file
View File

@@ -0,0 +1,87 @@
{
"originHash" : "db0ba74c125e968c67646390cbba012a5572a5c9c54171588ecbb73e370a448d",
"pins" : [
{
"identity" : "noora",
"kind" : "remoteSourceControl",
"location" : "https://github.com/tuist/Noora",
"state" : {
"revision" : "70c6d1477a982f3e4cd46ed2d122e04e9d0a0b59",
"version" : "0.56.0"
}
},
{
"identity" : "path",
"kind" : "remoteSourceControl",
"location" : "https://github.com/tuist/path",
"state" : {
"revision" : "7c74ac435e03a927c3a73134c48b61e60221abcb",
"version" : "0.3.8"
}
},
{
"identity" : "rainbow",
"kind" : "remoteSourceControl",
"location" : "https://github.com/onevcat/Rainbow",
"state" : {
"revision" : "cdf146ae671b2624917648b61c908d1244b98ca1",
"version" : "4.2.1"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "c5d11a805e765f52ba34ec7284bd4fcd6ba68615",
"version" : "1.7.0"
}
},
{
"identity" : "swift-async-algorithms",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-async-algorithms",
"state" : {
"revision" : "9d349bcc328ac3c31ce40e746b5882742a0d1272",
"version" : "1.1.3"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "8d9834a6189db730f6264db7556a7ffb751e99ee",
"version" : "1.4.0"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log",
"state" : {
"revision" : "bbd81b6725ae874c69e9b8c8804d462356b55523",
"version" : "1.10.1"
}
},
{
"identity" : "swift-subprocess",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-subprocess.git",
"state" : {
"revision" : "ba5888ad7758cbcbe7abebac37860b1652af2d9c",
"version" : "0.3.0"
}
},
{
"identity" : "swift-system",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-system",
"state" : {
"revision" : "7c6ad0fc39d0763e0b699210e4124afd5041c5df",
"version" : "1.6.4"
}
}
],
"version" : 3
}

46
Package.swift Normal file
View File

@@ -0,0 +1,46 @@
// swift-tools-version: 6.0
import PackageDescription
let package = Package(
name: "Inotify",
platforms: [.macOS(.v13), .custom("Linux", versionString: "4.4.302")],
products: [
.library(
name: "Inotify",
targets: ["Inotify"]
),
.executable(
name: "task",
targets: ["TaskCLI"]
)
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.7.0"),
.package(url: "https://github.com/apple/swift-async-algorithms", from: "1.1.3"),
.package(url: "https://github.com/apple/swift-log", from: "1.10.1"),
.package(url: "https://github.com/swiftlang/swift-subprocess.git", from: "0.3.0"),
.package(url: "https://github.com/tuist/Noora", from: "0.55.1")
],
targets: [
.target(
name: "Inotify",
dependencies: [
.product(name: "Logging", package: "swift-log"),
]
),
.testTarget(
name: "InotifyIntegrationTests",
dependencies: ["Inotify"],
),
.executableTarget(
name: "TaskCLI",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
.product(name: "Logging", package: "swift-log"),
.product(name: "Subprocess", package: "swift-subprocess"),
.product(name: "Noora", package: "Noora")
]
)
]
)

View File

@@ -0,0 +1,2 @@
actor Inotify {
}

View File

@@ -0,0 +1,9 @@
import ArgumentParser
@main
struct Command: AsyncParsableCommand {
static let configuration = CommandConfiguration(
abstract: "Project tasks of Astzweig's Swift Inotify project.",
subcommands: [TestCommand.self]
)
}

View File

@@ -0,0 +1,25 @@
import ArgumentParser
import Logging
struct GlobalOptions: ParsableArguments {
@Flag(
name: .short,
help: "Increase logging verbosity. Use -v, -vv, or -vvv."
)
var verbose: Int
var logLevel: Logger.Level {
switch verbose {
case 0: return .notice
case 1: return .info
case 2: return .debug
default: return .trace
}
}
func makeLogger(labeled label: String) -> Logger {
var logger = Logger(label: label)
logger.logLevel = logLevel
return logger
}
}

View File

@@ -0,0 +1,45 @@
import ArgumentParser
import AsyncAlgorithms
import Foundation
import Subprocess
import Noora
struct TestCommand: AsyncParsableCommand {
static let configuration = CommandConfiguration(
commandName: "test",
abstract: "Run swift test in a linux container.",
aliases: ["t"],
)
@OptionGroup var global: GlobalOptions
// MARK: - Run
func run() async throws {
let noora = Noora()
let logger = global.makeLogger(labeled: "swift-inotify.cli.task.test")
let currentDirectory = FileManager.default.currentDirectoryPath
noora.info("Running tests on Linux.")
logger.debug("Current directory", metadata: ["current-directory": "\(currentDirectory)"])
async let monitorResult = Subprocess.run(
.name("docker"),
arguments: ["run", "-v", "\(currentDirectory):/code", "--platform", "linux/arm64", "-w", "/code", "swift:latest", "swift", "test"],
preferredBufferSize: 10,
) { execution, standardInput, standardOutput, standardError in
print("")
let stdout = standardOutput.lines()
let stderr = standardError.lines()
for try await line in merge(stdout, stderr) {
noora.passthrough("\(line)")
}
print("")
}
if (try await monitorResult.terminationStatus.isSuccess) {
noora.success("All tests completed successfully.")
} else {
noora.error("Not all tests completed successfully.")
}
}
}

View File

@@ -0,0 +1,9 @@
import Testing
@testable import Inotify
@Suite("Initialisation")
struct InitTests {
@Test func createsCleanly() async throws {
let _ = Inotify()
}
}