diff --git a/Sources/TuistKit/Commands/ScaffoldCommand.swift b/Sources/TuistKit/Commands/ScaffoldCommand.swift index 32e3db518..fd351c2e2 100644 --- a/Sources/TuistKit/Commands/ScaffoldCommand.swift +++ b/Sources/TuistKit/Commands/ScaffoldCommand.swift @@ -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 { diff --git a/Sources/TuistLoader/Loaders/TemplateLoader.swift b/Sources/TuistLoader/Loaders/TemplateLoader.swift index 02c4be044..e9925ae06 100644 --- a/Sources/TuistLoader/Loaders/TemplateLoader.swift +++ b/Sources/TuistLoader/Loaders/TemplateLoader.swift @@ -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)