Compare commits
14 Commits
443d8d0727
...
stencil
Author | SHA1 | Date | |
---|---|---|---|
3f64e9682c | |||
eed20367b9 | |||
43b5111d79 | |||
2983093a9c | |||
b4bbaa3bfd | |||
498c8fa4ae | |||
2957da6233 | |||
d79af06c38 | |||
d8937f2de6 | |||
9b27f24197 | |||
1d58fd5510 | |||
f6c49bf626 | |||
f1b62d83c4 | |||
ee5055efa5 |
@ -18,6 +18,15 @@
|
||||
"version" : "1.8.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "pathkit",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/kylef/PathKit.git",
|
||||
"state" : {
|
||||
"revision" : "3bfd2737b700b9a36565a8c94f4ad2b050a5e574",
|
||||
"version" : "1.0.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "sourcekitten",
|
||||
"kind" : "remoteSourceControl",
|
||||
@ -27,6 +36,24 @@
|
||||
"version" : "0.34.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "spectre",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/kylef/Spectre.git",
|
||||
"state" : {
|
||||
"revision" : "26cc5e9ae0947092c7139ef7ba612e34646086c7",
|
||||
"version" : "0.10.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "stencil",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/stencilproject/Stencil.git",
|
||||
"state" : {
|
||||
"revision" : "4f222ac85d673f35df29962fc4c36ccfdaf9da5b",
|
||||
"version" : "0.15.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-argument-parser",
|
||||
"kind" : "remoteSourceControl",
|
||||
|
@ -11,6 +11,7 @@ let package = Package(
|
||||
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"),
|
||||
.package(url: "https://github.com/jpsim/Yams.git", from: "5.0.1"),
|
||||
.package(url: "https://github.com/realm/SwiftLint.git", .upToNextMajor(from: "0.54.0")),
|
||||
.package(url: "https://github.com/stencilproject/Stencil.git", .upToNextMajor(from: "0.15.1")),
|
||||
],
|
||||
targets: [
|
||||
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
||||
@ -20,7 +21,8 @@ let package = Package(
|
||||
dependencies: [
|
||||
"ToolCore",
|
||||
.product(name: "ArgumentParser", package: "swift-argument-parser"),
|
||||
"Yams"
|
||||
"Yams",
|
||||
"Stencil",
|
||||
],
|
||||
plugins: [.plugin(name: "SwiftLintPlugin", package: "SwiftLint")]
|
||||
),
|
||||
|
65
README.md
65
README.md
@ -133,6 +133,71 @@ swift run -c release ResgenSwift strings tags $FORCE_FLAG "./Tags/tags.txt" \
|
||||
|
||||
> ⚠️ If extension name is not set or is `Tags`, it will generate the following typaloas `typealias Tags = String`.
|
||||
|
||||
|
||||
## Analytics
|
||||
|
||||
Analytics will generate all you need to analyze UX with Matomo or Firebase Analytics. Input files are formatted in YAML. This command will generate a manager for each target and an AnalyticsManager. This is this one you will need to use. And it will generate a method for all tags you have declared in the YAML file. Next, you will need to use the `configure()` method of AnalyticsManager and if you want to use matomo to set up the `siteId` and the `url` of the site.
|
||||
|
||||
```sh
|
||||
swift run -c release ResgenSwift strings tags $FORCE_FLAG "./Tags/tags.txt" \
|
||||
--target "matomo firebase" \
|
||||
--extension-output-path "./Analytics/Generated" \
|
||||
--extension-name "AppAnalytics" \
|
||||
--extension-suffix "GreatApp" \
|
||||
--static-members true
|
||||
```
|
||||
|
||||
**Parameters**
|
||||
|
||||
1. `-f`: force generation
|
||||
2. Input tags file (must be YAML formatted)
|
||||
3. `--target`: target with you will log UX
|
||||
4. `--extension-output-path`: path where to generate generated extension
|
||||
5. `--extension-name` *(optional)* : name of class to add the extension
|
||||
6. `--extension-suffix` *(optional)* : additional text which is added to filename (ex: `AppAnalytics+GreatApp.swift`)
|
||||
7. `--static-members` *(optional)*: generate static properties or not
|
||||
|
||||
> ⚠️ If extension name is not set or is `Analytics`, it will generate the following typaloas `typealias Analytics = String`.
|
||||
|
||||
### YAML
|
||||
|
||||
```
|
||||
- id: s1_def_one
|
||||
name: s1 def one _TITLE_
|
||||
path: s1_def_one/_TITLE_
|
||||
action: Tap
|
||||
category: User
|
||||
tags: ios,droid
|
||||
comments:
|
||||
parameters:
|
||||
- name: title
|
||||
type: String
|
||||
replaceIn: name,path
|
||||
```
|
||||
|
||||
1. `id`: name of the method (method name will be composed of `log` + `Event|Screen` + `id`)
|
||||
2. `name`: name of the tag
|
||||
3. `path` *(optional with firebase)* : needed for matomo but not with firebase (log screen)
|
||||
4. `action` *(optional with firebase)* : needed for matomo but not with firebase (log event)
|
||||
5. `category` *(optional with firebase)* : needed for matomo but not with firebase (log event)
|
||||
6. `tags`: which platform target
|
||||
7. `comments` *(optional)*
|
||||
8. `parameters` *(optional)*
|
||||
|
||||
**Parameters**
|
||||
|
||||
You can use parameters in generate methods.
|
||||
|
||||
1. `name`: name of the parameter
|
||||
2. `type`: type of the parameter (Int, String, Bool, Double)
|
||||
3. `replaceIn` *(optional)*
|
||||
|
||||
**Replace in**
|
||||
|
||||
This is section is equivalent of `%s | %d | %f | %@`. You can put the content of the parameter in *name*, *path*, *action*, *category*.
|
||||
You need to put `_` + `NAME OF THE PARAMETER` + `_` in the target and which target you want in the value of `replaceIn`. (name need to be in uppercase)
|
||||
|
||||
|
||||
## Images
|
||||
|
||||
Images generator will generate images assets along with extensions to access those images easily.
|
||||
|
@ -4,18 +4,25 @@ import SwiftUI
|
||||
|
||||
extension ColorYolo {
|
||||
|
||||
/// Color red is #FF0000 (light) or #FF0000 (dark)"
|
||||
|
||||
/// Color red is #FF0000 #FF0000 or #FF0000 #FF0000"
|
||||
var red: Color {
|
||||
Color("red")
|
||||
}
|
||||
|
||||
/// Color green_alpha_50 is #A000FF00 (light) or #A000FF00 (dark)"
|
||||
|
||||
|
||||
/// Color green_alpha_50 is #A000FF00 #A000FF00 or #A000FF00 #A000FF00"
|
||||
var green_alpha_50: Color {
|
||||
Color("green_alpha_50")
|
||||
}
|
||||
|
||||
/// Color blue_light_dark is #0000FF (light) or #0000AA (dark)"
|
||||
|
||||
|
||||
/// Color blue_light_dark is #0000FF #0000FF or #0000AA #0000AA"
|
||||
var blue_light_dark: Color {
|
||||
Color("blue_light_dark")
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,18 +4,25 @@ import UIKit
|
||||
|
||||
extension UIColorYolo {
|
||||
|
||||
/// Color red is #FF0000 (light) or #FF0000 (dark)"
|
||||
|
||||
/// Color red is #FF0000 #FF0000 or #FF0000 #FF0000"
|
||||
@objc var red: UIColor {
|
||||
UIColor(named: "red")!
|
||||
}
|
||||
|
||||
/// Color green_alpha_50 is #A000FF00 (light) or #A000FF00 (dark)"
|
||||
|
||||
|
||||
/// Color green_alpha_50 is #A000FF00 #A000FF00 or #A000FF00 #A000FF00"
|
||||
@objc var green_alpha_50: UIColor {
|
||||
UIColor(named: "green_alpha_50")!
|
||||
}
|
||||
|
||||
/// Color blue_light_dark is #0000FF (light) or #0000AA (dark)"
|
||||
|
||||
|
||||
/// Color blue_light_dark is #0000FF #0000FF or #0000AA #0000AA"
|
||||
@objc var blue_light_dark: UIColor {
|
||||
UIColor(named: "blue_light_dark")!
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
// Generated by ResgenSwift.Color 1.2
|
||||
|
||||
import UIKit
|
||||
|
||||
|
||||
extension UIhkjhkColorYolo {
|
||||
|
||||
|
||||
/// Color red is #FF0000 #FF0000 or #FF0000 #FF0000"
|
||||
@objc var red: UIColor {
|
||||
UIColor(named: "red")!
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// Color green_alpha_50 is #A000FF00 #A000FF00 or #A000FF00 #A000FF00"
|
||||
@objc var green_alpha_50: UIColor {
|
||||
UIColor(named: "green_alpha_50")!
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// Color blue_light_dark is #0000FF #0000FF or #0000AA #0000AA"
|
||||
@objc var blue_light_dark: UIColor {
|
||||
UIColor(named: "blue_light_dark")!
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -81,7 +81,7 @@ class MatomoAnalyticsManager: AnalyticsManagerProtocol {
|
||||
class FirebaseAnalyticsManager: AnalyticsManagerProtocol {
|
||||
func logScreen(name: String, path: String) {
|
||||
var parameters = [
|
||||
AnalyticsParameterScreenName: name
|
||||
AnalyticsParameterScreenName: name as NSObject
|
||||
]
|
||||
|
||||
Analytics.logEvent(
|
||||
@ -96,19 +96,25 @@ class FirebaseAnalyticsManager: AnalyticsManagerProtocol {
|
||||
category: String,
|
||||
params: [String: Any]?
|
||||
) {
|
||||
var parameters: [String:Any] = [
|
||||
"action": action,
|
||||
"category": category,
|
||||
var parameters: [String:NSObject] = [
|
||||
"action": action as NSObject,
|
||||
"category": category as NSObject,
|
||||
]
|
||||
|
||||
if let supplementaryParameters = params {
|
||||
parameters.merge(supplementaryParameters) { (origin, new) -> Any in
|
||||
return origin
|
||||
for (newKey, newValue) in supplementaryParameters {
|
||||
if parameters.contains(where: { (key: String, value: NSObject) in
|
||||
key == newKey
|
||||
}) {
|
||||
continue
|
||||
}
|
||||
|
||||
parameters[newKey] = newValue as? NSObject
|
||||
}
|
||||
}
|
||||
|
||||
Analytics.logEvent(
|
||||
name,
|
||||
name.replacingOccurrences(of: [" "], with: "_"),
|
||||
parameters: parameters
|
||||
)
|
||||
}
|
||||
|
@ -12,14 +12,14 @@ FORCE_FLAG="$1"
|
||||
#
|
||||
#echo "\n-------------------------\n"
|
||||
#
|
||||
## Color
|
||||
#swift run -c release ResgenSwift colors $FORCE_FLAG "./Colors/sampleColors1.txt" \
|
||||
# --style all \
|
||||
# --xcassets-path "./Colors/colors.xcassets" \
|
||||
# --extension-output-path "./Colors/Generated/" \
|
||||
# --extension-name "ColorYolo" \
|
||||
# --extension-name-ui-kit "UIhkjhkColorYolo" \
|
||||
# --extension-suffix "GenAllScript"
|
||||
# Color
|
||||
swift run -c release ResgenSwift colors $FORCE_FLAG "./Colors/sampleColors1.txt" \
|
||||
--style all \
|
||||
--xcassets-path "./Colors/colors.xcassets" \
|
||||
--extension-output-path "./Colors/Generated/" \
|
||||
--extension-name "ColorYolo" \
|
||||
--extension-name-ui-kit "UIColorYolo" \
|
||||
--extension-suffix "GenAllScript"
|
||||
#
|
||||
#echo "\n-------------------------\n"
|
||||
#
|
||||
@ -61,10 +61,10 @@ FORCE_FLAG="$1"
|
||||
|
||||
#echo "\n-------------------------\n"
|
||||
#
|
||||
# Images
|
||||
swift run -c release ResgenSwift images $FORCE_FLAG "./Images/sampleImages.txt" \
|
||||
--xcassets-path "./Images/imagium.xcassets" \
|
||||
--extension-output-path "./Images/Generated" \
|
||||
--extension-name "ImageYolo" \
|
||||
--extension-name-ui-kit "UIImageYolo" \
|
||||
--extension-suffix "GenAllScript"
|
||||
## Images
|
||||
#swift run -c release ResgenSwift images $FORCE_FLAG "./Images/sampleImages.txt" \
|
||||
# --xcassets-path "./Images/imagium.xcassets" \
|
||||
# --extension-output-path "./Images/Generated" \
|
||||
# --extension-name "ImageYolo" \
|
||||
# --extension-name-ui-kit "UIImageYolo" \
|
||||
# --extension-suffix "GenAllScript"
|
||||
|
@ -33,7 +33,7 @@ enum FirebaseGenerator {
|
||||
"""
|
||||
func logScreen(name: String, path: String) {
|
||||
var parameters = [
|
||||
AnalyticsParameterScreenName: name
|
||||
AnalyticsParameterScreenName: name as NSObject
|
||||
]
|
||||
|
||||
Analytics.logEvent(
|
||||
@ -53,19 +53,25 @@ enum FirebaseGenerator {
|
||||
category: String,
|
||||
params: [String: Any]?
|
||||
) {
|
||||
var parameters: [String:Any] = [
|
||||
"action": action,
|
||||
"category": category,
|
||||
var parameters: [String:NSObject] = [
|
||||
"action": action as NSObject,
|
||||
"category": category as NSObject,
|
||||
]
|
||||
|
||||
if let supplementaryParameters = params {
|
||||
parameters.merge(supplementaryParameters) { (origin, new) -> Any in
|
||||
return origin
|
||||
for (newKey, newValue) in supplementaryParameters {
|
||||
if parameters.contains(where: { (key: String, value: NSObject) in
|
||||
key == newKey
|
||||
}) {
|
||||
continue
|
||||
}
|
||||
|
||||
parameters[newKey] = newValue as? NSObject
|
||||
}
|
||||
}
|
||||
|
||||
Analytics.logEvent(
|
||||
name,
|
||||
name.replacingOccurrences(of: [" "], with: "_"),
|
||||
parameters: parameters
|
||||
)
|
||||
}
|
||||
|
@ -41,12 +41,28 @@ struct ColorExtensionGenerator {
|
||||
staticVar: Bool,
|
||||
extensionName: String,
|
||||
isSwiftUI: Bool) -> String {
|
||||
[
|
||||
Self.getHeader(extensionClassname: extensionName, isSwiftUI: isSwiftUI),
|
||||
Self.getProperties(for: colors, withStaticVar: staticVar, isSwiftUI: isSwiftUI),
|
||||
Self.getFooter()
|
||||
]
|
||||
.joined(separator: "\n")
|
||||
// [
|
||||
// Self.getHeader(extensionClassname: extensionName, isSwiftUI: isSwiftUI),
|
||||
// Self.getProperties(for: colors, withStaticVar: staticVar, isSwiftUI: isSwiftUI),
|
||||
// Self.getFooter()
|
||||
// ]
|
||||
// .joined(separator: "\n")
|
||||
do {
|
||||
let context: [String: Any] = [
|
||||
"colors": colors,
|
||||
"isStatic": staticVar,
|
||||
"isSwiftUI": isSwiftUI,
|
||||
"toolName": Colors.toolName,
|
||||
"resgenVersion": ResgenSwiftVersion,
|
||||
"extensionClassname": extensionName
|
||||
]
|
||||
|
||||
return try ResgenSwift.environment.renderTemplate(name: "Colors/main_template", context: context)
|
||||
} catch {
|
||||
// let error = ColorsToolError.writeExtension(extensionFilePath, error.localizedDescription)
|
||||
// print(error.description)
|
||||
Colors.exit(withError: error)
|
||||
}
|
||||
}
|
||||
|
||||
private static func getHeader(extensionClassname: String, isSwiftUI: Bool) -> String {
|
||||
|
@ -8,6 +8,8 @@
|
||||
import ToolCore
|
||||
import Foundation
|
||||
import ArgumentParser
|
||||
import Stencil
|
||||
import PathKit
|
||||
|
||||
struct ResgenSwift: ParsableCommand {
|
||||
|
||||
@ -32,6 +34,20 @@ struct ResgenSwift: ParsableCommand {
|
||||
// subcommand is not given on the command line.
|
||||
//defaultSubcommand: Twine.self
|
||||
)
|
||||
|
||||
static let projectDirectory = URL(fileURLWithPath: #file) // ProjectDir/Sources/ResgenSwift/main.swift
|
||||
.deletingLastPathComponent() // ProjectDir/Sources/ResgenSwift/
|
||||
.deletingLastPathComponent() // ProjectDir/Sources/
|
||||
.deletingLastPathComponent() // ProjectDir/
|
||||
|
||||
static let environment = Environment(
|
||||
loader: FileSystemLoader(
|
||||
paths: [
|
||||
Path("\(projectDirectory.path)/Templates/")
|
||||
]
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
print(ResgenSwift.projectDirectory.path)
|
||||
ResgenSwift.main()
|
||||
|
0
Templates/Colors/json_template
Normal file
0
Templates/Colors/json_template
Normal file
21
Templates/Colors/main_template
Normal file
21
Templates/Colors/main_template
Normal file
@ -0,0 +1,21 @@
|
||||
// Generated by ResgenSwift.{{ toolName }} {{ resgenVersion }}
|
||||
{% if isSwiftUI %}
|
||||
import SwiftUI
|
||||
{% else %}
|
||||
import UIKit
|
||||
{% endif %}
|
||||
extension {{ extensionClassname }} {
|
||||
{% for color in colors %}
|
||||
{% if isSwiftUI %}
|
||||
/// Color {{ color.name }} is {{ color.light }} {{ color.light }} or {{ color.dark }} {{ color.dark }}"
|
||||
{% if isStatic %}static {% endif %}var {{ color.name }}: Color {
|
||||
Color("{{ color.name }}")
|
||||
}
|
||||
{% else %}
|
||||
/// Color {{ color.name }} is {{ color.light }} {{ color.light }} or {{ color.dark }} {{ color.dark }}"
|
||||
{% if isStatic %}static {% else %}@objc {% endif %}var {{ color.name }}: UIColor {
|
||||
UIColor(named: "{{ color.name }}")!
|
||||
}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
}
|
4
Templates/Colors/swiftui_template
Normal file
4
Templates/Colors/swiftui_template
Normal file
@ -0,0 +1,4 @@
|
||||
/// Color {{ color.name }} is {{ color.light }} {{ color.light }} or {{ color.dark }} {{ color.dark }}"
|
||||
{% if isStatic %}static {% endif %}var {{ color.name }}: Color {
|
||||
Color("{{ color.name }}")
|
||||
}
|
4
Templates/Colors/uikit_template
Normal file
4
Templates/Colors/uikit_template
Normal file
@ -0,0 +1,4 @@
|
||||
/// Color {{ color.name }} is {{ color.light }} {{ color.light }} or {{ color.dark }} {{ color.dark }}"
|
||||
{% if isStatic %}static {% else %}@objc {% endif %}var {{ color.name }}: UIColor {
|
||||
UIColor(named: "{{ color.name }}")!
|
||||
}
|
Reference in New Issue
Block a user