Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ let package = Package(
.package(url: "https://github.com/JohnSundell/Files", from: "4.0.0"),
.package(url: "https://github.com/nikolainobadi/NnGitKit.git", from: "0.6.0"),
.package(url: "https://github.com/nikolainobadi/NnShellKit.git", from: "2.2.0"),
.package(url: "https://github.com/nikolainobadi/NnSwiftDataKit", exact: "0.5.0"),
.package(url: "https://github.com/nikolainobadi/NnSwiftDataKit", from: "0.9.0"),
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"),
.package(url: "https://github.com/nikolainobadi/SwiftPickerKit.git", from: "0.8.0")
.package(url: "https://github.com/nikolainobadi/SwiftPickerKit.git", branch: "open-mock-picker")
],
targets: [
.executableTarget(
Expand Down
4 changes: 2 additions & 2 deletions Sources/NnexKit/Building/BuildConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public struct BuildConfig: Sendable {
public let buildType: BuildType
public let extraBuildArgs: [String]
public let skipClean: Bool
public let testCommand: TestCommand?
public let testCommand: CurrentSchema.TestCommand?

/// Initializes a new `BuildConfig` with the specified settings.
///
Expand All @@ -22,7 +22,7 @@ public struct BuildConfig: Sendable {
/// - extraBuildArgs: Additional arguments to pass to the build command.
/// - shouldClean: Indicates whether the project should be cleaned before building. Defaults to `true`.
/// - testCommand: An optional command to run tests after building. Defaults to `nil`, meaning no tests will be run.
public init(projectName: String, projectPath: String, buildType: BuildType, extraBuildArgs: [String], skipClean: Bool, testCommand: TestCommand?) {
public init(projectName: String, projectPath: String, buildType: BuildType, extraBuildArgs: [String], skipClean: Bool, testCommand: CurrentSchema.TestCommand?) {
self.projectName = projectName
self.projectPath = projectPath.hasSuffix("/") ? projectPath : projectPath + "/"
self.buildType = buildType
Expand Down
4 changes: 2 additions & 2 deletions Sources/NnexKit/Formula/PublishUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public enum PublishUtilities {
/// - shell: The shell instance to use for building.
/// - Returns: The binary output including path(s) and hash(es).
/// - Throws: An error if the build process fails.
public static func buildBinary(formula: SwiftDataFormula, buildType: BuildType, skipTesting: Bool, shell: any NnexShell) throws -> BinaryOutput {
public static func buildBinary(formula: SwiftDataHomebrewFormula, buildType: BuildType, skipTesting: Bool, shell: any NnexShell) throws -> BinaryOutput {
let testCommand = skipTesting ? nil : formula.testCommand
let config = BuildConfig(projectName: formula.name, projectPath: formula.localProjectPath, buildType: buildType, extraBuildArgs: formula.extraBuildArgs, skipClean: false, testCommand: testCommand)
let builder = ProjectBuilder(shell: shell, config: config)
Expand Down Expand Up @@ -52,7 +52,7 @@ public enum PublishUtilities {
/// - assetURLs: The asset URLs from the GitHub release.
/// - Returns: The formula content as a string.
/// - Throws: An error if formula generation fails.
public static func makeFormulaContent(formula: SwiftDataFormula, version: String, archivedBinaries: [ArchivedBinary], assetURLs: [String]) throws -> String {
public static func makeFormulaContent(formula: SwiftDataHomebrewFormula, version: String, archivedBinaries: [ArchivedBinary], assetURLs: [String]) throws -> String {
let formulaName = formula.name

if archivedBinaries.count == 1 {
Expand Down
79 changes: 0 additions & 79 deletions Sources/NnexKit/Formula/SwiftDataFormula.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,81 +9,90 @@ import SwiftData
import Foundation
import NnSwiftDataKit

/// Manages the SwiftData model context and application configuration.
public final class NnexContext {
private let context: ModelContext
private let defaults: UserDefaults
private let defaultBuildTypeKey = "defaultBuildTypeKey"
private let tapListFolderPathKey = "tapListFolderPathKey"

/// The model context for interacting with SwiftData models.
public let context: ModelContext

/// Initializes a new NnexContext instance.
/// - Parameters:
/// - appGroupId: The application group identifier.
/// - config: An optional model configuration.
/// - defaults: An optional UserDefaults instance.
public init(appGroupId: String, config: ModelConfiguration? = nil, defaults: UserDefaults? = nil) throws {
if let config, let defaults {
let container = try ModelContainer(for: SwiftDataTap.self, configurations: config)
self.context = .init(container)
self.defaults = defaults
init(schema: Schema, userDefaultsTestSuiteName: String?) throws {
let identifier = "com.nobadi.nnex"
let oldAppGroupId = "R8SJ24LQF3.\(identifier)"
// let appGroupId = "group.\(identifier)" // TODO: -
let appGroupId = oldAppGroupId

if let userDefaultsTestSuiteName {
defaults = .init(suiteName: userDefaultsTestSuiteName)!
defaults.removePersistentDomain(forName: userDefaultsTestSuiteName)
context = try .init(.init(for: schema, configurations: .init(isStoredInMemoryOnly: true)))
} else {
let (config, defaults) = try configureSwiftDataContainer(appGroupId: appGroupId)
let container = try ModelContainer(for: SwiftDataTap.self, configurations: config)
self.context = .init(container)
// TODO: -
// try migrateAppGroupSwiftDataStoreIfNeeded(from: oldAppGroupId, to: appGroupId)
let (container, defaults) = try makeAppGroupModelContainer(schema: schema, appGroupId: appGroupId)

self.defaults = defaults
self.context = .init(container)
}
}
}


// MARK: - Init
public extension NnexContext {
convenience init( userDefaultsTestSuiteName: String? = nil) throws {
try self.init(schema: .init(versionedSchema: CurrentSchema.self), userDefaultsTestSuiteName: userDefaultsTestSuiteName)
}
}


// MARK: - UserDefaults
extension NnexContext {
public extension NnexContext {
/// Saves the folder path for the tap list.
/// - Parameter path: The folder path to save.
public func saveTapListFolderPath(path: String) {
func saveTapListFolderPath(path: String) {
defaults.set(path, forKey: tapListFolderPathKey)
}

/// Loads the folder path for the tap list.
/// - Returns: The saved folder path or nil if not set.
public func loadTapListFolderPath() -> String? {
func loadTapListFolderPath() -> String? {
guard let path = defaults.string(forKey: tapListFolderPathKey), !path.isEmpty else { return nil }
return path
}

/// Saves the default build type.
/// - Parameter buildType: The build type to save.
public func saveDefaultBuildType(_ buildType: BuildType) {
func saveDefaultBuildType(_ buildType: BuildType) {
defaults.set(buildType, forKey: defaultBuildTypeKey)
}

/// Loads the default build type.
/// - Returns: The saved build type or a default value if not set.
public func loadDefaultBuildType() -> BuildType {
func loadDefaultBuildType() -> BuildType {
return defaults.object(forKey: defaultBuildTypeKey) as? BuildType ?? .universal
}
}


// MARK: - SwiftData
extension NnexContext {
public extension NnexContext {
/// Loads all saved taps from the SwiftData context.
/// - Returns: An array of SwiftDataTap objects.
public func loadTaps() throws -> [SwiftDataTap] {
return try context.fetch(FetchDescriptor<SwiftDataTap>())
/// - Returns: An array of SwiftDataHomebrewTap objects.
func loadTaps() throws -> [SwiftDataHomebrewTap] {
return try context.fetch(FetchDescriptor<SwiftDataHomebrewTap>())
}

/// Loads all saved formulas from the SwiftData context.
/// - Returns: An array of SwiftDataFormula objects.
public func loadFormulas() throws -> [SwiftDataFormula] {
return try context.fetch(FetchDescriptor<SwiftDataFormula>())
/// - Returns: An array of SwiftDataHomebrewFormula objects.
func loadFormulas() throws -> [SwiftDataHomebrewFormula] {
return try context.fetch(FetchDescriptor<SwiftDataHomebrewFormula>())
}

/// Saves a new tap with associated formulas.
/// - Parameters:
/// - tap: The tap to save.
/// - formulas: An optional array of formulas to associate with the tap.
public func saveNewTap(_ tap: SwiftDataTap, formulas: [SwiftDataFormula] = []) throws {
func saveNewTap(_ tap: SwiftDataHomebrewTap, formulas: [SwiftDataHomebrewFormula] = []) throws {
context.insert(tap)
for formula in formulas {
context.insert(formula)
Expand All @@ -95,7 +104,7 @@ extension NnexContext {

/// Deletes the specified tap and its associated formulas.
/// - Parameter tap: The tap to delete.
public func deleteTap(_ tap: SwiftDataTap) throws {
func deleteTap(_ tap: SwiftDataHomebrewTap) throws {
for formula in tap.formulas {
context.delete(formula)
}
Expand All @@ -107,19 +116,19 @@ extension NnexContext {
/// - Parameters:
/// - formula: The formula to save.
/// - tap: The tap to associate with the formula.
public func saveNewFormula(_ formula: SwiftDataFormula, in tap: SwiftDataTap) throws {
func saveNewFormula(_ formula: SwiftDataHomebrewFormula, in tap: SwiftDataHomebrewTap) throws {
context.insert(formula)
tap.formulas.append(formula)
formula.tap = tap
try context.save()
}

public func deleteFormula(_ formula: SwiftDataFormula) throws {
func deleteFormula(_ formula: SwiftDataHomebrewFormula) throws {
context.delete(formula)
try context.save()
}

public func saveChanges() throws {
func saveChanges() throws {
try context.save()
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//
// SwiftDataFormula+Extensions.swift
// SwiftDataHomebrewFormula+Extensions.swift
// nnex
//
// Created by Nikolai Nobadi on 3/25/25.
//

public extension SwiftDataFormula {
/// Initializes a SwiftDataFormula instance from a BrewFormula.
public extension SwiftDataHomebrewFormula {
/// Initializes a SwiftDataHomebrewFormula instance from a BrewFormula.
/// - Parameter brewFormula: The BrewFormula to convert.
convenience init(from brewFormula: BrewFormula) {
var uploadType = FormulaUploadType.binary
var uploadType = CurrentSchema.FormulaUploadType.binary

if let stableURL = brewFormula.versions.stable {
uploadType = stableURL.contains(".tar.gz") ? .tarball : .binary
Expand All @@ -26,4 +26,4 @@ public extension SwiftDataFormula {
extraBuildArgs: []
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// SwiftDataHomebrewFormula.swift
// nnex
//
// Created by Nikolai Nobadi on 3/22/25.
//

public typealias SwiftDataHomebrewFormula = CurrentSchema.SwiftDataFormula
8 changes: 8 additions & 0 deletions Sources/NnexKit/SwiftData/Models/SwiftDataHomebrewTap.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// SwiftDataHomebrewTap.swift
// nnex
//
// Created by Nikolai Nobadi on 3/22/25.
//

public typealias SwiftDataHomebrewTap = CurrentSchema.SwiftDataTap
8 changes: 8 additions & 0 deletions Sources/NnexKit/SwiftData/Schema/CurrentSchema.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// CurrentSchema.swift
// nnex
//
// Created by Nikolai Nobadi on 12/10/25.
//

public typealias CurrentSchema = FirstSchema
Loading