Add new analytics parameters pathSuffix
Some checks failed
openium/resgen.swift/pipeline/head There was a failure building this commit
Some checks failed
openium/resgen.swift/pipeline/head There was a failure building this commit
This commit is contained in:
@@ -39,7 +39,10 @@ struct Analytics: ParsableCommand {
|
||||
print("[\(Self.toolName)] Will generate analytics")
|
||||
|
||||
// Parse input file
|
||||
let sections = AnalyticsFileParser().parse(options.inputFile, target: options.target)
|
||||
let sections = AnalyticsFileParser().parse(
|
||||
options.inputFile,
|
||||
target: options.target
|
||||
)
|
||||
|
||||
// Generate extension
|
||||
AnalyticsGenerator.writeExtensionFiles(
|
||||
@@ -48,7 +51,8 @@ struct Analytics: ParsableCommand {
|
||||
tags: ["ios", "iosonly"],
|
||||
isStatic: options.staticMembers,
|
||||
outputFile: options.outputFile,
|
||||
visibility: options.extensionVisibility
|
||||
visibility: options.extensionVisibility,
|
||||
pathSuffix: options.pathSuffix
|
||||
)
|
||||
|
||||
print("[\(Self.toolName)] Analytics generated")
|
||||
|
||||
@@ -44,4 +44,9 @@ struct AnalyticsOptions: ParsableArguments {
|
||||
completion: .list(["public", "private", "package", "internal"])
|
||||
)
|
||||
var extensionVisibility: ExtensionVisibility = .internal
|
||||
|
||||
@Option(
|
||||
help: "Suffix to add to every path parameters. Default is 'iOS'."
|
||||
)
|
||||
var pathSuffix: String = "iOS"
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ enum AnalyticsGenerator {
|
||||
tags: [String],
|
||||
isStatic: Bool,
|
||||
outputFile: String,
|
||||
visibility: ExtensionVisibility
|
||||
visibility: ExtensionVisibility,
|
||||
pathSuffix: String
|
||||
) {
|
||||
// Get target type from enum
|
||||
let targetsString: [String] = target.components(separatedBy: " ")
|
||||
@@ -44,7 +45,8 @@ enum AnalyticsGenerator {
|
||||
sections: sections,
|
||||
tags: tags,
|
||||
isStatic: isStatic,
|
||||
visibility: visibility
|
||||
visibility: visibility,
|
||||
pathSuffix: pathSuffix
|
||||
)
|
||||
|
||||
// Write content
|
||||
@@ -65,13 +67,15 @@ enum AnalyticsGenerator {
|
||||
sections: [AnalyticsCategory],
|
||||
tags: [String],
|
||||
isStatic: Bool,
|
||||
visibility: ExtensionVisibility
|
||||
visibility: ExtensionVisibility,
|
||||
pathSuffix: String
|
||||
) -> String {
|
||||
[
|
||||
getHeader(
|
||||
targets: targets,
|
||||
isStatic: isStatic,
|
||||
visibility: visibility
|
||||
visibility: visibility,
|
||||
pathSuffix: pathSuffix
|
||||
),
|
||||
getProperties(
|
||||
sections: sections,
|
||||
@@ -89,14 +93,15 @@ enum AnalyticsGenerator {
|
||||
private static func getHeader(
|
||||
targets: [TrackerType],
|
||||
isStatic: Bool,
|
||||
visibility: ExtensionVisibility
|
||||
visibility: ExtensionVisibility,
|
||||
pathSuffix: String
|
||||
) -> String {
|
||||
"""
|
||||
// Generated by ResgenSwift.\(Analytics.toolName) \(ResgenSwiftVersion)
|
||||
|
||||
\(Self.getImport(targets: targets))
|
||||
|
||||
\(Self.getAnalyticsProtocol(targets: targets, visibility: visibility))
|
||||
\(Self.getAnalyticsProtocol(targets: targets, visibility: visibility, pathSuffix: pathSuffix))
|
||||
|
||||
\(Self.getTrackerTypeEnum(targets: targets, visibility: visibility))
|
||||
|
||||
@@ -317,7 +322,8 @@ enum AnalyticsGenerator {
|
||||
|
||||
private static func getAnalyticsProtocol(
|
||||
targets: [TrackerType],
|
||||
visibility: ExtensionVisibility
|
||||
visibility: ExtensionVisibility,
|
||||
pathSuffix: String
|
||||
) -> String {
|
||||
let proto = """
|
||||
// MARK: - Protocol
|
||||
@@ -344,11 +350,11 @@ enum AnalyticsGenerator {
|
||||
var result: [String] = [proto]
|
||||
|
||||
if targets.contains(TrackerType.matomo) {
|
||||
result.append(MatomoGenerator.service)
|
||||
result.append(MatomoGenerator.service(pathSuffix: pathSuffix))
|
||||
}
|
||||
|
||||
if targets.contains(TrackerType.firebase) {
|
||||
result.append(FirebaseGenerator.service)
|
||||
result.append(FirebaseGenerator.service(pathSuffix: pathSuffix))
|
||||
}
|
||||
|
||||
return result.joined(separator: "\n\n")
|
||||
|
||||
@@ -11,10 +11,10 @@ import Foundation
|
||||
|
||||
enum FirebaseGenerator {
|
||||
|
||||
static var service: String {
|
||||
static func service(pathSuffix: String) -> String {
|
||||
[
|
||||
Self.header,
|
||||
Self.logScreen,
|
||||
Self.logScreen(pathSuffix: pathSuffix),
|
||||
Self.logEvent,
|
||||
Self.enable,
|
||||
Self.footer
|
||||
@@ -35,8 +35,14 @@ enum FirebaseGenerator {
|
||||
"""
|
||||
}
|
||||
|
||||
private static var logScreen: String {
|
||||
"""
|
||||
private static func logScreen(pathSuffix: String) -> String {
|
||||
let pathSuffixCode: String = if pathSuffix.isEmpty == false {
|
||||
" + \"/\(pathSuffix)\""
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
||||
return """
|
||||
func logScreen(
|
||||
name: String,
|
||||
path: String,
|
||||
@@ -47,7 +53,7 @@ enum FirebaseGenerator {
|
||||
]
|
||||
|
||||
if path.isEmpty == false {
|
||||
parameters["path"] = path + "/iOS" as NSObject
|
||||
parameters["path"] = path\(pathSuffixCode) as NSObject
|
||||
}
|
||||
|
||||
if let supplementaryParameters = params {
|
||||
|
||||
@@ -11,11 +11,11 @@ import Foundation
|
||||
|
||||
enum MatomoGenerator {
|
||||
|
||||
static var service: String {
|
||||
static func service(pathSuffix: String) -> String {
|
||||
[
|
||||
Self.header,
|
||||
Self.setup,
|
||||
Self.logScreen,
|
||||
Self.logScreen(pathSuffix: pathSuffix),
|
||||
Self.logEvent,
|
||||
Self.enable,
|
||||
Self.footer
|
||||
@@ -67,8 +67,14 @@ enum MatomoGenerator {
|
||||
"""
|
||||
}
|
||||
|
||||
private static var logScreen: String {
|
||||
"""
|
||||
private static func logScreen(pathSuffix: String) -> String {
|
||||
let pathSuffixCode: String = if pathSuffix.isEmpty == false {
|
||||
" + \"/\(pathSuffix)\""
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
||||
return """
|
||||
func logScreen(
|
||||
name: String,
|
||||
path: String,
|
||||
@@ -76,7 +82,7 @@ enum MatomoGenerator {
|
||||
) {
|
||||
guard let trackerUrl = tracker.contentBase?.absoluteString else { return }
|
||||
|
||||
let urlString = URL(string: "\\(trackerUrl)" + "/" + "\\(path)" + "iOS")
|
||||
let urlString = URL(string: "\\(trackerUrl)" + "/" + "\\(path)"\(pathSuffixCode)
|
||||
tracker.track(
|
||||
view: [name],
|
||||
url: urlString
|
||||
|
||||
@@ -169,7 +169,6 @@ class AnalyticsFileParser {
|
||||
|
||||
if target.contains(TrackerType.matomo.value) {
|
||||
// Path
|
||||
|
||||
guard let path = screen.path else {
|
||||
let error = AnalyticsError.missingElement("screen path")
|
||||
print(error.description)
|
||||
@@ -181,6 +180,10 @@ class AnalyticsFileParser {
|
||||
definition.path = path
|
||||
}
|
||||
|
||||
while definition.path.last == "/" {
|
||||
definition.path = String(definition.path.dropLast())
|
||||
}
|
||||
|
||||
return definition
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,19 +89,22 @@ struct AnalyticsConfiguration: Codable, CustomDebugStringConvertible {
|
||||
let outputFile: String
|
||||
let visibility: String?
|
||||
let staticMembers: Bool?
|
||||
let pathSuffix: String?
|
||||
|
||||
internal init(
|
||||
inputFile: String,
|
||||
target: String,
|
||||
outputFile: String,
|
||||
visibility: String?,
|
||||
staticMembers: Bool?
|
||||
staticMembers: Bool?,
|
||||
pathSuffix: String?
|
||||
) {
|
||||
self.inputFile = inputFile
|
||||
self.target = target
|
||||
self.outputFile = outputFile
|
||||
self.visibility = visibility
|
||||
self.staticMembers = staticMembers
|
||||
self.pathSuffix = pathSuffix
|
||||
}
|
||||
|
||||
var debugDescription: String {
|
||||
@@ -112,6 +115,7 @@ struct AnalyticsConfiguration: Codable, CustomDebugStringConvertible {
|
||||
- Output file: \(outputFile)
|
||||
- Visiblity: \(visibility ?? "default")
|
||||
- Static members: \(staticMembers != nil ? "\(String(describing: staticMembers))" : "default")
|
||||
- Path suffix: \(pathSuffix != nil ? "\(String(describing: pathSuffix))" : "default")
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@ extension AnalyticsConfiguration: Runnable {
|
||||
// Add optional parameters
|
||||
[
|
||||
("--visibility", visibility),
|
||||
("--static-members", staticMembers?.description)
|
||||
("--static-members", staticMembers?.description),
|
||||
("--path-suffix", pathSuffix)
|
||||
].forEach { argumentName, argumentValue in
|
||||
if let argumentValue {
|
||||
args += [
|
||||
|
||||
Reference in New Issue
Block a user