Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for Swift Package Manager #15

Merged
merged 4 commits into from
Jan 30, 2017
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ playground.xcworkspace
# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
Packages/
.build/

# CocoaPods
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

### New Features

* Added support for Swift Package Manager.
[Krzysztof Zabłocki](https://github.com/krzysztofzablocki)
[#15](https://github.com/SwiftGen/StencilSwiftKit/issues/15)

### Internal Changes

* Renamed `SwiftTemplate` to `StencilSwiftTemplate`.
Expand Down
14 changes: 14 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import PackageDescription

let package = Package(
name: "StencilSwiftKit",
targets: [
Target(name: "StencilSwiftKit", dependencies: [])
],
dependencies: [
// https://github.com/kylef/Stencil/pull/84
.Package(url: "https://github.com/vknabel/Stencil.git", majorVersion: 0, minor: 7),
// Requires new release including https://github.com/kylef/PathKit/commit/7b17207
.Package(url: "https://github.com/vknabel/PathKit.git", majorVersion: 0, minor: 7),
]
)
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ def xcpretty(cmd)
end

task :build_for_testing do
sh "swift build"
xcpretty "xcodebuild -workspace StencilSwiftKit.xcworkspace -scheme Tests build-for-testing"
end

desc 'Run Unit Tests'
task :test => :build_for_testing do
sh "swift test"
xcpretty "xcodebuild -workspace StencilSwiftKit.xcworkspace -scheme Tests test-without-building"
end

Expand Down
1 change: 1 addition & 0 deletions Sources/Filters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// MIT Licence
//

import Foundation
import Stencil

enum FilterError: Error {
Expand Down
5 changes: 5 additions & 0 deletions Sources/StencilSwiftTemplate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
// MIT Licence
//

import Foundation
import Stencil

#if os(Linux) && !swift(>=3.1)
typealias NSRegularExpression = RegularExpression
#endif

// Workaround until Stencil fixes https://github.com/kylef/Stencil/issues/22
open class StencilSwiftTemplate: Template {
public required init(templateString: String, environment: Environment? = nil, name: String? = nil) {
Expand Down
14 changes: 7 additions & 7 deletions StencilSwiftKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@
DD5F34111E21657700AEB5DA /* Tests */ = {
isa = PBXGroup;
children = (
DD5F34291E21A3A200AEB5DA /* TestSuites */,
DD5F341C1E2199ED00AEB5DA /* Resources */,
DD5F341A1E21993A00AEB5DA /* TestsHelper.swift */,
DD5F34291E21A3A200AEB5DA /* StencilSwiftKitTests */,
);
path = Tests;
sourceTree = "<group>";
Expand All @@ -135,15 +133,17 @@
path = Resources;
sourceTree = "<group>";
};
DD5F34291E21A3A200AEB5DA /* TestSuites */ = {
DD5F34291E21A3A200AEB5DA /* StencilSwiftKitTests */ = {
isa = PBXGroup;
children = (
DD5F342A1E21A3A200AEB5DA /* CallNodeTests.swift */,
DD5F342B1E21A3A200AEB5DA /* SetNodeTests.swift */,
DD5F342C1E21A3A200AEB5DA /* StringFiltersTests.swift */,
DD5F342D1E21A3A200AEB5DA /* SwiftIdentifierTests.swift */,
DD5F341A1E21993A00AEB5DA /* TestsHelper.swift */,
DD5F341C1E2199ED00AEB5DA /* Resources */,
);
path = TestSuites;
path = StencilSwiftKitTests;
sourceTree = "<group>";
};
/* End PBXGroup section */
Expand Down Expand Up @@ -372,7 +372,7 @@
baseConfigurationReference = 47888DD528DEC4C84FD8F15B /* Pods-Tests.debug.xcconfig */;
buildSettings = {
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = Tests/Resources/Info.plist;
INFOPLIST_FILE = Tests/StencilSwiftKitTests/Resources/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_BUNDLE_IDENTIFIER = com.alisoftware.SwiftGenKitTests;
Expand All @@ -386,7 +386,7 @@
baseConfigurationReference = 4B3D39DBCD15D8F6BB891D92 /* Pods-Tests.release.xcconfig */;
buildSettings = {
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = Tests/Resources/Info.plist;
INFOPLIST_FILE = Tests/StencilSwiftKitTests/Resources/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_BUNDLE_IDENTIFIER = com.alisoftware.SwiftGenKitTests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,27 @@ func XCTDiffStrings(_ result: String, _ expected: String, file: StaticString = #
}

class Fixtures {
private static let testBundle = Bundle(for: Fixtures.self)
private static let resources: Path = {
if let path = Bundle(for: Fixtures.self).resourceURL?.path,
Path(path).exists {
return Path(path)
} else {
return Path(#file).parent() + "Resources"
}
}()
private init() {}

static func directory(subDirectory subDir: String? = nil) -> Path {
guard let rsrcURL = testBundle.resourceURL else {
fatalError("Unable to find resource directory URL")
}
let rsrc = Path(rsrcURL.path)

guard let dir = subDir else { return rsrc }
return rsrc + dir
guard let dir = subDir else { return resources }
return resources + dir
}

static func path(for name: String, subDirectory: String? = nil) -> Path {
guard let path = testBundle.path(forResource: name, ofType: "", inDirectory: subDirectory) else {
fatalError("Unable to find fixture \"\(name)\"")
if let subDirectory = subDirectory {
return resources + subDirectory + name
} else {
return resources + name
}
return Path(path)
}

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