Skip to content

Commit d83c77c

Browse files
authored
Setting up Initial Commands (#6)
1 parent d80997e commit d83c77c

File tree

75 files changed

+4993
-31
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+4993
-31
lines changed

.github/workflows/PackageDSLKit.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ on:
33
push:
44
branches-ignore:
55
- '*WIP'
6+
pull_request:
67
env:
78
PACKAGE_NAME: PackageDSLKit
89
jobs:

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,5 @@ xcuserdata
145145

146146
test_output.log
147147
.docc-build
148-
public
148+
public
149+
.temp

.swiftlint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ opt_in_rules:
5757
- optional_enum_case_matching
5858
- overridden_super_call
5959
- override_in_extension
60-
- pattern_matching_keywords
6160
- prefer_self_type_over_type_of_self
6261
- prefer_zero_over_explicit_init
6362
- private_action
@@ -117,6 +116,7 @@ identifier_name:
117116
excluded:
118117
- DerivedData
119118
- .build
119+
- .temp
120120
indentation_width:
121121
indentation_width: 2
122122
file_name:

.vscode/launch.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33
{
44
"type": "lldb",
55
"request": "launch",
6-
"args": [],
6+
"args": ["init", "--path", "Samples/Appz"],
7+
"cwd": "${workspaceFolder:PackageDSLKit}",
8+
"name": "Debug package",
9+
"program": "${workspaceFolder:PackageDSLKit}/.build/debug/package",
10+
"preLaunchTask": "swift: Build Debug package"
11+
},
12+
{
13+
"type": "lldb",
14+
"request": "launch",
15+
"args": ["init", "--path", "Samples/Appz"],
716
"cwd": "${workspaceFolder:PackageDSLKit}",
817
"name": "Debug package",
918
"program": "${workspaceFolder:PackageDSLKit}/.build/debug/package",

Mintfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
swiftlang/swift-format@600.0.0
22
realm/SwiftLint@0.57.0
3-
a7ex/xcresultparser@1.7.2
43
peripheryapp/periphery@2.20.0

Package.resolved

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,47 @@ import PackageDescription
88
let package = Package(
99
name: "PackageDSLKit",
1010
platforms: [
11-
.macOS(.v10_15)
11+
.macOS(.v13)
1212
],
1313
products: [
1414
.library(name: "PackageDSLKit", targets: ["PackageDSLKit"])
1515
],
1616
dependencies: [
17+
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.4.0"),
1718
.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "601.0.0-prerelease-2024-11-18"),
18-
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.4.0")
19+
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.4.0"),
20+
.package(url: "https://github.com/apple/swift-log.git", from: "1.6.0")
1921
],
2022
targets: [
2123
// Targets are the basic building blocks of a package, defining a module or a test suite.
2224
// Targets can depend on other targets in this package and products from dependencies.
2325
.target(
24-
name: "PackageDSLKit"
26+
name: "PackageDSLKit",
27+
dependencies: [
28+
.product(name: "SwiftSyntax", package: "swift-syntax"),
29+
.product(name: "SwiftParser", package: "swift-syntax"),
30+
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
31+
.product(
32+
name: "Logging",
33+
package: "swift-log",
34+
condition: .when(platforms: [.linux, .openbsd, .wasi, .android, .windows])
35+
)
36+
],
37+
38+
resources: [
39+
.copy("Resources/PackageDSL.swift.txt")
40+
]
2541
),
2642
.executableTarget(
2743
name: "package",
2844
dependencies: [
29-
.product(name: "SwiftSyntax", package: "swift-syntax"),
30-
.product(name: "SwiftParser", package: "swift-syntax"),
45+
"PackageDSLKit",
46+
.product(name: "ArgumentParser", package: "swift-argument-parser")
3147
]
3248
),
3349
.testTarget(
34-
name: "PackageDSLKitTests"
50+
name: "PackageDSLKitTests",
51+
dependencies: ["PackageDSLKit"]
3552
)
3653
]
3754
)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// Component.swift
3+
// PackageDSLKit
4+
//
5+
// Created by Leo Dion.
6+
// Copyright © 2025 BrightDigit.
7+
//
8+
// Permission is hereby granted, free of charge, to any person
9+
// obtaining a copy of this software and associated documentation
10+
// files (the “Software”), to deal in the Software without
11+
// restriction, including without limitation the rights to use,
12+
// copy, modify, merge, publish, distribute, sublicense, and/or
13+
// sell copies of the Software, and to permit persons to whom the
14+
// Software is furnished to do so, subject to the following
15+
// conditions:
16+
//
17+
// The above copyright notice and this permission notice shall be
18+
// included in all copies or substantial portions of the Software.
19+
//
20+
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
21+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24+
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27+
// OTHER DEALINGS IN THE SOFTWARE.
28+
//
29+
30+
public struct Component: Sendable, Hashable, Codable {
31+
public let name: String
32+
public let inheritedTypes: [String]
33+
public let properties: [String: Property]
34+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// ComponentBuildable.swift
3+
// PackageDSLKit
4+
//
5+
// Created by Leo Dion.
6+
// Copyright © 2025 BrightDigit.
7+
//
8+
// Permission is hereby granted, free of charge, to any person
9+
// obtaining a copy of this software and associated documentation
10+
// files (the “Software”), to deal in the Software without
11+
// restriction, including without limitation the rights to use,
12+
// copy, modify, merge, publish, distribute, sublicense, and/or
13+
// sell copies of the Software, and to permit persons to whom the
14+
// Software is furnished to do so, subject to the following
15+
// conditions:
16+
//
17+
// The above copyright notice and this permission notice shall be
18+
// included in all copies or substantial portions of the Software.
19+
//
20+
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
21+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24+
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27+
// OTHER DEALINGS IN THE SOFTWARE.
28+
//
29+
30+
import Foundation
31+
32+
internal protocol ComponentBuildable {
33+
associatedtype Requirements = Void
34+
static var directoryName: String { get }
35+
init(component: Component, requirements: Requirements)
36+
static func requirements(from component: Component) -> Requirements?
37+
func createComponent() -> Component
38+
}
39+
40+
extension ComponentBuildable {
41+
internal init?(component: Component) {
42+
guard let requirements = Self.requirements(from: component) else {
43+
return nil
44+
}
45+
self.init(component: component, requirements: requirements)
46+
}
47+
48+
internal static func directoryURL(relativeTo packageDSLURL: URL) -> URL {
49+
packageDSLURL.appending(path: self.directoryName, directoryHint: .isDirectory)
50+
}
51+
}
52+
53+
extension Component {
54+
internal func isType<T: ComponentBuildable>(of type: T.Type) -> Bool {
55+
type.requirements(from: self) != nil
56+
}
57+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//
2+
// ComponentWriter.swift
3+
// PackageDSLKit
4+
//
5+
// Created by Leo Dion.
6+
// Copyright © 2025 BrightDigit.
7+
//
8+
// Permission is hereby granted, free of charge, to any person
9+
// obtaining a copy of this software and associated documentation
10+
// files (the “Software”), to deal in the Software without
11+
// restriction, including without limitation the rights to use,
12+
// copy, modify, merge, publish, distribute, sublicense, and/or
13+
// sell copies of the Software, and to permit persons to whom the
14+
// Software is furnished to do so, subject to the following
15+
// conditions:
16+
//
17+
// The above copyright notice and this permission notice shall be
18+
// included in all copies or substantial portions of the Software.
19+
//
20+
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
21+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24+
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27+
// OTHER DEALINGS IN THE SOFTWARE.
28+
//
29+
30+
import SwiftSyntax
31+
32+
public struct ComponentWriter: Sendable, StructureWriter {
33+
private let propertyWriter: @Sendable (Property) -> VariableDeclSyntax
34+
35+
public init(
36+
propertyWriter: @escaping @Sendable (Property) -> VariableDeclSyntax = PropertyWriter.node
37+
) {
38+
self.propertyWriter = propertyWriter
39+
}
40+
41+
public func node(from component: Component) -> StructDeclSyntax {
42+
let memberBlockList = MemberBlockItemListSyntax(
43+
component.properties.values.map(propertyWriter).map {
44+
MemberBlockItemSyntax(decl: $0)
45+
}
46+
)
47+
let inheritedTypes = component.inheritedTypes
48+
.map { TokenSyntax.identifier($0) }
49+
.map {
50+
IdentifierTypeSyntax(name: $0)
51+
}
52+
.map {
53+
InheritedTypeSyntax(type: $0)
54+
}
55+
.reversed()
56+
.enumerated()
57+
.map { index, expression in
58+
if index == 0 {
59+
return expression
60+
}
61+
return expression.with(\.trailingComma, .commaToken())
62+
}
63+
.reversed()
64+
let inheritedTypeList = InheritedTypeListSyntax(inheritedTypes)
65+
let clause = InheritanceClauseSyntax(inheritedTypes: inheritedTypeList)
66+
let memberBlock = MemberBlockSyntax(members: memberBlockList)
67+
return StructDeclSyntax(
68+
name: .identifier(component.name, leadingTrivia: .space),
69+
inheritanceClause: clause,
70+
memberBlock: memberBlock
71+
)
72+
}
73+
}

0 commit comments

Comments
 (0)