diff --git a/Sources/PackageDSLKit/PackageDSLKit.swift b/Sources/PackageDSLKit/PackageDSLKit.swift index f4251c6..8b4707a 100644 --- a/Sources/PackageDSLKit/PackageDSLKit.swift +++ b/Sources/PackageDSLKit/PackageDSLKit.swift @@ -28,8 +28,15 @@ // import SwiftSyntax +import SwiftParser +import Foundation +enum PackageDSLError : Error { + case custom(String, (any Sendable)?) + case other(any Error) +} extension ImportDeclSyntax { + static func module(_ moduleName: String) -> ImportDeclSyntax { ImportDeclSyntax( path: ImportPathComponentListSyntax([ @@ -42,6 +49,15 @@ extension ImportDeclSyntax { } } public enum PackageDSLKit { + + static func parse(_ directoryURL: URL, with fileManager: FileManager) throws { + let indexFileURL = directoryURL.appendingPathComponent("Index.swift") + guard fileManager.fileExists(atPath: indexFileURL.path) else { + throw PackageDSLError.custom("Could not find Index.swift file at \(indexFileURL)", indexFileURL) + } + let sourceCode = try String(contentsOf: indexFileURL) + } + public static func labeledExpression(for name: String, items: [String]) -> LabeledExprSyntax { LabeledExprSyntax( leadingTrivia: .newline, diff --git a/Sources/package/Commands.swift b/Sources/package/Commands.swift index bfca795..a5c6305 100644 --- a/Sources/package/Commands.swift +++ b/Sources/package/Commands.swift @@ -78,6 +78,10 @@ enum FileManagerType : String, CaseIterable, ExpressibleByArgument { case fileManager } +enum ProductType : String, CaseIterable, ExpressibleByArgument { + case library + case executable +} extension Package { struct Initialize : ParsableCommand { @OptionGroup var settings: Settings @@ -131,13 +135,25 @@ extension Package.Target { extension Package { struct Product : ParsableCommand { - + static let configuration: CommandConfiguration = .init( + subcommands: [Add.self] + ) } } extension Package.Product { struct Add : ParsableCommand { + @Argument var name : String + @OptionGroup var settings: Settings + + @Option var type : ProductType = .library + + func run() throws { + // add to products directory + // add to index + + } } }