main.swift 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2016 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import Foundation
  15. let TEMPLATES = "Templates"
  16. var s = ""
  17. s += "// GENERATED: DO NOT EDIT\n"
  18. s += "//\n"
  19. s += "// This file contains base64 encodings of templates used for Swift GRPC code generation.\n"
  20. s += "//\n"
  21. s += "func loadTemplates() -> [String:String] {\n"
  22. s += " var templates : [String:String] = [:]\n"
  23. let filenames = try FileManager.default.contentsOfDirectory(atPath:TEMPLATES)
  24. for filename in filenames {
  25. if filename.hasSuffix(".swift") {
  26. let fileURL = URL(fileURLWithPath:TEMPLATES + "/" + filename)
  27. let filedata = try Data(contentsOf:fileURL)
  28. let encoding = filedata.base64EncodedString()
  29. s += "\n"
  30. s += " templates[\"" + filename + "\"] = \"" + encoding + "\"\n"
  31. }
  32. }
  33. s += " return templates\n"
  34. s += "}\n"
  35. print(s)