Skip to content

Commit 4cecc56

Browse files
krzysztofzablockiAliSoftware
authored andcommitted
feat: add support for Swift Package Manager (#15)
Add support for Swift Package Manager
1 parent 3101ac5 commit 4cecc56

21 files changed

+48
-19
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ playground.xcworkspace
3434
# Swift Package Manager
3535
#
3636
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
37-
# Packages/
37+
Packages/
3838
.build/
3939

4040
# CocoaPods

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
### New Features
1010

11+
* Added support for Swift Package Manager.
12+
[Krzysztof Zabłocki](https://github.com/krzysztofzablocki)
13+
[#15](https://github.com/SwiftGen/StencilSwiftKit/issues/15)
14+
1115
### Internal Changes
1216

1317
* Renamed `SwiftTemplate` to `StencilSwiftTemplate`.

Package.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import PackageDescription
2+
3+
let package = Package(
4+
name: "StencilSwiftKit",
5+
targets: [
6+
Target(name: "StencilSwiftKit", dependencies: [])
7+
],
8+
dependencies: [
9+
// https://github.com/kylef/Stencil/pull/84
10+
.Package(url: "https://github.com/vknabel/Stencil.git", majorVersion: 0, minor: 7),
11+
// Requires new release including https://github.com/kylef/PathKit/commit/7b17207
12+
.Package(url: "https://github.com/vknabel/PathKit.git", majorVersion: 0, minor: 7),
13+
]
14+
)

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ def xcpretty(cmd)
77
end
88

99
task :build_for_testing do
10+
sh "swift build"
1011
xcpretty "xcodebuild -workspace StencilSwiftKit.xcworkspace -scheme Tests build-for-testing"
1112
end
1213

1314
desc 'Run Unit Tests'
1415
task :test => :build_for_testing do
16+
sh "swift test"
1517
xcpretty "xcodebuild -workspace StencilSwiftKit.xcworkspace -scheme Tests test-without-building"
1618
end
1719

Sources/Filters.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// MIT Licence
55
//
66

7+
import Foundation
78
import Stencil
89

910
enum FilterError: Error {

Sources/StencilSwiftTemplate.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
// MIT Licence
55
//
66

7+
import Foundation
78
import Stencil
89

10+
#if os(Linux) && !swift(>=3.1)
11+
typealias NSRegularExpression = RegularExpression
12+
#endif
13+
914
// Workaround until Stencil fixes https://github.com/kylef/Stencil/issues/22
1015
open class StencilSwiftTemplate: Template {
1116
public required init(templateString: String, environment: Environment? = nil, name: String? = nil) {

StencilSwiftKit.xcodeproj/project.pbxproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@
118118
DD5F34111E21657700AEB5DA /* Tests */ = {
119119
isa = PBXGroup;
120120
children = (
121-
DD5F34291E21A3A200AEB5DA /* TestSuites */,
122-
DD5F341C1E2199ED00AEB5DA /* Resources */,
123-
DD5F341A1E21993A00AEB5DA /* TestsHelper.swift */,
121+
DD5F34291E21A3A200AEB5DA /* StencilSwiftKitTests */,
124122
);
125123
path = Tests;
126124
sourceTree = "<group>";
@@ -135,15 +133,17 @@
135133
path = Resources;
136134
sourceTree = "<group>";
137135
};
138-
DD5F34291E21A3A200AEB5DA /* TestSuites */ = {
136+
DD5F34291E21A3A200AEB5DA /* StencilSwiftKitTests */ = {
139137
isa = PBXGroup;
140138
children = (
141139
DD5F342A1E21A3A200AEB5DA /* CallNodeTests.swift */,
142140
DD5F342B1E21A3A200AEB5DA /* SetNodeTests.swift */,
143141
DD5F342C1E21A3A200AEB5DA /* StringFiltersTests.swift */,
144142
DD5F342D1E21A3A200AEB5DA /* SwiftIdentifierTests.swift */,
143+
DD5F341A1E21993A00AEB5DA /* TestsHelper.swift */,
144+
DD5F341C1E2199ED00AEB5DA /* Resources */,
145145
);
146-
path = TestSuites;
146+
path = StencilSwiftKitTests;
147147
sourceTree = "<group>";
148148
};
149149
/* End PBXGroup section */
@@ -372,7 +372,7 @@
372372
baseConfigurationReference = 47888DD528DEC4C84FD8F15B /* Pods-Tests.debug.xcconfig */;
373373
buildSettings = {
374374
COMBINE_HIDPI_IMAGES = YES;
375-
INFOPLIST_FILE = Tests/Resources/Info.plist;
375+
INFOPLIST_FILE = Tests/StencilSwiftKitTests/Resources/Info.plist;
376376
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
377377
MACOSX_DEPLOYMENT_TARGET = 10.11;
378378
PRODUCT_BUNDLE_IDENTIFIER = com.alisoftware.SwiftGenKitTests;
@@ -386,7 +386,7 @@
386386
baseConfigurationReference = 4B3D39DBCD15D8F6BB891D92 /* Pods-Tests.release.xcconfig */;
387387
buildSettings = {
388388
COMBINE_HIDPI_IMAGES = YES;
389-
INFOPLIST_FILE = Tests/Resources/Info.plist;
389+
INFOPLIST_FILE = Tests/StencilSwiftKitTests/Resources/Info.plist;
390390
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
391391
MACOSX_DEPLOYMENT_TARGET = 10.11;
392392
PRODUCT_BUNDLE_IDENTIFIER = com.alisoftware.SwiftGenKitTests;

Tests/TestsHelper.swift renamed to Tests/StencilSwiftKitTests/TestsHelper.swift

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,27 @@ func XCTDiffStrings(_ result: String, _ expected: String, file: StaticString = #
5353
}
5454

5555
class Fixtures {
56-
private static let testBundle = Bundle(for: Fixtures.self)
56+
private static let resources: Path = {
57+
if let path = Bundle(for: Fixtures.self).resourceURL?.path,
58+
Path(path).exists {
59+
return Path(path)
60+
} else {
61+
return Path(#file).parent() + "Resources"
62+
}
63+
}()
5764
private init() {}
5865

5966
static func directory(subDirectory subDir: String? = nil) -> Path {
60-
guard let rsrcURL = testBundle.resourceURL else {
61-
fatalError("Unable to find resource directory URL")
62-
}
63-
let rsrc = Path(rsrcURL.path)
64-
65-
guard let dir = subDir else { return rsrc }
66-
return rsrc + dir
67+
guard let dir = subDir else { return resources }
68+
return resources + dir
6769
}
6870

6971
static func path(for name: String, subDirectory: String? = nil) -> Path {
70-
guard let path = testBundle.path(forResource: name, ofType: "", inDirectory: subDirectory) else {
71-
fatalError("Unable to find fixture \"\(name)\"")
72+
if let subDirectory = subDirectory {
73+
return resources + subDirectory + name
74+
} else {
75+
return resources + name
7276
}
73-
return Path(path)
7477
}
7578

7679
static func string(for name: String, encoding: String.Encoding = .utf8) -> String {

0 commit comments

Comments
 (0)