Add visibility parameters to control scope of generated extension
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
This commit is contained in:
@ -18,7 +18,8 @@ enum ImageExtensionGenerator {
|
||||
inputFilename: String,
|
||||
extensionName: String,
|
||||
extensionFilePath: String,
|
||||
isSwiftUI: Bool
|
||||
isSwiftUI: Bool,
|
||||
visibility: ExtensionVisibility
|
||||
) {
|
||||
// Create extension conten1t
|
||||
let extensionContent = Self.getExtensionContent(
|
||||
@ -26,7 +27,8 @@ enum ImageExtensionGenerator {
|
||||
staticVar: staticVar,
|
||||
extensionName: extensionName,
|
||||
inputFilename: inputFilename,
|
||||
isSwiftUI: isSwiftUI
|
||||
isSwiftUI: isSwiftUI,
|
||||
visibility: visibility
|
||||
)
|
||||
|
||||
// Write content
|
||||
@ -45,11 +47,21 @@ enum ImageExtensionGenerator {
|
||||
staticVar: Bool,
|
||||
extensionName: String,
|
||||
inputFilename: String,
|
||||
isSwiftUI: Bool
|
||||
isSwiftUI: Bool,
|
||||
visibility: ExtensionVisibility
|
||||
) -> String {
|
||||
[
|
||||
Self.getHeader(inputFilename: inputFilename, extensionClassname: extensionName, isSwiftUI: isSwiftUI),
|
||||
Self.getProperties(images: images, staticVar: staticVar, isSwiftUI: isSwiftUI),
|
||||
Self.getHeader(
|
||||
inputFilename: inputFilename,
|
||||
extensionClassname: extensionName,
|
||||
isSwiftUI: isSwiftUI
|
||||
),
|
||||
Self.getProperties(
|
||||
images: images,
|
||||
staticVar: staticVar,
|
||||
isSwiftUI: isSwiftUI,
|
||||
visibility: visibility
|
||||
),
|
||||
Self.getFooter()
|
||||
]
|
||||
.joined(separator: "\n")
|
||||
@ -73,10 +85,13 @@ enum ImageExtensionGenerator {
|
||||
private static func getProperties(
|
||||
images: [ParsedImage],
|
||||
staticVar: Bool,
|
||||
isSwiftUI: Bool
|
||||
isSwiftUI: Bool,
|
||||
visibility: ExtensionVisibility
|
||||
) -> String {
|
||||
images
|
||||
.map { "\n\($0.getImageProperty(isStatic: staticVar, isSwiftUI: isSwiftUI))" }
|
||||
.map {
|
||||
"\n\($0.getImageProperty(isStatic: staticVar, isSwiftUI: isSwiftUI, visibility: visibility))"
|
||||
}
|
||||
.joined(separator: "\n")
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,8 @@ struct Images: ParsableCommand {
|
||||
inputFilename: options.inputFilenameWithoutExt,
|
||||
extensionName: extensionName,
|
||||
extensionFilePath: extensionFilePath,
|
||||
isSwiftUI: true
|
||||
isSwiftUI: true,
|
||||
visibility: options.extensionVisibility
|
||||
)
|
||||
}
|
||||
|
||||
@ -73,7 +74,8 @@ struct Images: ParsableCommand {
|
||||
inputFilename: options.inputFilenameWithoutExt,
|
||||
extensionName: extensionNameUIKit,
|
||||
extensionFilePath: extensionFilePathUIKit,
|
||||
isSwiftUI: false
|
||||
isSwiftUI: false,
|
||||
visibility: options.extensionVisibility
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -7,27 +7,54 @@
|
||||
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
import ToolCore
|
||||
|
||||
// swiftlint:disable no_grouping_extension
|
||||
|
||||
struct ImagesOptions: ParsableArguments {
|
||||
|
||||
@Flag(name: .customShort("f"), help: "Should force script execution")
|
||||
@Flag(
|
||||
name: .customShort("f"),
|
||||
help: "Should force script execution"
|
||||
)
|
||||
var forceExecution = false
|
||||
|
||||
@Flag(name: .customShort("F"), help: "Regenerate all images")
|
||||
@Flag(
|
||||
name: .customShort("F"),
|
||||
help: "Regenerate all images"
|
||||
)
|
||||
var forceExecutionAndGeneration = false
|
||||
|
||||
@Argument(help: "Input files where strings ared defined.", transform: { $0.replaceTiltWithHomeDirectoryPath() })
|
||||
@Argument(
|
||||
help: "Input files where strings ared defined.",
|
||||
completion: .file(),
|
||||
transform: { $0.replaceTiltWithHomeDirectoryPath() }
|
||||
)
|
||||
var inputFile: String
|
||||
|
||||
@Option(help: "Xcassets path where to generate images.", transform: { $0.replaceTiltWithHomeDirectoryPath() })
|
||||
@Option(
|
||||
help: "Xcassets path where to generate images.",
|
||||
transform: { $0.replaceTiltWithHomeDirectoryPath() }
|
||||
)
|
||||
var xcassetsPath: String
|
||||
|
||||
@Option(help: "Tell if it will generate static properties or not")
|
||||
@Option(
|
||||
help: "Tell if it will generate static properties or not",
|
||||
completion: .list(["true", "false"])
|
||||
)
|
||||
var staticMembers: Bool = false
|
||||
|
||||
@Option(help: "Path where to generate the extension.", transform: { $0.replaceTiltWithHomeDirectoryPath() })
|
||||
@Option(
|
||||
name: .customLong("visibility"),
|
||||
help: "Visibility of extension and properties. Possibles values: public, private, package, internal. Default is internal",
|
||||
completion: .list(["public", "private", "package", "internal"])
|
||||
)
|
||||
var extensionVisibility: ExtensionVisibility = .internal
|
||||
|
||||
@Option(
|
||||
help: "Path where to generate the extension.",
|
||||
transform: { $0.replaceTiltWithHomeDirectoryPath() }
|
||||
)
|
||||
var extensionOutputPath: String?
|
||||
|
||||
@Option(help: "SwiftUI extension name. If not specified, no extension will be generated.")
|
||||
|
@ -6,6 +6,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import ToolCore
|
||||
|
||||
enum ImageExtension: String {
|
||||
|
||||
@ -129,16 +130,16 @@ struct ParsedImage {
|
||||
|
||||
// MARK: - Extension property
|
||||
|
||||
func getImageProperty(isStatic: Bool, isSwiftUI: Bool) -> String {
|
||||
func getImageProperty(isStatic: Bool, isSwiftUI: Bool, visibility: ExtensionVisibility) -> String {
|
||||
if isSwiftUI {
|
||||
return """
|
||||
\(isStatic ? "static " : "")var \(name): Image {
|
||||
\(visibility) \(isStatic ? "static " : "")var \(name): Image {
|
||||
Image("\(name)")
|
||||
}
|
||||
"""
|
||||
}
|
||||
return """
|
||||
\(isStatic ? "static " : "")var \(name): UIImage {
|
||||
\(visibility) \(isStatic ? "static " : "")var \(name): UIImage {
|
||||
UIImage(named: "\(name)")!
|
||||
}
|
||||
"""
|
||||
|
Reference in New Issue
Block a user