Skip to content

Commit a79e418

Browse files
committed
Warn when using a template name found in AppSupport
1 parent 2d87582 commit a79e418

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

Sources/SwiftGen/Commander/TemplateCommands.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ enum TemplateCLI {
2626
try output.write(
2727
content: """
2828
---
29-
You can add custom templates in \(Path.appSupportTemplates).
30-
You can also specify templates by path using `templatePath` instead of `templateName`.
31-
For more information, see the documentation on GitHub.
29+
You can also specify custom templates by path, using `templatePath` instead of `templateName`.
30+
For more information, see the documentation on GitHub or use `swiftgen template doc`.
3231
"""
3332
)
3433
}
@@ -86,8 +85,8 @@ private extension TemplateCLI {
8685
templates(in: path + parser.templateFolder).map { " - \($0.lastComponentWithoutExtension)" }
8786
}
8887
var lines = ["\(parser.name):"]
89-
lines.append(" custom:")
90-
lines.append(contentsOf: parserTemplates(in: Path.appSupportTemplates))
88+
lines.append(" custom (deprecated):")
89+
lines.append(contentsOf: parserTemplates(in: Path.deprecatedAppSupportTemplates))
9190
lines.append(" bundled:")
9291
lines.append(contentsOf: parserTemplates(in: Path.bundledTemplates))
9392
return lines.joined(separator: "\n")

Sources/SwiftGen/Path+CommonLocations.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ extension Path {
2020
return binaryPath
2121
}()
2222

23-
static let applicationSupport: Path = {
23+
// Deprecated: Remove this in SwiftGen 7.0
24+
static let deprecatedApplicationSupport: Path = {
2425
let paths = NSSearchPathForDirectoriesInDomains(
2526
.applicationSupportDirectory,
2627
.userDomainMask,
@@ -32,7 +33,8 @@ extension Path {
3233
return Path(path)
3334
}()
3435

35-
static let appSupportTemplates = Path.applicationSupport + "SwiftGen/templates"
36+
// Deprecated: Remove this in SwiftGen 7.0
37+
static let deprecatedAppSupportTemplates = Path.deprecatedApplicationSupport + "SwiftGen/templates"
3638
static let bundledTemplates = binary.parent() + templatesRelativePath
3739

3840
// MARK: Private

Sources/SwiftGen/TemplateRef.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,18 @@ enum TemplateRef: Equatable {
4545
func resolvePath(forParser parser: ParserCLI) throws -> Path {
4646
switch self {
4747
case .name(let templateShortName):
48-
var path = Path.appSupportTemplates + parser.templateFolder + "\(templateShortName).stencil"
49-
if !path.isFile {
48+
var path = Path.deprecatedAppSupportTemplates + parser.templateFolder + "\(templateShortName).stencil"
49+
if path.isFile {
50+
logMessage(
51+
.warning,
52+
"""
53+
Refering templates in Application Support by name will be deprecated in SwiftGen 7.0.
54+
For custom templates, please use `templatePath` instead of `templateName` to point to them.
55+
We also recommend you move your custom templates from \(Path.deprecatedAppSupportTemplates)
56+
to your project's folder so that your project is able to run independently on all machines.
57+
"""
58+
)
59+
} else {
5060
path = Path.bundledTemplates + parser.templateFolder + "\(templateShortName).stencil"
5161
}
5262
guard path.isFile else {

0 commit comments

Comments
 (0)