Load custom templates.
This commit is contained in:
parent
7560d3703d
commit
9cc42da1cd
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue