Load custom templates.

This commit is contained in:
Marek Fořt 2020-02-16 17:45:47 +01:00
parent 7560d3703d
commit 9cc42da1cd
2 changed files with 12 additions and 2 deletions

View File

@ -39,8 +39,7 @@ class ScaffoldCommand: NSObject, Command {
}
func run(with arguments: ArgumentParser.Result) throws {
let templatesDirectory = Environment.shared.versionsDirectory.appending(components: Constants.version, Constants.templatesDirectoryName)
let directories = try FileHandler.shared.contentsOfDirectory(templatesDirectory)
let directories = try templateLoader.templateDirectories()
let shouldList = arguments.get(listArgument) ?? false
if shouldList {

View File

@ -5,6 +5,7 @@ import TuistSupport
import ProjectDescription
public protocol TemplateLoading {
func templateDirectories() throws -> [AbsolutePath]
func load(at path: AbsolutePath) throws -> Template
func generate(at path: AbsolutePath, to path: AbsolutePath) throws
}
@ -23,6 +24,16 @@ public class TemplateLoader: TemplateLoading {
self.manifestLoader = manifestLoader
}
public func templateDirectories() throws -> [AbsolutePath] {
let templatesDirectory = Environment.shared.versionsDirectory.appending(components: Constants.version, Constants.templatesDirectoryName)
if let rootPath = RootDirectoryLocator.shared.locate(from: AbsolutePath(FileHandler.shared.currentPath.pathString)) {
let customTemplatesDirectory = rootPath.appending(components: Constants.tuistDirectoryName, Constants.templatesDirectoryName)
return try FileHandler.shared.contentsOfDirectory(templatesDirectory) + FileHandler.shared.contentsOfDirectory(customTemplatesDirectory)
} else {
return try FileHandler.shared.contentsOfDirectory(templatesDirectory)
}
}
public func load(at path: AbsolutePath) throws -> Template {
let manifest = try manifestLoader.loadTemplate(at: path)
return try TuistLoader.Template.from(manifest: manifest)