Browse Source

Rename template directory and modify plugin to look for templates in the same directory as the plugin executable.

Tim Burks 9 years ago
parent
commit
09ab02ceaf

+ 2 - 3
Plugin/README.md

@@ -11,7 +11,6 @@ the Makefile:
 
 	protoc ../Examples/Echo/echo.proto --proto_path=../Examples/Echo --swiftgrpc_out=. 
 
-The plugin uses template files in the [templates](templates) 
+The plugin uses template files in the [swiftgrpc.templates](swiftgrpc.templates) 
 directory. This directory currently must be in the same location 
-where the compiler is run.
-
+as the `protoc-gen-swiftgrpc` plugin executable.

+ 9 - 3
Plugin/Sources/main.swift

@@ -12,10 +12,11 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-import Stencil
 import Foundation
 import SwiftProtobuf
 import PluginLibrary
+import Stencil
+import PathKit
 
 func protoMessageName(_ name :String?) -> String {
   guard let name = name else {
@@ -120,8 +121,13 @@ func stripMarkers(_ code:String) -> String {
 
 func main() throws {
 
+  // we expect our templates to be in the same directory as this executable.
+  let executableURL = URL(fileURLWithPath: Bundle.main.executablePath!)
+  let executableDir : String = executableURL.deletingLastPathComponent().path
+  let templatePath = Path(executableDir + "/swiftgrpc.templates/")
+
   // initialize template engine and add custom filters
-  let fileSystemLoader = FileSystemLoader(paths: ["templates/"])
+  let fileSystemLoader = FileSystemLoader(paths: [templatePath])
   let ext = Extension()
   ext.registerFilter("call") { (value: Any?, arguments: [Any?]) in
     return try packageServiceMethodName(arguments) + "Call"
@@ -213,7 +219,7 @@ func main() throws {
   }
 
   log += "\(request)"
-  
+
   // add the logfile to the code generation response
   var logfile = Google_Protobuf_Compiler_CodeGeneratorResponse.File()
   logfile.name = "swiftgrpc.log"

+ 0 - 0
Plugin/templates/client-call-bidistreaming.swift → Plugin/swiftgrpc.templates/client-call-bidistreaming.swift


+ 0 - 0
Plugin/templates/client-call-clientstreaming.swift → Plugin/swiftgrpc.templates/client-call-clientstreaming.swift


+ 0 - 0
Plugin/templates/client-call-serverstreaming.swift → Plugin/swiftgrpc.templates/client-call-serverstreaming.swift


+ 0 - 0
Plugin/templates/client-call-unary.swift → Plugin/swiftgrpc.templates/client-call-unary.swift


+ 0 - 0
Plugin/templates/client.pb.swift → Plugin/swiftgrpc.templates/client.pb.swift


+ 0 - 0
Plugin/templates/server-session-bidistreaming.swift → Plugin/swiftgrpc.templates/server-session-bidistreaming.swift


+ 0 - 0
Plugin/templates/server-session-clientstreaming.swift → Plugin/swiftgrpc.templates/server-session-clientstreaming.swift


+ 0 - 0
Plugin/templates/server-session-serverstreaming.swift → Plugin/swiftgrpc.templates/server-session-serverstreaming.swift


+ 0 - 0
Plugin/templates/server-session-unary.swift → Plugin/swiftgrpc.templates/server-session-unary.swift


+ 0 - 0
Plugin/templates/server.pb.swift → Plugin/swiftgrpc.templates/server.pb.swift