-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Swift Compiler plugins to package up templates into code
- Loading branch information
Full Queue Developer
authored and
Full Queue Developer
committed
Oct 15, 2023
1 parent
e7b183c
commit 3338638
Showing
11 changed files
with
106 additions
and
728 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
Plugins/GenerateTemplatesPlugin/GenerateTemplatesPlugin.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import PackagePlugin | ||
import Foundation | ||
|
||
@main | ||
struct GenerateTemplatesPlugin: BuildToolPlugin { | ||
func createBuildCommands(context: PackagePlugin.PluginContext, target: PackagePlugin.Target) async throws -> [PackagePlugin.Command] { | ||
|
||
let templatesDir = context.package.directory.appending(subpath: "templates") | ||
let enumerator = FileManager.default.enumerator(atPath: templatesDir.string) | ||
|
||
let inputFiles = paths(fromEnumerator: enumerator!).map { path in | ||
templatesDir.appending(path) | ||
} | ||
|
||
let templateDirNames = try FileManager.default.contentsOfDirectory(atPath: templatesDir.string) | ||
|
||
return [ | ||
.buildCommand( | ||
displayName: "GenerateTemplatesPlugin", | ||
executable: try context.tool(named: "GenerateTemplatesTool").path, | ||
arguments: [ | ||
templatesDir.string, | ||
context.pluginWorkDirectory.string | ||
], | ||
inputFiles: inputFiles, | ||
outputFiles: [ | ||
context.pluginWorkDirectory.appending("Templates.swift"), | ||
] + templateDirNames.map({ templateName in | ||
context.pluginWorkDirectory.appending("\(templateName)Template.swift") | ||
}) | ||
), | ||
] | ||
} | ||
|
||
func paths(fromEnumerator enumerator: FileManager.DirectoryEnumerator) -> [String] { | ||
var result: [String] = [] | ||
while let file = enumerator.nextObject() as? String { | ||
result += [file] | ||
} | ||
return result | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
SPX/Sources/generate-scaffold-code/FileManager.resetDir(atPath).swift
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.